Skip to content

Commit

Permalink
Loading of default translations for locales that are consist of an `I…
Browse files Browse the repository at this point in the history
…SO 639-1` language code and an `ISO 3166-1` country code
  • Loading branch information
tg666 committed Jan 5, 2022
1 parent 6494ba3 commit 59e9ae1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Default translations are now loaded also for locales that are consist of an `ISO 639-1` language code and an `ISO 3166-1` country code e.g. `en-US`.

## [0.3.2] - 2021-01-03

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ The package comes with the default translations for the following languages:
- [Czech - cs](src/resources/translations/cs.json)
- [Slovak - sk](src/resources/translations/sk.json)

Translations that will be loaded and accessible for the widget are taken from the field `Locales`. Locale codes are in the format `ISO 639-1` and each locale must be defined on a new line.
Translations that will be loaded and accessible for the widget are taken from the field `Locales`. Each locale must be defined on a new line.
If you want to rewrite default translations or you want to add translations for a new locale then you can define them in a table `Translations`.

### Locale detection
Expand Down
3 changes: 2 additions & 1 deletion src/CookieConsentWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ class CookieConsentWrapper {
}

loadTranslations(locale) {
const localeIso639 = 2 < locale.length ? locale[0] + locale[1] : locale;
let translations;

try {
translations = require(`./resources/translations/${locale}`);
translations = require(`./resources/translations/${localeIso639}`);
} catch (e) {
translations = {};
}
Expand Down

0 comments on commit 59e9ae1

Please sign in to comment.