Created
August 1, 2018 05:28
-
-
Save hkitago/deb642a3a01967640fc0cdc544402f11 to your computer and use it in GitHub Desktop.
module of dynamic import.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/***************************************************************************** | |
* Call in app.js like this: | |
* | |
* const localizeStrings = function(){ | |
* import('./localization.js') | |
* .then(() => { | |
* const lang = settings.language === 'English' ? 'en' : localization.lang; | |
* if(localization.labelStrings[lang]) { | |
* document.getElementById('label0').textContent = localization.labelStrings[lang].label0; | |
* //updateBtnLabel.call(this); | |
* } | |
* }); | |
* }; | |
****************************************************************************/ | |
'use strict'; | |
(function(){ | |
const exp = { | |
get lang(){ | |
let lang = window.navigator.language; | |
return lang && lang.length > 2 ? lang.substring(0, 2) : 'en'; | |
}, | |
labelStrings: { | |
en: { | |
label0: 'Label-0', | |
label1: 'Label-1' | |
}, | |
ja: { | |
label0: 'ラベル-0', | |
label1: 'ラベル-1' | |
} | |
} | |
}; | |
if (typeof module !== 'undefined') { | |
module.exports = exp; | |
module.exports.default = module.exports; | |
} | |
else { | |
self.localization = exp; | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment