diff --git a/README.md b/README.md index 58a19ba..b550dac 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,8 @@ Application expects to find an object named `sizeme_options` (TODO: rename to `S gaTrackingId: "UA-40735596-2", shopType: "magento", debugState: false, - uiOptions: {} + uiOptions: {}, + additionalTranslations: {} } ``` * [serviceStatus] (_Boolean_): is SizeMe enabled. Default: true. @@ -50,3 +51,16 @@ Application expects to find an object named `sizeme_options` (TODO: rename to `S - [sizeSelectorType] (_String_): type of the size selector used in the shop. Possible values at the moment: "default" (default, doh) and "swatches" - [addToCartElement] (_String_): DOM-element to listen to for add-to-cart events - [addToCartEvent] (_String_): DOM-event for add-to-cart + +* [additionalTranslations] (_Object_): Optionally override translations defined under ['i18n'](src/i18n). Example of how to +override the Swedish translation for chest: +```javascript +{ + sv: { + humanMeasurements: { + chest: "Bröst" + } + } +} +``` +Similarly override any other key in any other language (en, fi, sv). diff --git a/src/i18n.js b/src/i18n.js index 77d9ea4..785bd5d 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -1,3 +1,5 @@ +/* global sizeme_options */ + import uiOptions from "./api/uiOptions"; import i18n from "i18next"; import en from "./i18n/en.json"; @@ -7,7 +9,7 @@ import sv from "./i18n/sv.json"; i18n.init({ lng: uiOptions.lang || document.documentElement.lang || "en", fallbackLng: "en", - debug: true, + debug: false, interpolation: { format: (value, format) => { switch (format) { @@ -35,4 +37,14 @@ i18n.init({ } }); +if (sizeme_options.additionalTranslations) { + console.log(sizeme_options.additionalTranslations); + const addtr = sizeme_options.additionalTranslations; + ["en", "fi", "sv"].forEach(lng => { + if (addtr[lng]) { + i18n.addResourceBundle(lng, "translation", addtr[lng], true, true); + } + }); +} + export default i18n;