diff --git a/src/renderer/components/general-settings/general-settings.js b/src/renderer/components/general-settings/general-settings.js index 7d015b95..f4428570 100644 --- a/src/renderer/components/general-settings/general-settings.js +++ b/src/renderer/components/general-settings/general-settings.js @@ -103,6 +103,10 @@ export default Vue.extend({ const names = [] Object.keys(this.$i18n.messages).forEach((locale) => { + if (locale === 'system') { + names.push('System Language') + return + } const localeName = this.$i18n.messages[locale]['Locale Name'] if (typeof localeName !== 'undefined') { names.push(localeName) diff --git a/src/renderer/main.js b/src/renderer/main.js index 4404b54c..0cdbd45b 100644 --- a/src/renderer/main.js +++ b/src/renderer/main.js @@ -27,26 +27,36 @@ Vue.component('FontAwesomeIcon', FontAwesomeIcon) Vue.use(VueI18n) // List of locales approved for use -const activeLocales = ['en-US', 'en_GB', 'ar', 'bg', 'cs', 'da', 'de-DE', 'el', 'es', 'es-MX', 'fi', 'fr-FR', 'gl', 'he', 'hu', 'hr', 'id', 'is', 'it', 'ja', 'nb_NO', 'nl', 'nn', 'pl', 'pt', 'pt-BR', 'pt-PT', 'ru', 'sk', 'sl', 'sv', 'tr', 'uk', 'vi', 'zh-CN', 'zh-TW'] +const activeLocales = ['system', 'en-US', 'en_GB', 'ar', 'bg', 'cs', 'da', 'de-DE', 'el', 'es', 'es-MX', 'fi', 'fr-FR', 'gl', 'he', 'hu', 'hr', 'id', 'is', 'it', 'ja', 'nb_NO', 'nl', 'nn', 'pl', 'pt', 'pt-BR', 'pt-PT', 'ru', 'sk', 'sl', 'sv', 'tr', 'uk', 'vi', 'zh-CN', 'zh-TW'] const messages = {} /* eslint-disable-next-line */ const fileLocation = isDev ? 'static/locales/' : `${__dirname}/static/locales/` // Take active locales and load respective YAML file activeLocales.forEach((locale) => { + // Import elctrons app object to access getLocale function + const { app } = require('@electron/remote') try { // File location when running in dev - const doc = yaml.load(fs.readFileSync(`${fileLocation}${locale}.yaml`)) - messages[locale] = doc + if (locale === 'system') { + const systemsLocale = activeLocales.filter((currentValue) => { return currentValue.startsWith(app.getLocale()) }) + if (systemsLocale.length) { + const doc = yaml.load(fs.readFileSync(`${fileLocation}${systemsLocale[0]}.yaml`)) + messages[locale] = doc + } + } else { + const doc = yaml.load(fs.readFileSync(`${fileLocation}${locale}.yaml`)) + messages[locale] = doc + } } catch (e) { console.log(e) } }) const i18n = new VueI18n({ - locale: 'en-US', // set locale + locale: 'system', // set locale standard is to follow the systems locale fallbackLocale: { - default: 'en-US' + default: 'en-US' // for the case systems locale has no corresponding .yaml file en-US gets set }, messages // set locale messages })