humanswitch/consentcookie

Default and fallback language

Closed this issue · 2 comments

Issue #47 describes the functionality for multilanguage. But this is based on browser language and the default language is Dutch.

Description

You should be able to configure default and fallback languages

Preference in CC language:

  1. CC - API language. If configurated or not available (not available yet)
  2. CC - Default language. If configurated or not available
  3. CC - Browser language. If not available
  4. CC - Fallback language
  5. CC - Default CC code setting (Dutch at the moment)

definition

Default language throug CC-API. Set the default language through the API.
Default language then this language is always used if available in language file.
Next preferred browser language If preferred browser language isn't available then the next second etc. should be checked before going to the fallback (improvement for #47)
Fallback language If browser language isn't available then this language should be used. Now this is dutch and this should be configurable
CC default code language English is improvement

Context

In CC init json you should be able to configure in object 'general':

  • Default language
  • Fallback language

This should be used in ConsentCookie language setting.

Implemented the default and fallback language options.

Example:

  ConsentCookie.init({
    'general': {
      'language': {
        'default': 'fr',
        'fallback': 'en'
      }
    },
    'resources': {
      'nl': {
        'about': {
          'title': 'Dutch',
        },
      },
      'en': {
        'about': {
          'title': 'English',
        },
      },
      'fr': {
        'about': {
          'title': 'French',
        },
      },
      'en-US': {
        'about': {
          'title': 'en-US',
        },
      }
    }
  });

The example above shows a config with 4 languages defined, nl , en , fr and en-US .
Following the flow of the description the language in ConsentCookie is changed.

To test the fallback config, change the browser language to something not configured, like German and remove the default option. To see the changes, check the title of the about screen.

Test results

Default language ✔️

Used example script on my GTM demo page. As expected, the title ' French' appeared in the About screen.

Fallback language ✔️

Used example script on my GTM demo page. Removed all my languages in Google Chrome and added only the (not supported) "Danish" language. As expected, the title ''English' appeared in the About screen.