From 084fc369da2c6b9a409d7a76792ddc2af8679bf9 Mon Sep 17 00:00:00 2001 From: MTRNord Date: Tue, 9 May 2017 15:13:52 +0200 Subject: [PATCH 1/2] fix issue with language loading in react-sdk 2/2 --- scripts/copy-res.js | 24 ++++++++++++++--------- src/vector/index.js | 48 ++++++++++++++++++++++++--------------------- 2 files changed, 41 insertions(+), 31 deletions(-) diff --git a/scripts/copy-res.js b/scripts/copy-res.js index 68014831bc9..0f30f9d2d7d 100755 --- a/scripts/copy-res.js +++ b/scripts/copy-res.js @@ -23,7 +23,7 @@ const fs = require('fs'); const rimraf = require('rimraf'); // cleanup language files before copying them. -rimraf("webapp/i18n/", function () { console.log('cleanup language files'); }); +//rimraf("webapp/", function () { console.log('cleanup language files'); }); //From http://stackoverflow.com/a/20525865/4929236 function generateFileArray(dir, files_) { @@ -131,8 +131,6 @@ function next(i, err) { } } -next(0); - // Generate Language List const testFolder = 'src/i18n/'; @@ -145,11 +143,17 @@ if (!fs.existsSync('webapp')){ if (!fs.existsSync('webapp/i18n/')){ fs.mkdirSync('webapp/i18n/'); } -fs.readdir(testFolder, (err, files) => { - files.forEach(file => { - if (file == 'pt_BR.json') { - languages['pt_br'] = file; - } else if (file.indexOf("-") > -1) { + +if (!fs.existsSync('webapp/i18n/languages.json')){ + rimraf("webapp/i18n/languages.json", function () { console.log('cleanup languages.json file'); }); +} + +fs.readdir(testFolder, function(err, files) { + if (err) { + throw err; + } + files.forEach(function(file) { + if (file.indexOf("-") > -1) { languages[file.split('-')[0]] = file; } else if (file.indexOf("_") > -1) { languages[file.split('_')[0]] = file; @@ -157,5 +161,7 @@ fs.readdir(testFolder, (err, files) => { languages[file.split('.json')[0]] = file; } }); - fs.writeFile('webapp/i18n/languages.json', JSON.stringify(languages, null, 4), 'utf8'); + fs.writeFile('webapp/i18n/languages.json', JSON.stringify(languages, null, 4)); }) + +next(0); diff --git a/src/vector/index.js b/src/vector/index.js index 098b605383a..d2e7a26e536 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -427,30 +427,34 @@ async function loadApp() { } } -const _localSettings = getLocalSettings(); -dis.register(onAction); -if (!_localSettings.hasOwnProperty('language')) { - const language = navigator.languages[0] || navigator.language || navigator.userLanguage; - if (language.indexOf("-") > -1) { - dis.dispatch({ - action: 'set_language', - value: language.split('-')[0], - }); - counterpart.setLocale(language.split('-')[0]); - setLocalSetting('language', language.split('-')[0]); - } else { - dis.dispatch({ +function loadLanguage(callback) { + const _localSettings = getLocalSettings(); + dis.register(onAction); + if (!_localSettings.hasOwnProperty('language')) { + const language = navigator.languages[0] || navigator.language || navigator.userLanguage; + if (language.indexOf("-") > -1) { + onAction({ + action: 'set_language', + value: language.split('-')[0], + }); + sdk.setLanguage(language.split('-')[0]); + setLocalSetting('language', language.split('-')[0]); + } else { + onAction({ + action: 'set_language', + value: language, + }); + sdk.setLanguage(language); + setLocalSetting('language', language); + } + }else { + sdk.setLanguage(_localSettings.language); + onAction({ action: 'set_language', - value: language, + value: _localSettings.language, }); - counterpart.setLocale(language); - setLocalSetting('language', language); } -}else { - dis.dispatch({ - action: 'set_language', - value: _localSettings.language, - }); + callback(); } -loadApp(); +loadLanguage(loadApp); From a874307f380e13d3c6c56be879418e03ff9c1326 Mon Sep 17 00:00:00 2001 From: MTRNord Date: Tue, 9 May 2017 15:27:39 +0200 Subject: [PATCH 2/2] fix pt-br 2/2 --- src/vector/index.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/vector/index.js b/src/vector/index.js index d2e7a26e536..746638a893b 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -317,9 +317,6 @@ function onAction(payload) { if (language.indexOf("-") > -1) { counterpart.setLocale(language.split('-')[0]); setLocalSetting('language', language.split('-')[0]); - } else if (language == 'pt-br') { - counterpart.setLocale('pt-br'); - setLocalSetting('language', 'pt-br'); } else { counterpart.setLocale(language); setLocalSetting('language', language);