mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-16 12:55:14 +03:00
Use i18next as i18n framework
This commit is contained in:
parent
e2a629a620
commit
0a71f1e559
39 changed files with 607 additions and 408 deletions
|
@ -1,12 +1,66 @@
|
|||
'use strict';
|
||||
|
||||
function localize() {
|
||||
/*
|
||||
* Wrapper around the i18n system
|
||||
*/
|
||||
|
||||
var i18n = {}
|
||||
|
||||
/**
|
||||
* Functions that depend on the i18n framework
|
||||
*/
|
||||
i18n.init = function(cb) {
|
||||
|
||||
var defaultLocale = window.navigator.userLanguage || window.navigator.language;
|
||||
|
||||
i18next
|
||||
.use(i18nextXHRBackend)
|
||||
.init({
|
||||
lng: defaultLocale,
|
||||
getAsync: false,
|
||||
debug: true,
|
||||
ns: ['messages'],
|
||||
defaultNS:['messages'],
|
||||
fallbackLng: 'en',
|
||||
backend: { loadPath: '/_locales/{{lng}}/{{ns}}.json' }
|
||||
}, function(err, t) {
|
||||
if (err !== undefined) {
|
||||
console.error('Error loading i18n ' + err);
|
||||
} else {
|
||||
console.log('i18n system loaded');
|
||||
}
|
||||
if (cb !== undefined) {
|
||||
cb();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
i18n.getMessage = function(messageID, parameters) {
|
||||
var translatedString = i18next.t(messageID + '.message');
|
||||
|
||||
if (parameters !== undefined) {
|
||||
parameters.forEach(function(element, index) {
|
||||
translatedString = translatedString.replace('$' + (index + 1), element);
|
||||
});
|
||||
}
|
||||
|
||||
return translatedString;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper functions, don't depend of the i18n framework
|
||||
*/
|
||||
|
||||
i18n.localizePage = function() {
|
||||
|
||||
var localized = 0;
|
||||
|
||||
var translate = function(messageID) {
|
||||
localized++;
|
||||
|
||||
return chrome.i18n.getMessage(messageID);
|
||||
return i18n.getMessage(messageID);
|
||||
};
|
||||
|
||||
$('[i18n]:not(.i18n-replaced)').each(function() {
|
||||
|
@ -38,4 +92,4 @@ function localize() {
|
|||
});
|
||||
|
||||
return localized;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue