mirror of
https://github.com/element-hq/element-web
synced 2024-11-23 01:35:49 +03:00
add labels to language picker
This commit is contained in:
parent
98c4252840
commit
b8e26ddf3d
2 changed files with 15 additions and 13 deletions
|
@ -40,14 +40,7 @@ export default class LanguageDropdown extends React.Component {
|
|||
}
|
||||
|
||||
componentWillMount() {
|
||||
languageHandler.getAllLanguageKeysFromJson().then((langKeys) => {
|
||||
const langs = [];
|
||||
langKeys.forEach((languageKey) => {
|
||||
langs.push({
|
||||
value: languageKey,
|
||||
label: _t(languageKey)
|
||||
});
|
||||
});
|
||||
languageHandler.getAllLanguagesFromJson().then((langs) => {
|
||||
langs.sort(function(a, b){
|
||||
if(a.label < b.label) return -1;
|
||||
if(a.label > b.label) return 1;
|
||||
|
|
|
@ -133,7 +133,7 @@ export function setLanguage(preferredLangs) {
|
|||
throw new Error("Unable to find an appropriate language");
|
||||
}
|
||||
|
||||
return getLanguage(i18nFolder + availLangs[langToUse]);
|
||||
return getLanguage(i18nFolder + availLangs[langToUse].fileName);
|
||||
}).then((langData) => {
|
||||
counterpart.registerTranslations(langToUse, langData);
|
||||
counterpart.setLocale(langToUse);
|
||||
|
@ -142,16 +142,25 @@ export function setLanguage(preferredLangs) {
|
|||
|
||||
// Set 'en' as fallback language:
|
||||
if (langToUse != "en") {
|
||||
return getLanguage(i18nFolder + availLangs['en']);
|
||||
return getLanguage(i18nFolder + availLangs['en'].fileName);
|
||||
}
|
||||
}).then((langData) => {
|
||||
if (langData) counterpart.registerTranslations('en', langData);
|
||||
});
|
||||
};
|
||||
|
||||
export function getAllLanguageKeysFromJson() {
|
||||
return getLangsJson().then((langs) => {
|
||||
return Object.keys(langs);
|
||||
export function getAllLanguagesFromJson() {
|
||||
return getLangsJson().then((langsObject) => {
|
||||
var langs = [];
|
||||
for (var langKey in langsObject) {
|
||||
if (langsObject.hasOwnProperty(langKey)) {
|
||||
langs.push({
|
||||
'value': langKey,
|
||||
'label': langsObject[langKey].label
|
||||
});
|
||||
}
|
||||
}
|
||||
return langs;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue