humanswitch / consentcookie

Open source AVG solution for websites
Apache License 2.0
27 stars 10 forks source link

Language codes reference to available languages #56

Closed christianvriens closed 6 years ago

christianvriens commented 6 years ago

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'

StevenChoo commented 6 years ago

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.

StevenChoo commented 6 years ago

@christianvriens What do you think?

StevenChoo commented 6 years ago

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

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

proposed:

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

In the example above:

rockxwre commented 6 years ago

Test results :heavy_check_mark:

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'.