Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/translations' into translations
Browse files Browse the repository at this point in the history
  • Loading branch information
RiotTranslate committed May 9, 2017
2 parents bc87ba0 + a874307 commit 41f49cc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 34 deletions.
24 changes: 15 additions & 9 deletions scripts/copy-res.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
Expand Down Expand Up @@ -131,8 +131,6 @@ function next(i, err) {
}
}

next(0);

// Generate Language List

const testFolder = 'src/i18n/';
Expand All @@ -145,17 +143,25 @@ 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;
} else {
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);
51 changes: 26 additions & 25 deletions src/vector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -427,30 +424,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);

0 comments on commit 41f49cc

Please sign in to comment.