Skip to content

Instantly share code, notes, and snippets.

@taufiksu
Created September 6, 2017 02:47
Show Gist options
  • Save taufiksu/5a4223b7f0e88989c6a3f34a51c18607 to your computer and use it in GitHub Desktop.
Save taufiksu/5a4223b7f0e88989c6a3f34a51c18607 to your computer and use it in GitHub Desktop.
Multi Language Code For Framework 7
var localize = {
locals: {
'id': {
title: "Judul Baru",
description: "Deskripsi Baru"
},
'en': {
title: "New Title",
description: "New Description"
}
},
start: function (lang) {
lang = lang.toLowerCase();
var langs = this.locals;
$$('.lang').each(function () {
var txt = $$(this).data('lang');
var to = $$(this).data('lang-to');
if (txt !== '' && typeof langs[lang][txt] !== 'undefined') {
switch (to) {
case 'text':
$$(this).text(langs[lang][txt]);
break;
case 'placeholder':
case 'alt':
case 'title':
$$(this).attr(to, langs[lang][txt]);
break;
case 'html':
default:
$$(this).html(langs[lang][txt]);
break;
}
}
});
}
};
@taufiksu
Copy link
Author

taufiksu commented Sep 6, 2017

// To Use It

Put the code when cordova start

localize.start('id');

Put in html file

<span class="lang" data-lang="title" data-lang-to="html"></span>

<input type="text" data-lang="title" data-lang-to="placeholder"/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment