Skip to content

A full-featured download manager.

fix: i18n get language by electron locale

Dr_rOot2bc4a8c61e2a
diff --git a/src/shared/locales/index.js b/src/shared/locales/index.js
index 6d9e0a51..b043d537 100644
--- a/src/shared/locales/index.js
+++ b/src/shared/locales/index.js
@@ -111,24 +111,29 @@ function checkLngIsAvailable (locale) {
/**
* getLanguage
* @param { String } locale
- * https://electronjs.org/docs/api/locales
+ * https://www.electronjs.org/docs/api/app#appgetlocale
*
* Only these locales need to add a `startsWith` fallback
* when there are with the same prefix
*
+ * ar, ar-XB
* de, de-AT, de-CH, de-DE
- * en, en-AU, en-CA, en-GB, en-NZ, en-US, en-ZA
- * es, es-419
+ * en, en-AU, en-CA, en-GB, en-IN, en-NZ, en-US, en-XA, en-ZA
+ * es, es-419, es-AR, es-CL, es-CO, es-CR, es-ES, es-HN, es-MX, es-PE, es-US, es-UY, es-VE
* fr, fr-CA, fr-CH, fr-FR
* it, it-CH, it-IT
* pt, pt-BR, pt-PT
- * zh, zh-CN, zh-TW
+ * zh, zh-CN, zh-HK, zh-TW
*/
export function getLanguage (locale = 'en-US') {
if (checkLngIsAvailable(locale)) {
return locale
}
+ if (locale.startsWith('ar')) {
+ return 'ar'
+ }
+
if (locale.startsWith('de')) {
return 'de'
}
@@ -141,17 +146,25 @@ export function getLanguage (locale = 'en-US') {
return 'es'
}
+ if (locale.startsWith('fr')) {
+ return 'fr'
+ }
+
+ if (locale.startsWith('it')) {
+ return 'it'
+ }
+
// If there is a pt-PT translation in the future,
// here will fallback to pt-PT.
if (locale.startsWith('pt')) {
return 'pt-BR'
}
- if (locale.startsWith('zh')) {
- return 'zh-CN'
+ if (locale === 'zh-HK') {
+ return 'zh-TW'
}
- if (locale.startsWith('fr')) {
- return 'fr'
+ if (locale.startsWith('zh')) {
+ return 'zh-CN'
}
}