From: Tiago Melo Date: Fri, 7 Feb 2020 17:17:35 +0000 (-0100) Subject: mgr/dashboard: Fix i18n configuration X-Git-Tag: v16.1.0~2351^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6050790f13066217429405f1acbed1ff9d713ec0;p=ceph.git mgr/dashboard: Fix i18n configuration Signed-off-by: Tiago Melo --- diff --git a/src/pybind/mgr/dashboard/frontend/angular.json b/src/pybind/mgr/dashboard/frontend/angular.json index beaeb5a549c5..310b340d8039 100644 --- a/src/pybind/mgr/dashboard/frontend/angular.json +++ b/src/pybind/mgr/dashboard/frontend/angular.json @@ -5,59 +5,20 @@ "projects": { "ceph-dashboard": { "i18n": { + "sourceLocale": { "code": "en", "baseHref": "" }, "locales": { - "cs": { - "translation": "src/locale/messages.cs.xlf", - "baseHref": "" - }, - "de-DE": { - "translation": "src/locale/messages.de-DE.xlf", - "baseHref": "" - }, - "en-US": { - "translation": "src/locale/messages.en-US.xlf", - "baseHref": "" - }, - "es-ES": { - "translation": "src/locale/messages.es-ES.xlf", - "baseHref": "" - }, - "fr-FR": { - "translation": "src/locale/messages.fr-FR.xlf", - "baseHref": "" - }, - "id-ID": { - "translation": "src/locale/messages.id-ID.xlf", - "baseHref": "" - }, - "it-IT": { - "translation": "src/locale/messages.it-IT.xlf", - "baseHref": "" - }, - "ja-JP": { - "translation": "src/locale/messages.ja-JP.xlf", - "baseHref": "" - }, - "ko-KR": { - "translation": "src/locale/messages.ko-KR.xlf", - "baseHref": "" - }, - "pl-PL": { - "translation": "src/locale/messages.pl-PL.xlf", - "baseHref": "" - }, - "pt-BR": { - "translation": "src/locale/messages.pt-BR.xlf", - "baseHref": "" - }, - "zh-CN": { - "translation": "src/locale/messages.zh-CN.xlf", - "baseHref": "" - }, - "zh-TW": { - "translation": "src/locale/messages.zh-TW.xlf", - "baseHref": "" - } + "cs": { "translation": "src/locale/messages.cs.xlf", "baseHref": "" }, + "de": { "translation": "src/locale/messages.de-DE.xlf", "baseHref": "" }, + "es": { "translation": "src/locale/messages.es-ES.xlf", "baseHref": "" }, + "fr": { "translation": "src/locale/messages.fr-FR.xlf", "baseHref": "" }, + "id": { "translation": "src/locale/messages.id-ID.xlf", "baseHref": "" }, + "it": { "translation": "src/locale/messages.it-IT.xlf", "baseHref": "" }, + "ja": { "translation": "src/locale/messages.ja-JP.xlf", "baseHref": "" }, + "ko": { "translation": "src/locale/messages.ko-KR.xlf", "baseHref": "" }, + "pl": { "translation": "src/locale/messages.pl-PL.xlf", "baseHref": "" }, + "pt": { "translation": "src/locale/messages.pt-BR.xlf", "baseHref": "" }, + "zh-Hans": { "translation": "src/locale/messages.zh-CN.xlf", "baseHref": "" }, + "zh-Hant": { "translation": "src/locale/messages.zh-TW.xlf", "baseHref": "" } } }, "root": "", @@ -74,6 +35,7 @@ "main": "src/main.ts", "tsConfig": "src/tsconfig.app.json", "polyfills": "src/polyfills.ts", + "deleteOutputPath": false, "assets": [ "src/assets", "src/favicon.ico", @@ -128,160 +90,43 @@ ] }, "cs": { - "budgets": [ - { - "type": "anyComponentStyle", - "maximumWarning": "6kb" - } - ], - "localize": [ - "cs" - ], - "outputPath": "dist" + "localize": ["cs"] }, "de-DE": { - "budgets": [ - { - "type": "anyComponentStyle", - "maximumWarning": "6kb" - } - ], - "localize": [ - "de-DE" - ], - "outputPath": "dist" + "localize": ["de"] }, "en-US": { - "budgets": [ - { - "type": "anyComponentStyle", - "maximumWarning": "6kb" - } - ], - "localize": [ - "en-US" - ], - "outputPath": "dist" + "localize": ["en"] }, "es-ES": { - "budgets": [ - { - "type": "anyComponentStyle", - "maximumWarning": "6kb" - } - ], - "localize": [ - "es-ES" - ], - "outputPath": "dist" + "localize": ["es"] }, "fr-FR": { - "budgets": [ - { - "type": "anyComponentStyle", - "maximumWarning": "6kb" - } - ], - "localize": [ - "fr-FR" - ], - "outputPath": "dist" + "localize": ["fr"] }, "id-ID": { - "budgets": [ - { - "type": "anyComponentStyle", - "maximumWarning": "6kb" - } - ], - "localize": [ - "id-ID" - ], - "outputPath": "dist" + "localize": ["id"] }, "it-IT": { - "budgets": [ - { - "type": "anyComponentStyle", - "maximumWarning": "6kb" - } - ], - "localize": [ - "it-IT" - ], - "outputPath": "dist" + "localize": ["it"] }, "ja-JP": { - "budgets": [ - { - "type": "anyComponentStyle", - "maximumWarning": "6kb" - } - ], - "localize": [ - "ja-JP" - ], - "outputPath": "dist" + "localize": ["ja"] }, "ko-KR": { - "budgets": [ - { - "type": "anyComponentStyle", - "maximumWarning": "6kb" - } - ], - "localize": [ - "ko-KR" - ], - "outputPath": "dist" + "localize": ["ko"] }, "pl-PL": { - "budgets": [ - { - "type": "anyComponentStyle", - "maximumWarning": "6kb" - } - ], - "localize": [ - "pl-PL" - ], - "outputPath": "dist" + "localize": ["pl"] }, "pt-BR": { - "budgets": [ - { - "type": "anyComponentStyle", - "maximumWarning": "6kb" - } - ], - "localize": [ - "pt-BR" - ], - "outputPath": "dist" + "localize": ["pt"] }, "zh-CN": { - "budgets": [ - { - "type": "anyComponentStyle", - "maximumWarning": "6kb" - } - ], - "localize": [ - "zh-CN" - ], - "outputPath": "dist" + "localize": ["zh-Hans"] }, "zh-TW": { - "budgets": [ - { - "type": "anyComponentStyle", - "maximumWarning": "6kb" - } - ], - "localize": [ - "zh-TW" - ], - "outputPath": "dist" + "localize": ["zh-Hant"] } } }, @@ -298,35 +143,35 @@ "cs": { "browserTarget": "ceph-dashboard:build:cs" }, - "de-DE": { - "browserTarget": "ceph-dashboard:build:de-DE" + "de": { + "browserTarget": "ceph-dashboard:build:de" }, - "en-US": { - "browserTarget": "ceph-dashboard:build:en-US" + "en": { + "browserTarget": "ceph-dashboard:build:en" }, - "es-ES": { - "browserTarget": "ceph-dashboard:build:es-ES" + "es": { + "browserTarget": "ceph-dashboard:build:es" }, - "fr-FR": { - "browserTarget": "ceph-dashboard:build:fr-FR" + "fr": { + "browserTarget": "ceph-dashboard:build:fr" }, - "id-ID": { - "browserTarget": "ceph-dashboard:build:id-ID" + "id": { + "browserTarget": "ceph-dashboard:build:id" }, - "it-IT": { - "browserTarget": "ceph-dashboard:build:it-IT" + "it": { + "browserTarget": "ceph-dashboard:build:it" }, - "ja-JP": { - "browserTarget": "ceph-dashboard:build:ja-JP" + "ja": { + "browserTarget": "ceph-dashboard:build:ja" }, - "ko-KR": { - "browserTarget": "ceph-dashboard:build:ko-KR" + "ko": { + "browserTarget": "ceph-dashboard:build:ko" }, - "pl-PL": { - "browserTarget": "ceph-dashboard:build:pl-PL" + "pl": { + "browserTarget": "ceph-dashboard:build:pl" }, - "pt-BR": { - "browserTarget": "ceph-dashboard:build:pt-BR" + "pt": { + "browserTarget": "ceph-dashboard:build:pt" }, "zh-CN": { "browserTarget": "ceph-dashboard:build:zh-CN" @@ -371,4 +216,4 @@ "cli": { "analytics": false } -} \ No newline at end of file +} diff --git a/src/pybind/mgr/dashboard/frontend/package.json b/src/pybind/mgr/dashboard/frontend/package.json index d3fa80a1c20b..1fa5f23c90a6 100644 --- a/src/pybind/mgr/dashboard/frontend/package.json +++ b/src/pybind/mgr/dashboard/frontend/package.json @@ -8,7 +8,7 @@ "scripts": { "ng": "ng", "start": "npm run env_build && ng serve --host 0.0.0.0", - "build": "export _locale=${LOCALE:-$npm_package_config_locale}; if [ ${_locale} = $npm_package_config_locale ]; then export _file=; else export _file=src/locale/messages.${_locale}.xlf; fi; ng build --outputPath=dist/${_locale} --i18nFile=${_file} --i18nLocale=${_locale}", + "build": "export _locale=${LOCALE:-$npm_package_config_locale}; ng build --configuration=${_locale}", "prebuild": "npm run env_build", "build:cs": "LOCALE=cs npm run build", "build:de-DE": "LOCALE=de-DE npm run build", @@ -25,7 +25,7 @@ "build:zh-TW": "LOCALE=zh-TW npm run build", "env_build": "cp src/environments/environment.tpl.ts src/environments/environment.prod.ts && cp src/environments/environment.tpl.ts src/environments/environment.ts && node ./environment.build.js", "i18n": "npm run i18n:extract && npm run i18n:push && npm run i18n:pull && npm run i18n:merge", - "i18n:extract": "ng xi18n --i18n-format xlf --i18n-locale en-US --output-path locale --progress=false && ngx-extractor -i 'src/**/*.ts' -f xlf -o src/locale/messages.xlf -l en-US", + "i18n:extract": "ng xi18n --output-path locale --progress=false && ngx-extractor -i 'src/**/*.ts' -f xlf -o src/locale/messages.xlf -l en-US", "i18n:push": "npx i18ntool push -c i18n.config.json", "i18n:pull": "npx i18ntool pull -c i18n.config.json", "i18n:merge": "npx i18ntool merge -c i18n.config.json", diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/language-selector/language-selector.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/language-selector/language-selector.component.spec.ts index e3a09dba73a6..57753f17f4d1 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/language-selector/language-selector.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/language-selector/language-selector.component.spec.ts @@ -44,47 +44,47 @@ describe('LanguageSelectorComponent', () => { expectLanguageChange('cs'); }); - it('should change to de-DE', () => { - expectLanguageChange('de-DE'); + it('should change to de', () => { + expectLanguageChange('de'); }); - it('should change to es-ES', () => { - expectLanguageChange('es-ES'); + it('should change to es', () => { + expectLanguageChange('es'); }); - it('should change to fr-FR', () => { - expectLanguageChange('fr-FR'); + it('should change to fr', () => { + expectLanguageChange('fr'); }); - it('should change to id-ID', () => { - expectLanguageChange('id-ID'); + it('should change to id', () => { + expectLanguageChange('id'); }); - it('should change to it-IT', () => { - expectLanguageChange('it-IT'); + it('should change to it', () => { + expectLanguageChange('it'); }); - it('should change to ja-JP', () => { - expectLanguageChange('ja-JP'); + it('should change to ja', () => { + expectLanguageChange('ja'); }); - it('should change to ko-KR', () => { - expectLanguageChange('ko-KR'); + it('should change to ko', () => { + expectLanguageChange('ko'); }); - it('should change to pl-PL', () => { - expectLanguageChange('pl-PL'); + it('should change to pl', () => { + expectLanguageChange('pl'); }); - it('should change to pt-BR', () => { - expectLanguageChange('pt-BR'); + it('should change to pt', () => { + expectLanguageChange('pt'); }); - it('should change to zh-CN', () => { - expectLanguageChange('zh-CN'); + it('should change to zh-Hans', () => { + expectLanguageChange('zh-Hans'); }); - it('should change to zh-TW', () => { - expectLanguageChange('zh-TW'); + it('should change to zh-Hant', () => { + expectLanguageChange('zh-Hant'); }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/language-selector/supported-languages.enum.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/language-selector/supported-languages.enum.ts index 1ba8a6eb667a..251ae4b072a0 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/language-selector/supported-languages.enum.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/language-selector/supported-languages.enum.ts @@ -16,18 +16,18 @@ import { // language-selector.component.spec.ts export enum SupportedLanguages { 'cs' = 'Čeština', - 'de-DE' = 'Deutsch', - 'en-US' = 'English', - 'es-ES' = 'Español', - 'fr-FR' = 'Français', - 'id-ID' = 'Bahasa Indonesia', - 'it-IT' = 'Italiano', - 'ja-JP' = '日本語', - 'ko-KR' = '한국어', - 'pl-PL' = 'Polski', - 'pt-BR' = 'Português (brasileiro)', - 'zh-CN' = '中文 (简体)', - 'zh-TW' = '中文 (繁體)' + 'de' = 'Deutsch', + 'en' = 'English', + 'es' = 'Español', + 'fr' = 'Français', + 'id' = 'Bahasa Indonesia', + 'it' = 'Italiano', + 'ja' = '日本語', + 'ko' = '한국어', + 'pl' = 'Polski', + 'pt' = 'Português (brasileiro)', + 'zh-Hans' = '中文 (简体)', + 'zh-Hant' = '中文 (繁體)' } // Supported languages: diff --git a/src/pybind/mgr/dashboard/frontend/src/polyfills.ts b/src/pybind/mgr/dashboard/frontend/src/polyfills.ts index 39a942e0444e..3368646d33aa 100644 --- a/src/pybind/mgr/dashboard/frontend/src/polyfills.ts +++ b/src/pybind/mgr/dashboard/frontend/src/polyfills.ts @@ -1,3 +1,7 @@ +/*************************************************************************************************** + * Load `$localize` onto the global scope - used if i18n tags appear in Angular templates. + */ +import '@angular/localize/init'; /** * This file includes polyfills needed by Angular and is loaded before the app. * You can add your own extra polyfills to this file. diff --git a/src/pybind/mgr/dashboard/tests/test_home.py b/src/pybind/mgr/dashboard/tests/test_home.py index 2ec1b2ad7641..b44e6d090594 100644 --- a/src/pybind/mgr/dashboard/tests/test_home.py +++ b/src/pybind/mgr/dashboard/tests/test_home.py @@ -24,7 +24,7 @@ class HomeTest(ControllerTestCase, FakeFsMixin): cls.fs.create_dir(frontend_path) cls.fs.create_file( os.path.join(frontend_path, '..', 'package.json'), - contents='{"config":{"locale": "en-US"}}') + contents='{"config":{"locale": "en"}}') with mock.patch(cls.builtins_open, new=cls.f_open),\ mock.patch('os.listdir', new=cls.f_os.listdir): lang = LanguageMixin() @@ -52,7 +52,7 @@ class HomeTest(ControllerTestCase, FakeFsMixin): @mock.patch(FakeFsMixin.builtins_open, new=FakeFsMixin.f_open) @mock.patch('os.stat', new=FakeFsMixin.f_os.stat) @mock.patch('os.listdir', new=FakeFsMixin.f_os.listdir) - def test_home_en_us(self): + def test_home_en(self): self._get('/', headers=[('Accept-Language', 'en-US')]) self.assertStatus(200) logger.info(self.body)