From 858244988cc3be822f9f8bd216de07844eca2dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Schauer-K=C3=B6ckeis?= Date: Wed, 11 Sep 2024 16:44:43 +0200 Subject: [PATCH 1/4] Feat: Systemwide Default Language MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Schauer-Köckeis --- src/i18n/index.js | 28 +++- src/i18n/locales/de.json | 3 + src/i18n/locales/en.json | 3 + src/i18n/locales/es.json | 3 + src/i18n/locales/fr.json | 3 + src/i18n/locales/hi.json | 3 + src/i18n/locales/it.json | 3 + src/i18n/locales/ja.json | 3 + src/i18n/locales/pl.json | 3 + src/i18n/locales/pt-BR.json | 3 + src/i18n/locales/pt.json | 3 + src/i18n/locales/ru.json | 3 + src/i18n/locales/uk-UA.json | 3 + src/i18n/locales/zh.json | 3 + src/router/index.js | 12 ++ src/views/administration/AdminMenu.vue | 5 + src/views/administration/Administration.vue | 2 + .../configuration/DefaultLanguage.vue | 128 ++++++++++++++++++ 18 files changed, 209 insertions(+), 5 deletions(-) create mode 100644 src/views/administration/configuration/DefaultLanguage.vue diff --git a/src/i18n/index.js b/src/i18n/index.js index ff4d8e246..30fffd201 100644 --- a/src/i18n/index.js +++ b/src/i18n/index.js @@ -1,8 +1,21 @@ import Vue from 'vue'; import VueI18n from 'vue-i18n'; +import axios from 'axios'; +import api from '../shared/api.json'; Vue.use(VueI18n); +async function getDefaultLanguage() { + try { + let url = `${api.BASE_URL}/${api.URL_CONFIG_PROPERTY}/public/general/default.language`; + let response = await axios.get(url); + return decodeURIComponent(response.data.propertyValue); + } catch (error) { + console.error('Error fetching default language:', error); + return ''; + } +} + function loadLocaleMessages() { const locales = require.context( './locales', @@ -54,15 +67,20 @@ function matchLocale(requestedLocale) { ); return 'en'; } - const i18n = new VueI18n({ - locale: matchLocale( + locale: 'en', + fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'en', + messages: localeMessages, +}); + +getDefaultLanguage().then((defaultLanguage) => { + const matchedLocale = matchLocale( (localStorage && localStorage.getItem('Locale')) || + defaultLanguage || navigator.language || navigator.userLanguage, - ), - fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'en', - messages: localeMessages, + ); + i18n.locale = matchedLocale; }); export default i18n; diff --git a/src/i18n/locales/de.json b/src/i18n/locales/de.json index 979d5e06d..5a3ef72c7 100644 --- a/src/i18n/locales/de.json +++ b/src/i18n/locales/de.json @@ -68,6 +68,9 @@ "create_template": "Vorlage erstellen", "create_user": "Benutzer erstellen", "default": "Standard", + "default_language": "Standardsprache", + "default_language_desc": "Standardsprache, die für alle verwendet wird, wenn sie keine angegeben haben. \nWenn dies deaktiviert ist, wird die Sprache des Browsers verwendet.", + "default_language_enable": "Aktivieren Sie die Standardsprache", "default_template_restored": "Standardvorlagen wiederhergestellt", "defectdojo": "DefectDojo", "delete_alert": "Alarm löschen", diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 04ea8105f..7d97caa36 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -68,6 +68,9 @@ "create_template": "Create Template", "create_user": "Create User", "default": "Default", + "default_language": "Default Language", + "default_language_desc": "Default language, which is used for everyone, when they didn't specify one. Langauge from Browser will be used, when this is disabled.", + "default_language_enable": "Enable Default language", "default_template_restored": "Default templates restored", "defectdojo": "DefectDojo", "delete_alert": "Delete Alert", diff --git a/src/i18n/locales/es.json b/src/i18n/locales/es.json index 7297b7afa..0cd9b5078 100644 --- a/src/i18n/locales/es.json +++ b/src/i18n/locales/es.json @@ -68,6 +68,9 @@ "create_template": "Crear plantilla", "create_user": "Crear usuario", "default": "Por defecto", + "default_language": "Idioma predeterminado", + "default_language_desc": "Idioma predeterminado, que se usa para todos, cuando no especificaron uno. \nSe utilizará el idioma del navegador cuando esté deshabilitado.", + "default_language_enable": "Habilitar idioma predeterminado", "default_template_restored": "Plantillas predeterminadas restauradas", "defectdojo": "DefectoDojo", "delete_alert": "Eliminar alerta", diff --git a/src/i18n/locales/fr.json b/src/i18n/locales/fr.json index 14bba4b07..9888ddc84 100644 --- a/src/i18n/locales/fr.json +++ b/src/i18n/locales/fr.json @@ -68,6 +68,9 @@ "create_template": "Créer un modèle", "create_user": "Créer un utilisateur", "default": "Défaut", + "default_language": "Langue par défaut", + "default_language_desc": "Langue par défaut, qui est utilisée par tout le monde, lorsqu'ils n'en ont pas spécifié. \nLa langue du navigateur sera utilisée lorsqu'elle est désactivée.", + "default_language_enable": "Activer la langue par défaut", "default_template_restored": "Modèles par défaut restaurés", "defectdojo": "DefectDojo", "delete_alert": "Supprimer l'alerte", diff --git a/src/i18n/locales/hi.json b/src/i18n/locales/hi.json index 47dbed1fe..e19322f2b 100644 --- a/src/i18n/locales/hi.json +++ b/src/i18n/locales/hi.json @@ -68,6 +68,9 @@ "create_template": "टेम्पलेट बनाएं", "create_user": "उपयोगकर्ता बनाइये", "default": "गलती करना", + "default_language": "डिफ़ॉल्ट भाषा", + "default_language_desc": "डिफ़ॉल्ट भाषा, जिसका उपयोग सभी के लिए किया जाता है, जब उन्होंने किसी एक को निर्दिष्ट नहीं किया हो। \nइसे अक्षम करने पर ब्राउज़र से लैंग्वेज का उपयोग किया जाएगा।", + "default_language_enable": "डिफ़ॉल्ट भाषा सक्षम करें", "default_template_restored": "डिफ़ॉल्ट टेम्पलेट्स पुनर्स्थापित किए गए", "defectdojo": "डिफेक्टडोजो", "delete_alert": "अलर्ट हटाएं", diff --git a/src/i18n/locales/it.json b/src/i18n/locales/it.json index c58b0c783..9048529ae 100644 --- a/src/i18n/locales/it.json +++ b/src/i18n/locales/it.json @@ -68,6 +68,9 @@ "create_template": "Crea modello", "create_user": "Creare un utente", "default": "Predefinito", + "default_language": "Lingua predefinita", + "default_language_desc": "Lingua predefinita, utilizzata da tutti quando non ne è stata specificata una. \nQuando questa opzione è disabilitata, verrà utilizzata la lingua del browser.", + "default_language_enable": "Abilita la lingua predefinita", "default_template_restored": "Modelli predefiniti ripristinati", "defectdojo": "DifettoDojo", "delete_alert": "Elimina avviso", diff --git a/src/i18n/locales/ja.json b/src/i18n/locales/ja.json index b054b3749..fac847a38 100644 --- a/src/i18n/locales/ja.json +++ b/src/i18n/locales/ja.json @@ -68,6 +68,9 @@ "create_template": "テンプレートを作成", "create_user": "ユーザーを作成", "default": "デフォルト", + "default_language": "デフォルトの言語", + "default_language_desc": "デフォルトの言語。指定しなかった場合に全員に使用されます。\nこれを無効にすると、ブラウザの言語が使用されます。", + "default_language_enable": "デフォルト言語を有効にする", "default_template_restored": "デフォルトのテンプレートが復元されました", "defectdojo": "DefectDojo", "delete_alert": "アラートを削除", diff --git a/src/i18n/locales/pl.json b/src/i18n/locales/pl.json index 83cebffef..f2f4080f3 100644 --- a/src/i18n/locales/pl.json +++ b/src/i18n/locales/pl.json @@ -68,6 +68,9 @@ "create_template": "Utwórz szablon", "create_user": "Stwórz użytkownika", "default": "Domyślny", + "default_language": "Domyślny język", + "default_language_desc": "Domyślny język, którego używają wszyscy, jeśli go nie określili. \nJeśli ta opcja jest wyłączona, używany będzie język z przeglądarki.", + "default_language_enable": "Włącz język domyślny", "default_template_restored": "Przywrócono domyślne szablony", "defectdojo": "DefektDojo", "delete_alert": "Usuń alert", diff --git a/src/i18n/locales/pt-BR.json b/src/i18n/locales/pt-BR.json index 0b7bc9225..02702639a 100644 --- a/src/i18n/locales/pt-BR.json +++ b/src/i18n/locales/pt-BR.json @@ -68,6 +68,9 @@ "create_template": "Criar modelo", "create_user": "Criar usuário", "default": "Padrão", + "default_language": "Idioma padrão", + "default_language_desc": "Idioma padrão, que é usado por todos, quando não especificam um. \nO idioma do navegador será usado quando estiver desabilitado.", + "default_language_enable": "Ativar idioma padrão", "default_template_restored": "Modelos padrão restaurados", "defectdojo": "DefectDojo", "delete_alert": "Excluir alerta", diff --git a/src/i18n/locales/pt.json b/src/i18n/locales/pt.json index 9b9ea0e53..ae51eccd0 100644 --- a/src/i18n/locales/pt.json +++ b/src/i18n/locales/pt.json @@ -68,6 +68,9 @@ "create_template": "Criar modelo", "create_user": "Criar utilizador", "default": "Padrão", + "default_language": "Idioma padrão", + "default_language_desc": "Idioma padrão, que é usado por todos, quando não especificam um. \nO idioma do navegador será usado quando estiver desabilitado.", + "default_language_enable": "Ativar idioma padrão", "default_template_restored": "Modelos padrão restaurados", "defectdojo": "DefectDojo", "delete_alert": "Excluir alerta", diff --git a/src/i18n/locales/ru.json b/src/i18n/locales/ru.json index 149ccc33d..64e14d605 100644 --- a/src/i18n/locales/ru.json +++ b/src/i18n/locales/ru.json @@ -68,6 +68,9 @@ "create_template": "Создать шаблон", "create_user": "Создать пользователя", "default": "По умолчанию", + "default_language": "Язык по умолчанию", + "default_language_desc": "Язык по умолчанию, который используется всеми, если они его не указали. \nЕсли эта опция отключена, будет использоваться язык из браузера.", + "default_language_enable": "Включить язык по умолчанию", "default_template_restored": "Шаблоны по умолчанию восстановлены", "defectdojo": "ДефектДодзё", "delete_alert": "Удалить оповещение", diff --git a/src/i18n/locales/uk-UA.json b/src/i18n/locales/uk-UA.json index afa35d362..0e90bb660 100644 --- a/src/i18n/locales/uk-UA.json +++ b/src/i18n/locales/uk-UA.json @@ -68,6 +68,9 @@ "create_template": "Створити шаблон", "create_user": "Створити користувача", "default": "За замовчуванням", + "default_language": "Мова за замовчуванням", + "default_language_desc": "Мова за замовчуванням, яка використовується для всіх, якщо вони не вказали її. \nЯкщо цей параметр вимкнено, використовуватиметься мова з браузера.", + "default_language_enable": "Увімкнути мову за замовчуванням", "default_template_restored": "Стандартні шаблони відновлено", "defectdojo": "DefectDojo", "delete_alert": "Видалити сповіщення", diff --git a/src/i18n/locales/zh.json b/src/i18n/locales/zh.json index bcfa26d72..0ae34c9b6 100644 --- a/src/i18n/locales/zh.json +++ b/src/i18n/locales/zh.json @@ -68,6 +68,9 @@ "create_template": "创建模板", "create_user": "创建用户", "default": "默认", + "default_language": "默认语言", + "default_language_desc": "默认语言,当他们没有指定一种语言时,每个人都使用它。\n禁用时,将使用浏览器中的语言。", + "default_language_enable": "启用默认语言", "default_template_restored": "恢复默认模板", "defectdojo": "DefectDojo (一个开源的应用程序安全漏洞协调和管理平台)", "delete_alert": "删除告警", diff --git a/src/router/index.js b/src/router/index.js index 3f66346dc..108fef22d 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -28,6 +28,8 @@ const BomFormats = () => import('@/views/administration/configuration/BomFormats'); const WelcomeMessage = () => import('@/views/administration/configuration/WelcomeMessage'); +const DefaultLanguage = () => + import('@/views/administration/configuration/DefaultLanguage'); const Email = () => import('@/views/administration/configuration/Email'); const Jira = () => import('@/views/administration/configuration/JiraConfig'); const InternalComponents = () => @@ -360,6 +362,16 @@ function configRoutes() { permission: 'SYSTEM_CONFIGURATION', }, }, + { + path: 'configuration/defaultLanguage', + component: DefaultLanguage, + meta: { + title: i18n.t('message.administration'), + i18n: 'message.administration', + sectionPath: '/admin', + permission: 'SYSTEM_CONFIGURATION', + }, + }, { path: 'configuration/email', component: Email, diff --git a/src/views/administration/AdminMenu.vue b/src/views/administration/AdminMenu.vue index 47f86976f..56a4901b9 100644 --- a/src/views/administration/AdminMenu.vue +++ b/src/views/administration/AdminMenu.vue @@ -91,6 +91,11 @@ export default { name: this.$t('admin.bom_formats'), route: 'configuration/bomFormats', }, + { + component: 'DefaultLanguage', + name: this.$t('admin.default_language'), + route: 'configuration/defaultLanguage', + }, { component: 'Email', name: this.$t('admin.email'), diff --git a/src/views/administration/Administration.vue b/src/views/administration/Administration.vue index 5034e2931..977598128 100644 --- a/src/views/administration/Administration.vue +++ b/src/views/administration/Administration.vue @@ -20,6 +20,7 @@ import AdminMenu from './AdminMenu'; // Configuration plugins import BomFormats from './configuration/BomFormats'; +import DefaultLanguage from './configuration/DefaultLanguage'; import Email from './configuration/Email'; import General from './configuration/General'; import InternalComponents from './configuration/InternalComponents'; @@ -75,6 +76,7 @@ export default { General, WelcomeMessage, BomFormats, + DefaultLanguage, Email, Jira, InternalComponents, diff --git a/src/views/administration/configuration/DefaultLanguage.vue b/src/views/administration/configuration/DefaultLanguage.vue new file mode 100644 index 000000000..fac1ff5ea --- /dev/null +++ b/src/views/administration/configuration/DefaultLanguage.vue @@ -0,0 +1,128 @@ + + + From da0ad492aec06972c1c604405f53a58598912838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Schauer-K=C3=B6ckeis?= Date: Tue, 17 Sep 2024 13:32:25 +0200 Subject: [PATCH 2/4] Moved default Language to General MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Schauer-Köckeis --- src/i18n/index.js | 2 +- src/router/index.js | 12 -- src/views/administration/AdminMenu.vue | 5 - src/views/administration/Administration.vue | 2 - .../configuration/DefaultLanguage.vue | 128 ------------------ .../administration/configuration/General.vue | 121 ++++++++++++++--- 6 files changed, 103 insertions(+), 167 deletions(-) delete mode 100644 src/views/administration/configuration/DefaultLanguage.vue diff --git a/src/i18n/index.js b/src/i18n/index.js index 30fffd201..7112c298d 100644 --- a/src/i18n/index.js +++ b/src/i18n/index.js @@ -7,7 +7,7 @@ Vue.use(VueI18n); async function getDefaultLanguage() { try { - let url = `${api.BASE_URL}/${api.URL_CONFIG_PROPERTY}/public/general/default.language`; + let url = `${api.BASE_URL}/${api.URL_CONFIG_PROPERTY}/public/general/default.locale`; let response = await axios.get(url); return decodeURIComponent(response.data.propertyValue); } catch (error) { diff --git a/src/router/index.js b/src/router/index.js index 108fef22d..3f66346dc 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -28,8 +28,6 @@ const BomFormats = () => import('@/views/administration/configuration/BomFormats'); const WelcomeMessage = () => import('@/views/administration/configuration/WelcomeMessage'); -const DefaultLanguage = () => - import('@/views/administration/configuration/DefaultLanguage'); const Email = () => import('@/views/administration/configuration/Email'); const Jira = () => import('@/views/administration/configuration/JiraConfig'); const InternalComponents = () => @@ -362,16 +360,6 @@ function configRoutes() { permission: 'SYSTEM_CONFIGURATION', }, }, - { - path: 'configuration/defaultLanguage', - component: DefaultLanguage, - meta: { - title: i18n.t('message.administration'), - i18n: 'message.administration', - sectionPath: '/admin', - permission: 'SYSTEM_CONFIGURATION', - }, - }, { path: 'configuration/email', component: Email, diff --git a/src/views/administration/AdminMenu.vue b/src/views/administration/AdminMenu.vue index 56a4901b9..47f86976f 100644 --- a/src/views/administration/AdminMenu.vue +++ b/src/views/administration/AdminMenu.vue @@ -91,11 +91,6 @@ export default { name: this.$t('admin.bom_formats'), route: 'configuration/bomFormats', }, - { - component: 'DefaultLanguage', - name: this.$t('admin.default_language'), - route: 'configuration/defaultLanguage', - }, { component: 'Email', name: this.$t('admin.email'), diff --git a/src/views/administration/Administration.vue b/src/views/administration/Administration.vue index 977598128..5034e2931 100644 --- a/src/views/administration/Administration.vue +++ b/src/views/administration/Administration.vue @@ -20,7 +20,6 @@ import AdminMenu from './AdminMenu'; // Configuration plugins import BomFormats from './configuration/BomFormats'; -import DefaultLanguage from './configuration/DefaultLanguage'; import Email from './configuration/Email'; import General from './configuration/General'; import InternalComponents from './configuration/InternalComponents'; @@ -76,7 +75,6 @@ export default { General, WelcomeMessage, BomFormats, - DefaultLanguage, Email, Jira, InternalComponents, diff --git a/src/views/administration/configuration/DefaultLanguage.vue b/src/views/administration/configuration/DefaultLanguage.vue deleted file mode 100644 index fac1ff5ea..000000000 --- a/src/views/administration/configuration/DefaultLanguage.vue +++ /dev/null @@ -1,128 +0,0 @@ - - - diff --git a/src/views/administration/configuration/General.vue b/src/views/administration/configuration/General.vue index e4f6f4b35..109fd2711 100644 --- a/src/views/administration/configuration/General.vue +++ b/src/views/administration/configuration/General.vue @@ -1,32 +1,79 @@ From 9ff2b282eaeaef325e37b2a6956ab084bdb1880e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Schauer-K=C3=B6ckeis?= Date: Tue, 17 Sep 2024 15:41:26 +0200 Subject: [PATCH 3/4] Improved the getting of Default locale MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Schauer-Köckeis --- .../administration/configuration/General.vue | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/views/administration/configuration/General.vue b/src/views/administration/configuration/General.vue index 109fd2711..185b2077f 100644 --- a/src/views/administration/configuration/General.vue +++ b/src/views/administration/configuration/General.vue @@ -64,7 +64,7 @@ class="px-4" @click="saveChanges" :disabled=" - this.isDefaultLanguageEnabled && this.defaultLanguage === ' ' + this.isDefaultLanguageEnabled && this.defaultLanguage === '' " >{{ $t('message.update') }} @@ -119,9 +119,7 @@ export default { { groupName: 'general', propertyName: 'default.locale', - propertyValue: encodeURIComponent( - this.isDefaultLanguageEnabled ? this.defaultLanguage : ' ', - ), + propertyValue: this.isDefaultLanguageEnabled ? this.defaultLanguage : null, }, ]); }, @@ -160,15 +158,13 @@ export default { case 'badge.enabled': this.isBadgesEnabled = common.toBoolean(item.propertyValue); break; + case 'default.locale': + this.isDefaultLanguageEnabled = !!common.trimToNull(item.propertyValue); + this.defaultLanguage = this.isDefaultLanguageEnabled ? item.propertyValue : ''; + break; } } }); - let url = `${this.$api.BASE_URL}/${this.$api.URL_CONFIG_PROPERTY}/public/general/default.locale`; - this.axios.get(url).then((response) => { - this.defaultLanguage = decodeURIComponent(response.data.propertyValue); - this.isDefaultLanguageEnabled = - decodeURIComponent(response.data.propertyValue) !== ' '; - }); }, }; From 31397542646a772ee08448aa8dbdf467fcc9e1be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Schauer-K=C3=B6ckeis?= Date: Tue, 17 Sep 2024 16:11:30 +0200 Subject: [PATCH 4/4] Fixed linter issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Schauer-Köckeis --- .../administration/configuration/General.vue | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/views/administration/configuration/General.vue b/src/views/administration/configuration/General.vue index 185b2077f..8f75934e0 100644 --- a/src/views/administration/configuration/General.vue +++ b/src/views/administration/configuration/General.vue @@ -63,9 +63,7 @@ variant="outline-primary" class="px-4" @click="saveChanges" - :disabled=" - this.isDefaultLanguageEnabled && this.defaultLanguage === '' - " + :disabled="this.isDefaultLanguageEnabled && this.defaultLanguage === ''" >{{ $t('message.update') }} @@ -119,7 +117,9 @@ export default { { groupName: 'general', propertyName: 'default.locale', - propertyValue: this.isDefaultLanguageEnabled ? this.defaultLanguage : null, + propertyValue: this.isDefaultLanguageEnabled + ? this.defaultLanguage + : null, }, ]); }, @@ -159,8 +159,12 @@ export default { this.isBadgesEnabled = common.toBoolean(item.propertyValue); break; case 'default.locale': - this.isDefaultLanguageEnabled = !!common.trimToNull(item.propertyValue); - this.defaultLanguage = this.isDefaultLanguageEnabled ? item.propertyValue : ''; + this.isDefaultLanguageEnabled = !!common.trimToNull( + item.propertyValue, + ); + this.defaultLanguage = this.isDefaultLanguageEnabled + ? item.propertyValue + : ''; break; } }