Skip to content

Instantly share code, notes, and snippets.

@hkitago
Created August 1, 2018 05:28
Show Gist options
  • Save hkitago/deb642a3a01967640fc0cdc544402f11 to your computer and use it in GitHub Desktop.
Save hkitago/deb642a3a01967640fc0cdc544402f11 to your computer and use it in GitHub Desktop.
module of dynamic import.
/*****************************************************************************
* 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