@gucciogucci/simply-translation
Advanced tools
Comparing version 1.1.1 to 1.2.2
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=function(e){const t=e.default;let a;if(void 0!==e.source&&"url_pathname_slot2"===e.source){const[,,e]=window.location.pathname.split("/");a=e}else a=void 0!==e.source&&"html"===e.source?document.documentElement.lang.toLowerCase():navigator.language;const o=e.languages[a]?JSON.stringify(e.languages[a]):JSON.stringify(e.languages[t]);localStorage.setItem("translate",o)},exports.simplyTranslate=function(e,t){let a=JSON.parse(localStorage.getItem("translate"))[e];return t&&t.forEach(((e,t)=>{a=a.replace(`{${t}}`,e)})),a}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=function(e){const t=e.default;let a,o="translate";if(e.storageName&&(o="translate_"+e.storageName,window.ggsp_storage=o),void 0!==e.source&&"url_pathname_slot2"===e.source){const[,,e]=window.location.pathname.split("/");a=e}else a=void 0!==e.source&&"html"===e.source?document.documentElement.lang.toLowerCase():navigator.language;const s=e.languages[a]?JSON.stringify(e.languages[a]):JSON.stringify(e.languages[t]);localStorage.setItem(o,s)},exports.simplyTranslate=function(e,t){const a=window.ggsp_storage?window.ggsp_storage:"translate";let o=JSON.parse(localStorage.getItem(a))[e];return t&&t.forEach(((e,t)=>{o=o.replace(`{${t}}`,e)})),o}; |
{ | ||
"name": "@gucciogucci/simply-translation", | ||
"version": "1.1.1", | ||
"version": "1.2.2", | ||
"description": "Simply Translation library", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.min.js", |
@@ -74,7 +74,25 @@ # simply-translation | ||
| languages | yes | {object} | {'en-US': en, 'it-IT': it, ...} | mapping languages files | | ||
| storageName | no | {string} | | In order to avoid potential conflicts in case you have more than one app with this lib in the same page, you can add an extra name parameter to the storage data | | ||
Example: | ||
### Examples | ||
#### Basic configuration | ||
It will use the _Browser Language_ as selector, `en-US` as default language and `it-IT` as extra language: | ||
```js | ||
loadTranslation({ | ||
default: 'en-US', | ||
languages: { | ||
'en-US': en, | ||
'it-IT': it, | ||
} | ||
}); | ||
``` | ||
#### With different Language Selector sourse | ||
It will use URL as Language Selector `https://www.domain.com/uk/en/`, and `zh_hk`, and `zh` as extras languages: | ||
```js | ||
loadTranslation({ | ||
default: 'en', | ||
@@ -90,2 +108,16 @@ source: 'url_pathname_slot2', | ||
#### With different data storage name | ||
The translation will be storage in a different object: | ||
```js | ||
loadTranslation({ | ||
default: 'en', | ||
languages: { | ||
'en': en | ||
}, | ||
storageName: 'newName' | ||
}); | ||
``` | ||
### How to use it | ||
@@ -92,0 +124,0 @@ |
13283
140