From 1435579ddfd4d45fb7093d5f34cb9ea42d2fb107 Mon Sep 17 00:00:00 2001 From: nscuro Date: Mon, 22 Apr 2024 22:18:49 +0200 Subject: [PATCH 1/7] Add locale picker to header This is to make it easier to switch languages, without having to fiddle with browser settings. Signed-off-by: nscuro --- src/containers/DefaultHeader.vue | 3 ++ src/i18n/index.js | 43 +++++++++++++++++++++++++-- src/i18n/locales/de.json | 37 ++++++++++++++++------- src/i18n/locales/en.json | 29 +++++++++++++----- src/i18n/locales/es.json | 37 ++++++++++++++++------- src/i18n/locales/fr.json | 37 ++++++++++++++++------- src/i18n/locales/hi.json | 37 ++++++++++++++++------- src/i18n/locales/it.json | 37 ++++++++++++++++------- src/i18n/locales/ja.json | 37 ++++++++++++++++------- src/i18n/locales/pl.json | 37 ++++++++++++++++------- src/i18n/locales/pt-BR.json | 37 ++++++++++++++++------- src/i18n/locales/pt.json | 37 ++++++++++++++++------- src/i18n/locales/ru.json | 37 ++++++++++++++++------- src/i18n/locales/zh.json | 37 ++++++++++++++++------- src/views/components/LocalePicker.vue | 41 +++++++++++++++++++++++++ 15 files changed, 393 insertions(+), 130 deletions(-) create mode 100644 src/views/components/LocalePicker.vue diff --git a/src/containers/DefaultHeader.vue b/src/containers/DefaultHeader.vue index 55f47d8f2..f38253881 100644 --- a/src/containers/DefaultHeader.vue +++ b/src/containers/DefaultHeader.vue @@ -12,12 +12,14 @@ + From 74ca02787081c9781df2e6b2bfbbf7482b0a59c2 Mon Sep 17 00:00:00 2001 From: nscuro Date: Mon, 22 Apr 2024 22:59:16 +0200 Subject: [PATCH 2/7] Move vue-i18n-extract flags to config file; Add excludes for `language.*` Signed-off-by: nscuro --- package.json | 2 +- vue-i18n-extract.config.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 vue-i18n-extract.config.js diff --git a/package.json b/package.json index 661c14d7e..eef9fea2e 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "eslint-fix": "eslint --ext .js,.vue,.json,.md,.yaml --fix . --report-unused-disable-directives", "prettier": "prettier --check --cache '**/*.{js,vue,json,md,yaml}'", "prettier-fix": "prettier --write --cache '**/*.{js,vue,json,md,yaml}'", - "vue-i18n-extract": "vue-i18n-extract report --vueFiles 'src/**/*.?(vue|js)' --languageFiles 'src/i18n/locales/*.json' --exclude 'validation.max_value' --exclude 'validation.min_value' --exclude 'validation.confirmed' --exclude 'validation.required' --ci --ci" + "vue-i18n-extract": "vue-i18n-extract report --ci" }, "dependencies": { "@coreui/coreui": "2.1.16", diff --git a/vue-i18n-extract.config.js b/vue-i18n-extract.config.js new file mode 100644 index 000000000..e5e1349b8 --- /dev/null +++ b/vue-i18n-extract.config.js @@ -0,0 +1,22 @@ +module.exports = { + exclude: [ + "language.de", + "language.en", + "language.es", + "language.fr", + "language.hi", + "language.it", + "language.ja", + "language.pl", + "language.pt", + "language.pt-BR", + "language.ru", + "language.zh", + "validation.confirmed", + "validation.max_value", + "validation.min_value", + "validation.required", + ], + languageFiles: "src/i18n/locales/*.json", + vueFiles: "src/**/*.?(vue|js)" +} From 6875e37353d6b1518eeb471c0fbffc864d727b74 Mon Sep 17 00:00:00 2001 From: nscuro Date: Mon, 22 Apr 2024 23:07:29 +0200 Subject: [PATCH 3/7] Make prettier happy Signed-off-by: nscuro --- vue-i18n-extract.config.js | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/vue-i18n-extract.config.js b/vue-i18n-extract.config.js index e5e1349b8..18a72bac8 100644 --- a/vue-i18n-extract.config.js +++ b/vue-i18n-extract.config.js @@ -1,22 +1,22 @@ module.exports = { exclude: [ - "language.de", - "language.en", - "language.es", - "language.fr", - "language.hi", - "language.it", - "language.ja", - "language.pl", - "language.pt", - "language.pt-BR", - "language.ru", - "language.zh", - "validation.confirmed", - "validation.max_value", - "validation.min_value", - "validation.required", + 'language.de', + 'language.en', + 'language.es', + 'language.fr', + 'language.hi', + 'language.it', + 'language.ja', + 'language.pl', + 'language.pt', + 'language.pt-BR', + 'language.ru', + 'language.zh', + 'validation.confirmed', + 'validation.max_value', + 'validation.min_value', + 'validation.required', ], - languageFiles: "src/i18n/locales/*.json", - vueFiles: "src/**/*.?(vue|js)" -} + languageFiles: 'src/i18n/locales/*.json', + vueFiles: 'src/**/*.?(vue|js)', +}; From fe6a6c7c73a7455a3a02680227b8ee31bf0ee763 Mon Sep 17 00:00:00 2001 From: nscuro Date: Tue, 23 Apr 2024 11:38:01 +0200 Subject: [PATCH 4/7] Display locales as country flags rather than language codes Thanks @fnxpt for the suggestion! Signed-off-by: nscuro --- src/views/components/LocalePicker.vue | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/views/components/LocalePicker.vue b/src/views/components/LocalePicker.vue index cf5cf6e68..d597cd633 100644 --- a/src/views/components/LocalePicker.vue +++ b/src/views/components/LocalePicker.vue @@ -14,7 +14,7 @@ :value="locale" :title="$t(`language.${locale}`)" > - {{ locale.toUpperCase() }} + {{ localeToFlag(locale) }} @@ -36,6 +36,26 @@ export default { localStorage.setItem('Locale', value); this.$i18n.locale = value; }, + localeToFlag: function (locale) { + // Largely taken from wojtekmaj/country-code-to-flag-emoji. Adopted to be able to deal with locale codes as inputs. + // https://github.com/wojtekmaj/country-code-to-flag-emoji/blob/ff0d3d2dd9680b6f860d85fc9e713e93e396adb7/src/index.ts + + let countryCode = locale.split('-').pop().toUpperCase(); + if (countryCode === 'EN') { + countryCode = 'US'; // Sorry Britain! + } else if (countryCode === 'HI') { + countryCode = 'IN'; + } else if (countryCode === 'JA') { + countryCode = 'JP'; + } else if (countryCode === 'ZH') { + countryCode = 'CN'; + } + + return Array.from(countryCode) + .map((letter) => letter.toLowerCase().charCodeAt(0) + 127365) + .map((charCode) => String.fromCodePoint(charCode)) + .join(''); + }, }, }; From b114d9d6616d66a3f6a72522790056a61236f8e7 Mon Sep 17 00:00:00 2001 From: nscuro Date: Tue, 23 Apr 2024 19:56:21 +0200 Subject: [PATCH 5/7] Move locale picker to profile dropdown Signed-off-by: nscuro --- src/containers/DefaultHeader.vue | 3 --- src/containers/DefaultHeaderProfileDropdown.vue | 11 +++++++++++ src/views/components/LocalePicker.vue | 7 ++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/containers/DefaultHeader.vue b/src/containers/DefaultHeader.vue index f38253881..55f47d8f2 100644 --- a/src/containers/DefaultHeader.vue +++ b/src/containers/DefaultHeader.vue @@ -12,14 +12,12 @@ -