humanswitch/consentcookie

Language codes reference to available languages

christianvriens opened this issue · 4 comments

This list shows language codes used in browsers: https://www.metamodpro.com/browser-language-codes

If someone has language en-US and the languages available in CC are 'en' and 'nl'.
There is no default setting and the fallback is 'nl'.

I think we should use 'en'

Are we going to use the as an automatic process OR/AND are should there be an option to set a reference from a language code to an available language.

Example:
'ar' (arabic as browser language) should refer to 'en'
'pl' (polish as browser language) should refer to 'en'

I would suggest that the key of the resources that represents the language, should have a format that it can represent multiple languages. This could be for example with a seperator.

Current:

// Not relevant config omitted
{
  "resources": {
    "nl": {
      "general": {}
    },
    "en": {
      "general": {}
    },
    "en-US": {
      "general": {}
    }
  }
}

proposed

// Not relevant config omitted
{
  "resources": {
    "nl": {
      "general": {}
    },
    "en|en-US": {
      "general": {}
    }
  }
}

Proposed is an example. For the example is ```|```` used as seperator but this can be another character.

Example:
'ar' (arabic as browser language) should refer to 'en'
'pl' (polish as browser language) should refer to 'en'

We can use the default and fallback, so that we don`t have to add all possible languages in the proposed format.

@christianvriens What do you think?

Decided on using an alias system instead of a composite key variant.

The value of a defined resource can be of 2 types:

  • resource (object), a JavaScript object that defines all translations for the given language key
  • alias (string), the name of the language key of which the resource should be used as translation

proposed:

// Not relevant config omitted
{
  "resources": {
    "nl": {
      "general": {}
    },
    "en": {
      "general": {}
    },
    "en-US": "en"
  }
}

In the example above:

  • nl and en are defined as resources
  • en-US is defined as an alias for the en resource

Test results ✔️

Used the following init script:

  'language': {
	'fallback': 'en'
  }
},
'resources': {
  'nl': "fr",
  'fr': {
	'about': {
	  'title': 'French',
	},
  },
},...

and loaded the page with Dutch language. As expected, the about title was 'French'.