Skip to content

Commit

Permalink
html10n: do not error when locale variant is found
Browse files Browse the repository at this point in the history
Fixes ether#3882.
  • Loading branch information
iquidus committed Apr 19, 2020
1 parent e76f66f commit 9f34b2c
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/static/js/html10n.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,20 @@ window.html10n = (function(window, document, undefined) {

// dat alng ain't here, man!
if (!data[lang]) {
var msg = 'Couldn\'t find translations for '+lang
, l
if(~lang.indexOf('-')) lang = lang.split('-')[0] // then let's try related langs
for(l in data) {
if(lang != l && l.indexOf(lang) === 0 && data[l]) {
lang = l
break;
if (lang.indexOf('-') > -1) {
var msg = 'Couldn\'t find translations for '+lang
lang = lang.split('-')[0] // get root locale incase variant (e.g ru-RU)
if (!data[lang]) { // check root locale (e.g ru)
var l
for(l in data) { // try similar (e.g zh-hans)
if(lang != l && l.indexOf(lang) === 0 && data[l]) {
lang = l
break;
}
}
if(lang != l) return cb(new Error(msg))
}
}
if(lang != l) return cb(new Error(msg))
}

if ('string' == typeof data[lang]) {
Expand Down

0 comments on commit 9f34b2c

Please sign in to comment.