git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit f2ca2ca157f5185508d7d9ac0fc3e92532a793cd

Merge branch 'i18n-BCP47' of https://github.com/ssbc/patchwork

Matt McKegg committed on 10/28/2017, 10:36:26 AM
Parent: 42288cf44aa8aaf32d1036942ee30c6730803575
Parent: e56f598e317e0f73881bc6004495c39c60bccf65

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