git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit e56f598e317e0f73881bc6004495c39c60bccf65

i18n - Try BCP47 codes, otherwise load family language if exist.

Marcos Gutierrez committed on 10/26/2017, 1:46:36 PM
Parent: 37f1f5982ffb6d545b8e4e7156aefa8285ecdc6b

Files changed

plugs/intl/sync/i18n.jschanged
plugs/intl/sync/i18n.jsView
@@ -91,12 +91,19 @@
9191 defaultLocale: 'en'
9292 })
9393
9494 watch(api.settings.obs.get('patchwork.lang', navigator.language), currentLocale => {
95- i18nL.setLocale(getSubLocal(currentLocale))
95+ var locales = i18nL.getLocales()
9696
97- // Only refresh if the language has already been selected once.
98- // This will prevent the update loop
97+ // Try BCP47 codes, otherwise load family language if exist
98+ if (locales.indexOf(currentLocale) !== -1) {
99+ i18nL.setLocale(currentLocale)
100+ } else {
101+ i18nL.setLocale(getSimilar(locales, currentLocale))
102+ }
103+
104+ // Only refresh if the language has already been selected once.
105+ // This will prevent the update loop
99106 if (_locale) {
100107 electron.remote.getCurrentWebContents().reloadIgnoringCache()
101108 }
102109 })
@@ -108,4 +115,17 @@
108115 // For now get only global languages
109116 function getSubLocal (loc) {
110117 return loc.split('-')[0]
111118 }
119+
120+function getSimilar (locales, option) {
121+ var reindexed = {}
122+ locales.forEach(function (local) {
123+ (reindexed[getSubLocal(local)])
124+ ? reindexed[getSubLocal(local)].concat(local)
125+ : reindexed[getSubLocal(local)] = [local]
126+ }, this)
127+ if (reindexed[getSubLocal(option)]) {
128+ return reindexed[getSubLocal(option)][0]
129+ }
130+ return option
131+}

Built with git-ssb-web