Merge pull request #1000 from matrix-org/revert-994-revert-989-add-language-picker-labels

Revert "Revert "add labels to language picker""
This commit is contained in:
Matthew Hodgson 2017-06-01 19:46:44 +01:00 committed by GitHub
commit ba99036054
2 changed files with 15 additions and 13 deletions

View file

@ -40,14 +40,7 @@ export default class LanguageDropdown extends React.Component {
} }
componentWillMount() { componentWillMount() {
languageHandler.getAllLanguageKeysFromJson().then((langKeys) => { languageHandler.getAllLanguagesFromJson().then((langs) => {
const langs = [];
langKeys.forEach((languageKey) => {
langs.push({
value: languageKey,
label: _t(languageKey)
});
});
langs.sort(function(a, b){ langs.sort(function(a, b){
if(a.label < b.label) return -1; if(a.label < b.label) return -1;
if(a.label > b.label) return 1; if(a.label > b.label) return 1;

View file

@ -133,7 +133,7 @@ export function setLanguage(preferredLangs) {
throw new Error("Unable to find an appropriate language"); throw new Error("Unable to find an appropriate language");
} }
return getLanguage(i18nFolder + availLangs[langToUse]); return getLanguage(i18nFolder + availLangs[langToUse].fileName);
}).then((langData) => { }).then((langData) => {
counterpart.registerTranslations(langToUse, langData); counterpart.registerTranslations(langToUse, langData);
counterpart.setLocale(langToUse); counterpart.setLocale(langToUse);
@ -142,16 +142,25 @@ export function setLanguage(preferredLangs) {
// Set 'en' as fallback language: // Set 'en' as fallback language:
if (langToUse != "en") { if (langToUse != "en") {
return getLanguage(i18nFolder + availLangs['en']); return getLanguage(i18nFolder + availLangs['en'].fileName);
} }
}).then((langData) => { }).then((langData) => {
if (langData) counterpart.registerTranslations('en', langData); if (langData) counterpart.registerTranslations('en', langData);
}); });
}; };
export function getAllLanguageKeysFromJson() { export function getAllLanguagesFromJson() {
return getLangsJson().then((langs) => { return getLangsJson().then((langsObject) => {
return Object.keys(langs); var langs = [];
for (var langKey in langsObject) {
if (langsObject.hasOwnProperty(langKey)) {
langs.push({
'value': langKey,
'label': langsObject[langKey].label
});
}
}
return langs;
}); });
} }