Merge pull request #1069 from jitsi/update-i18next
Updates i18next and bundles default translations.
This commit is contained in:
commit
f08e9afc19
3
app.js
3
app.js
|
@ -29,6 +29,7 @@ import API from './modules/API/API';
|
||||||
|
|
||||||
import UIEvents from './service/UI/UIEvents';
|
import UIEvents from './service/UI/UIEvents';
|
||||||
import getTokenData from "./modules/TokenData/TokenData";
|
import getTokenData from "./modules/TokenData/TokenData";
|
||||||
|
import translation from "./modules/translation/translation";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to push history state with the following parameters:
|
* Tries to push history state with the following parameters:
|
||||||
|
@ -95,6 +96,7 @@ const APP = {
|
||||||
UI,
|
UI,
|
||||||
settings,
|
settings,
|
||||||
conference,
|
conference,
|
||||||
|
translation,
|
||||||
/**
|
/**
|
||||||
* After the APP has been initialized provides utility methods for dealing
|
* After the APP has been initialized provides utility methods for dealing
|
||||||
* with the conference room URL(address).
|
* with the conference room URL(address).
|
||||||
|
@ -106,7 +108,6 @@ const APP = {
|
||||||
init () {
|
init () {
|
||||||
this.keyboardshortcut =
|
this.keyboardshortcut =
|
||||||
require("./modules/keyboardshortcut/keyboardshortcut");
|
require("./modules/keyboardshortcut/keyboardshortcut");
|
||||||
this.translation = require("./modules/translation/translation");
|
|
||||||
this.configFetch = require("./modules/config/HttpConfigFetch");
|
this.configFetch = require("./modules/config/HttpConfigFetch");
|
||||||
this.tokenData = getTokenData();
|
this.tokenData = getTokenData();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
{
|
{
|
||||||
"en": "English",
|
"en": "English",
|
||||||
|
|
||||||
"bg": "Bulgarian",
|
"bg": "Bulgarian",
|
||||||
"de": "German",
|
"de": "German",
|
||||||
"es": "Spanish",
|
"es": "Spanish",
|
||||||
|
|
|
@ -105,6 +105,9 @@ export default {
|
||||||
|
|
||||||
APP.translation.translateElement(selectEl);
|
APP.translation.translateElement(selectEl);
|
||||||
|
|
||||||
|
APP.translation.addLanguageChangedListener(
|
||||||
|
lng => selectInput[0].dataset.i18n = `languages:${lng}`);
|
||||||
|
|
||||||
UIUtil.showElement(wrapperId);
|
UIUtil.showElement(wrapperId);
|
||||||
}
|
}
|
||||||
// DEVICES LIST
|
// DEVICES LIST
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
/* global $, require, config, interfaceConfig */
|
/* global $, require, config, interfaceConfig */
|
||||||
var i18n = require("i18next-client");
|
import i18n from 'i18next';
|
||||||
var languages = require("../../service/translation/languages");
|
import XHR from 'i18next-xhr-backend';
|
||||||
var DEFAULT_LANG = languages.EN;
|
import jqueryI18next from 'jquery-i18next';
|
||||||
|
import languagesR from "../../lang/languages.json";
|
||||||
|
import mainR from "../../lang/main.json";
|
||||||
|
import languages from "../../service/translation/languages";
|
||||||
|
|
||||||
i18n.addPostProcessor(
|
const DEFAULT_LANG = languages.EN;
|
||||||
"resolveAppName",
|
|
||||||
value => value.replace("__app__", interfaceConfig.APP_NAME));
|
|
||||||
|
|
||||||
var defaultOptions = {
|
const defaultOptions = {
|
||||||
detectLngQS: "lang",
|
compatibilityAPI: 'v1',
|
||||||
useCookie: false,
|
compatibilityJSON: 'v1',
|
||||||
fallbackLng: DEFAULT_LANG,
|
fallbackLng: DEFAULT_LANG,
|
||||||
load: "unspecific",
|
load: "unspecific",
|
||||||
resGetPath: 'lang/__ns__-__lng__.json',
|
resGetPath: 'lang/__ns__-__lng__.json',
|
||||||
|
@ -21,48 +22,11 @@ var defaultOptions = {
|
||||||
fallbackOnNull: true,
|
fallbackOnNull: true,
|
||||||
fallbackOnEmpty: true,
|
fallbackOnEmpty: true,
|
||||||
useDataAttrOptions: true,
|
useDataAttrOptions: true,
|
||||||
app: interfaceConfig.APP_NAME,
|
app: interfaceConfig.APP_NAME
|
||||||
getAsync: true,
|
|
||||||
defaultValueFromContent: false,
|
|
||||||
customLoad: function(lng, ns, options, done) {
|
|
||||||
var resPath = "lang/__ns__-__lng__.json";
|
|
||||||
if(lng === languages.EN)
|
|
||||||
resPath = "lang/__ns__.json";
|
|
||||||
var url = i18n.functions.applyReplacement(resPath,
|
|
||||||
{ lng: lng, ns: ns });
|
|
||||||
i18n.functions.ajax({
|
|
||||||
url: url,
|
|
||||||
success: function(data) {
|
|
||||||
i18n.functions.log('loaded: ' + url);
|
|
||||||
done(null, data);
|
|
||||||
},
|
|
||||||
error : function(xhr, status, error) {
|
|
||||||
if ((status && status == 200) ||
|
|
||||||
(xhr && xhr.status && xhr.status == 200)) {
|
|
||||||
// file loaded but invalid json, stop waste time !
|
|
||||||
i18n.functions.error('There is a typo in: ' + url);
|
|
||||||
} else if ((status && status == 404) ||
|
|
||||||
(xhr && xhr.status && xhr.status == 404)) {
|
|
||||||
i18n.functions.log('Does not exist: ' + url);
|
|
||||||
} else {
|
|
||||||
var theStatus = status ? status :
|
|
||||||
((xhr && xhr.status) ? xhr.status : null);
|
|
||||||
i18n.functions.log(theStatus + ' when loading ' + url);
|
|
||||||
}
|
|
||||||
|
|
||||||
done(error, {});
|
|
||||||
},
|
|
||||||
dataType: "json",
|
|
||||||
async : options.getAsync
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// options for caching
|
|
||||||
// useLocalStorage: true,
|
|
||||||
// localStorageExpirationTime: 86400000 // in ms, default 1 week
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function initCompleted() {
|
function initCompleted() {
|
||||||
$("[data-i18n]").i18n();
|
$("[data-i18n]").localize();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLangFromQuery() {
|
function getLangFromQuery() {
|
||||||
|
@ -78,8 +42,8 @@ function getLangFromQuery() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
class Translation {
|
||||||
init: function (settingsLang) {
|
init (settingsLang) {
|
||||||
let options = defaultOptions;
|
let options = defaultOptions;
|
||||||
|
|
||||||
let lang = getLangFromQuery() || settingsLang || config.defaultLanguage;
|
let lang = getLangFromQuery() || settingsLang || config.defaultLanguage;
|
||||||
|
@ -98,31 +62,48 @@ module.exports = {
|
||||||
options.lng = lang;
|
options.lng = lang;
|
||||||
}
|
}
|
||||||
|
|
||||||
i18n.init(options, initCompleted);
|
i18n.use(XHR)
|
||||||
},
|
.use({
|
||||||
setLanguage: function (lang) {
|
type: 'postProcessor',
|
||||||
|
name: "resolveAppName",
|
||||||
|
process: (res, key) => {
|
||||||
|
return i18n.t(key, {app: options.app});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.init(options, initCompleted);
|
||||||
|
// adds default language which is preloaded from code
|
||||||
|
i18n.addResourceBundle(DEFAULT_LANG, 'main', mainR, true, true);
|
||||||
|
i18n.addResourceBundle(
|
||||||
|
DEFAULT_LANG, 'languages', languagesR, true, true);
|
||||||
|
jqueryI18next.init(i18n, $, {useOptionsAttr: true});
|
||||||
|
}
|
||||||
|
|
||||||
|
setLanguage (lang) {
|
||||||
if(!lang)
|
if(!lang)
|
||||||
lang = DEFAULT_LANG;
|
lang = DEFAULT_LANG;
|
||||||
i18n.setLng(lang, defaultOptions, initCompleted);
|
i18n.setLng(lang, defaultOptions, initCompleted);
|
||||||
},
|
|
||||||
getCurrentLanguage: function () {
|
|
||||||
return i18n.lng();
|
|
||||||
},
|
|
||||||
translateElement: function (selector, options) {
|
|
||||||
// i18next expects undefined if options are missing, check if its null
|
|
||||||
selector.i18n(
|
|
||||||
options === null ? undefined : options);
|
|
||||||
},
|
|
||||||
generateTranslationHTML: function (key, options) {
|
|
||||||
var str = "<span data-i18n=\"" + key + "\"";
|
|
||||||
if (options) {
|
|
||||||
str += " data-i18n-options='" + JSON.stringify(options) + "'";
|
|
||||||
}
|
|
||||||
str += ">";
|
|
||||||
// i18next expects undefined if options ARE missing, check if its null
|
|
||||||
str += i18n.t(key, options === null ? undefined : options);
|
|
||||||
str += "</span>";
|
|
||||||
return str;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
getCurrentLanguage () {
|
||||||
|
return i18n.lng();
|
||||||
|
}
|
||||||
|
|
||||||
|
translateElement (selector, options) {
|
||||||
|
// i18next expects undefined if options are missing, check if its null
|
||||||
|
selector.localize(
|
||||||
|
options === null ? undefined : options);
|
||||||
|
}
|
||||||
|
|
||||||
|
generateTranslationHTML (key, options) {
|
||||||
|
let optAttr = options
|
||||||
|
? ` data-i18n-options='${JSON.stringify(options)}'` : "";
|
||||||
|
let text = i18n.t(key, options === null ? undefined : options);
|
||||||
|
return `<span data-i18n="${key}"${optAttr}>${text}</span>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
addLanguageChangedListener(listener) {
|
||||||
|
i18n.on('languageChanged', listener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new Translation();
|
||||||
|
|
|
@ -21,7 +21,10 @@
|
||||||
"autosize": "^1.18.13",
|
"autosize": "^1.18.13",
|
||||||
"bootstrap": "3.1.1",
|
"bootstrap": "3.1.1",
|
||||||
"events": "*",
|
"events": "*",
|
||||||
"i18next-client": "1.7.7",
|
"i18next": "3.4.4",
|
||||||
|
"i18next-xhr-backend": "1.1.0",
|
||||||
|
"jquery-i18next": "1.1.0",
|
||||||
|
"json-loader": "0.5.4",
|
||||||
"jQuery-Impromptu": "trentrichardson/jQuery-Impromptu#v6.0.0",
|
"jQuery-Impromptu": "trentrichardson/jQuery-Impromptu#v6.0.0",
|
||||||
"jquery": "~2.1.1",
|
"jquery": "~2.1.1",
|
||||||
"jquery-contextmenu": "*",
|
"jquery-contextmenu": "*",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
module.exports = {
|
export default {
|
||||||
getLanguages : function () {
|
getLanguages : function () {
|
||||||
var languages = [];
|
var languages = [];
|
||||||
for (var lang in this)
|
for (var lang in this)
|
||||||
|
|
|
@ -58,6 +58,11 @@ var config = {
|
||||||
name: '[path][name].[ext]'
|
name: '[path][name].[ext]'
|
||||||
},
|
},
|
||||||
test: /\.(gif|png|svg)$/
|
test: /\.(gif|png|svg)$/
|
||||||
|
},{
|
||||||
|
//Adds the ability to import json files.
|
||||||
|
loader: 'json',
|
||||||
|
exclude: __dirname + '/node_modules/',
|
||||||
|
test: /\.json$/
|
||||||
}],
|
}],
|
||||||
noParse: [
|
noParse: [
|
||||||
// Do not parse the files of the Strophe.js library or at least
|
// Do not parse the files of the Strophe.js library or at least
|
||||||
|
|
Loading…
Reference in New Issue