From 504e6202ab69901c2bb16610398edbe48b9ab541 Mon Sep 17 00:00:00 2001 From: Daniel James Smith Date: Thu, 2 Feb 2023 00:14:24 +0100 Subject: [PATCH] Extract loading locales (#4622) This reduces the noise in the app.modules where the angular locales are loaded. Simplifies extending with new locales as all of them can be found in the same place under the same file-name This has previously also been done in the web client --- apps/browser/src/popup/app.module.ts | 114 ++------------------------ apps/browser/src/popup/locales.ts | 108 +++++++++++++++++++++++++ apps/desktop/src/app/app.module.ts | 115 +-------------------------- apps/desktop/src/app/locales.ts | 112 ++++++++++++++++++++++++++ 4 files changed, 229 insertions(+), 220 deletions(-) create mode 100644 apps/browser/src/popup/locales.ts create mode 100644 apps/desktop/src/app/locales.ts diff --git a/apps/browser/src/popup/app.module.ts b/apps/browser/src/popup/app.module.ts index 5697541715..3d04f79787 100644 --- a/apps/browser/src/popup/app.module.ts +++ b/apps/browser/src/popup/app.module.ts @@ -3,60 +3,12 @@ import { DragDropModule } from "@angular/cdk/drag-drop"; import { LayoutModule } from "@angular/cdk/layout"; import { OverlayModule } from "@angular/cdk/overlay"; import { ScrollingModule } from "@angular/cdk/scrolling"; -import { CurrencyPipe, DatePipe, registerLocaleData } from "@angular/common"; -import localeAr from "@angular/common/locales/ar"; -import localeAz from "@angular/common/locales/az"; -import localeBe from "@angular/common/locales/be"; -import localeBg from "@angular/common/locales/bg"; -import localeBn from "@angular/common/locales/bn"; -import localeBs from "@angular/common/locales/bs"; -import localeCa from "@angular/common/locales/ca"; -import localeCs from "@angular/common/locales/cs"; -import localeDa from "@angular/common/locales/da"; -import localeDe from "@angular/common/locales/de"; -import localeEl from "@angular/common/locales/el"; -import localeEnGb from "@angular/common/locales/en-GB"; -import localeEnIn from "@angular/common/locales/en-IN"; -import localeEs from "@angular/common/locales/es"; -import localeEt from "@angular/common/locales/et"; -import localeEu from "@angular/common/locales/eu"; -import localeFa from "@angular/common/locales/fa"; -import localeFi from "@angular/common/locales/fi"; -import localeFil from "@angular/common/locales/fil"; -import localeFr from "@angular/common/locales/fr"; -import localeHe from "@angular/common/locales/he"; -import localeHi from "@angular/common/locales/hi"; -import localeHr from "@angular/common/locales/hr"; -import localeHu from "@angular/common/locales/hu"; -import localeId from "@angular/common/locales/id"; -import localeIt from "@angular/common/locales/it"; -import localeJa from "@angular/common/locales/ja"; -import localeKa from "@angular/common/locales/ka"; -import localeKm from "@angular/common/locales/km"; -import localeKn from "@angular/common/locales/kn"; -import localeKo from "@angular/common/locales/ko"; -import localeLt from "@angular/common/locales/lt"; -import localeLv from "@angular/common/locales/lv"; -import localeMl from "@angular/common/locales/ml"; -import localeNb from "@angular/common/locales/nb"; -import localeNl from "@angular/common/locales/nl"; -import localeNn from "@angular/common/locales/nn"; -import localePl from "@angular/common/locales/pl"; -import localePtBr from "@angular/common/locales/pt"; -import localePtPt from "@angular/common/locales/pt-PT"; -import localeRo from "@angular/common/locales/ro"; -import localeRu from "@angular/common/locales/ru"; -import localeSi from "@angular/common/locales/si"; -import localeSk from "@angular/common/locales/sk"; -import localeSl from "@angular/common/locales/sl"; -import localeSr from "@angular/common/locales/sr"; -import localeSv from "@angular/common/locales/sv"; -import localeTh from "@angular/common/locales/th"; -import localeTr from "@angular/common/locales/tr"; -import localeUk from "@angular/common/locales/uk"; -import localeVi from "@angular/common/locales/vi"; -import localeZhCn from "@angular/common/locales/zh-Hans"; -import localeZhTw from "@angular/common/locales/zh-Hant"; +// eslint-disable-next-line import/order +import { CurrencyPipe, DatePipe } from "@angular/common"; + +// Register the locales for the application +import "./locales"; + import { NgModule } from "@angular/core"; import { FormsModule, ReactiveFormsModule } from "@angular/forms"; import { BrowserModule } from "@angular/platform-browser"; @@ -121,60 +73,6 @@ import { SyncComponent } from "./settings/sync.component"; import { VaultTimeoutInputComponent } from "./settings/vault-timeout-input.component"; import { TabsComponent } from "./tabs.component"; -registerLocaleData(localeAr, "ar"); -registerLocaleData(localeAz, "az"); -registerLocaleData(localeBe, "be"); -registerLocaleData(localeBg, "bg"); -registerLocaleData(localeBn, "bn"); -registerLocaleData(localeBs, "bs"); -registerLocaleData(localeCa, "ca"); -registerLocaleData(localeCs, "cs"); -registerLocaleData(localeDa, "da"); -registerLocaleData(localeDe, "de"); -registerLocaleData(localeEl, "el"); -registerLocaleData(localeEnGb, "en-GB"); -registerLocaleData(localeEnIn, "en-IN"); -registerLocaleData(localeEs, "es"); -registerLocaleData(localeEt, "et"); -registerLocaleData(localeEu, "eu"); -registerLocaleData(localeFa, "fa"); -registerLocaleData(localeFi, "fi"); -registerLocaleData(localeFil, "fil"); -registerLocaleData(localeFr, "fr"); -registerLocaleData(localeHe, "he"); -registerLocaleData(localeHi, "hi"); -registerLocaleData(localeHr, "hr"); -registerLocaleData(localeHu, "hu"); -registerLocaleData(localeId, "id"); -registerLocaleData(localeIt, "it"); -registerLocaleData(localeJa, "ja"); -registerLocaleData(localeKa, "ka"); -registerLocaleData(localeKm, "km"); -registerLocaleData(localeKn, "kn"); -registerLocaleData(localeKo, "ko"); -registerLocaleData(localeLt, "lt"); -registerLocaleData(localeLv, "lv"); -registerLocaleData(localeMl, "ml"); -registerLocaleData(localeNb, "nb"); -registerLocaleData(localeNl, "nl"); -registerLocaleData(localeNn, "nn"); -registerLocaleData(localePl, "pl"); -registerLocaleData(localePtBr, "pt-BR"); -registerLocaleData(localePtPt, "pt-PT"); -registerLocaleData(localeRo, "ro"); -registerLocaleData(localeRu, "ru"); -registerLocaleData(localeSi, "si"); -registerLocaleData(localeSk, "sk"); -registerLocaleData(localeSl, "sl"); -registerLocaleData(localeSr, "sr"); -registerLocaleData(localeSv, "sv"); -registerLocaleData(localeTh, "th"); -registerLocaleData(localeTr, "tr"); -registerLocaleData(localeUk, "uk"); -registerLocaleData(localeVi, "vi"); -registerLocaleData(localeZhCn, "zh-CN"); -registerLocaleData(localeZhTw, "zh-TW"); - @NgModule({ imports: [ A11yModule, diff --git a/apps/browser/src/popup/locales.ts b/apps/browser/src/popup/locales.ts new file mode 100644 index 0000000000..f24f7368db --- /dev/null +++ b/apps/browser/src/popup/locales.ts @@ -0,0 +1,108 @@ +import { registerLocaleData } from "@angular/common"; +import localeAr from "@angular/common/locales/ar"; +import localeAz from "@angular/common/locales/az"; +import localeBe from "@angular/common/locales/be"; +import localeBg from "@angular/common/locales/bg"; +import localeBn from "@angular/common/locales/bn"; +import localeBs from "@angular/common/locales/bs"; +import localeCa from "@angular/common/locales/ca"; +import localeCs from "@angular/common/locales/cs"; +import localeDa from "@angular/common/locales/da"; +import localeDe from "@angular/common/locales/de"; +import localeEl from "@angular/common/locales/el"; +import localeEnGb from "@angular/common/locales/en-GB"; +import localeEnIn from "@angular/common/locales/en-IN"; +import localeEs from "@angular/common/locales/es"; +import localeEt from "@angular/common/locales/et"; +import localeEu from "@angular/common/locales/eu"; +import localeFa from "@angular/common/locales/fa"; +import localeFi from "@angular/common/locales/fi"; +import localeFil from "@angular/common/locales/fil"; +import localeFr from "@angular/common/locales/fr"; +import localeHe from "@angular/common/locales/he"; +import localeHi from "@angular/common/locales/hi"; +import localeHr from "@angular/common/locales/hr"; +import localeHu from "@angular/common/locales/hu"; +import localeId from "@angular/common/locales/id"; +import localeIt from "@angular/common/locales/it"; +import localeJa from "@angular/common/locales/ja"; +import localeKa from "@angular/common/locales/ka"; +import localeKm from "@angular/common/locales/km"; +import localeKn from "@angular/common/locales/kn"; +import localeKo from "@angular/common/locales/ko"; +import localeLt from "@angular/common/locales/lt"; +import localeLv from "@angular/common/locales/lv"; +import localeMl from "@angular/common/locales/ml"; +import localeNb from "@angular/common/locales/nb"; +import localeNl from "@angular/common/locales/nl"; +import localeNn from "@angular/common/locales/nn"; +import localePl from "@angular/common/locales/pl"; +import localePtBr from "@angular/common/locales/pt"; +import localePtPt from "@angular/common/locales/pt-PT"; +import localeRo from "@angular/common/locales/ro"; +import localeRu from "@angular/common/locales/ru"; +import localeSi from "@angular/common/locales/si"; +import localeSk from "@angular/common/locales/sk"; +import localeSl from "@angular/common/locales/sl"; +import localeSr from "@angular/common/locales/sr"; +import localeSv from "@angular/common/locales/sv"; +import localeTh from "@angular/common/locales/th"; +import localeTr from "@angular/common/locales/tr"; +import localeUk from "@angular/common/locales/uk"; +import localeVi from "@angular/common/locales/vi"; +import localeZhCn from "@angular/common/locales/zh-Hans"; +import localeZhTw from "@angular/common/locales/zh-Hant"; + +registerLocaleData(localeAr, "ar"); +registerLocaleData(localeAz, "az"); +registerLocaleData(localeBe, "be"); +registerLocaleData(localeBg, "bg"); +registerLocaleData(localeBn, "bn"); +registerLocaleData(localeBs, "bs"); +registerLocaleData(localeCa, "ca"); +registerLocaleData(localeCs, "cs"); +registerLocaleData(localeDa, "da"); +registerLocaleData(localeDe, "de"); +registerLocaleData(localeEl, "el"); +registerLocaleData(localeEnGb, "en-GB"); +registerLocaleData(localeEnIn, "en-IN"); +registerLocaleData(localeEs, "es"); +registerLocaleData(localeEt, "et"); +registerLocaleData(localeEu, "eu"); +registerLocaleData(localeFa, "fa"); +registerLocaleData(localeFi, "fi"); +registerLocaleData(localeFil, "fil"); +registerLocaleData(localeFr, "fr"); +registerLocaleData(localeHe, "he"); +registerLocaleData(localeHi, "hi"); +registerLocaleData(localeHr, "hr"); +registerLocaleData(localeHu, "hu"); +registerLocaleData(localeId, "id"); +registerLocaleData(localeIt, "it"); +registerLocaleData(localeJa, "ja"); +registerLocaleData(localeKa, "ka"); +registerLocaleData(localeKm, "km"); +registerLocaleData(localeKn, "kn"); +registerLocaleData(localeKo, "ko"); +registerLocaleData(localeLt, "lt"); +registerLocaleData(localeLv, "lv"); +registerLocaleData(localeMl, "ml"); +registerLocaleData(localeNb, "nb"); +registerLocaleData(localeNl, "nl"); +registerLocaleData(localeNn, "nn"); +registerLocaleData(localePl, "pl"); +registerLocaleData(localePtBr, "pt-BR"); +registerLocaleData(localePtPt, "pt-PT"); +registerLocaleData(localeRo, "ro"); +registerLocaleData(localeRu, "ru"); +registerLocaleData(localeSi, "si"); +registerLocaleData(localeSk, "sk"); +registerLocaleData(localeSl, "sl"); +registerLocaleData(localeSr, "sr"); +registerLocaleData(localeSv, "sv"); +registerLocaleData(localeTh, "th"); +registerLocaleData(localeTr, "tr"); +registerLocaleData(localeUk, "uk"); +registerLocaleData(localeVi, "vi"); +registerLocaleData(localeZhCn, "zh-CN"); +registerLocaleData(localeZhTw, "zh-TW"); diff --git a/apps/desktop/src/app/app.module.ts b/apps/desktop/src/app/app.module.ts index b07db465ed..52d68fa428 100644 --- a/apps/desktop/src/app/app.module.ts +++ b/apps/desktop/src/app/app.module.ts @@ -1,61 +1,8 @@ import "zone.js/dist/zone"; -import { registerLocaleData } from "@angular/common"; -import localeAf from "@angular/common/locales/af"; -import localeAr from "@angular/common/locales/ar"; -import localeAz from "@angular/common/locales/az"; -import localeBe from "@angular/common/locales/be"; -import localeBg from "@angular/common/locales/bg"; -import localeBn from "@angular/common/locales/bn"; -import localeBs from "@angular/common/locales/bs"; -import localeCa from "@angular/common/locales/ca"; -import localeCs from "@angular/common/locales/cs"; -import localeDa from "@angular/common/locales/da"; -import localeDe from "@angular/common/locales/de"; -import localeEl from "@angular/common/locales/el"; -import localeEnGb from "@angular/common/locales/en-GB"; -import localeEnIn from "@angular/common/locales/en-IN"; -import localeEo from "@angular/common/locales/eo"; -import localeEs from "@angular/common/locales/es"; -import localeEt from "@angular/common/locales/et"; -import localeEu from "@angular/common/locales/eu"; -import localeFa from "@angular/common/locales/fa"; -import localeFi from "@angular/common/locales/fi"; -import localeFil from "@angular/common/locales/fil"; -import localeFr from "@angular/common/locales/fr"; -import localeHe from "@angular/common/locales/he"; -import localeHi from "@angular/common/locales/hi"; -import localeHr from "@angular/common/locales/hr"; -import localeHu from "@angular/common/locales/hu"; -import localeId from "@angular/common/locales/id"; -import localeIt from "@angular/common/locales/it"; -import localeJa from "@angular/common/locales/ja"; -import localeKa from "@angular/common/locales/ka"; -import localeKm from "@angular/common/locales/km"; -import localeKn from "@angular/common/locales/kn"; -import localeKo from "@angular/common/locales/ko"; -import localeLv from "@angular/common/locales/lv"; -import localeMl from "@angular/common/locales/ml"; -import localeNb from "@angular/common/locales/nb"; -import localeNl from "@angular/common/locales/nl"; -import localeNn from "@angular/common/locales/nn"; -import localePl from "@angular/common/locales/pl"; -import localePtBr from "@angular/common/locales/pt"; -import localePtPt from "@angular/common/locales/pt-PT"; -import localeRo from "@angular/common/locales/ro"; -import localeRu from "@angular/common/locales/ru"; -import localeSi from "@angular/common/locales/si"; -import localeSk from "@angular/common/locales/sk"; -import localeSl from "@angular/common/locales/sl"; -import localeSr from "@angular/common/locales/sr"; -import localeMe from "@angular/common/locales/sr-Latn-ME"; -import localeSv from "@angular/common/locales/sv"; -import localeTh from "@angular/common/locales/th"; -import localeTr from "@angular/common/locales/tr"; -import localeUk from "@angular/common/locales/uk"; -import localeVi from "@angular/common/locales/vi"; -import localeZhCn from "@angular/common/locales/zh-Hans"; -import localeZhTw from "@angular/common/locales/zh-Hant"; +// Register the locales for the application +import "./locales"; + import { NgModule } from "@angular/core"; import { ColorPasswordCountPipe } from "@bitwarden/angular/pipes/color-password-count.pipe"; @@ -107,62 +54,6 @@ import { EffluxDatesComponent as SendEffluxDatesComponent } from "./send/efflux- import { SendComponent } from "./send/send.component"; import { SharedModule } from "./shared/shared.module"; -registerLocaleData(localeAf, "af"); -registerLocaleData(localeAr, "ar"); -registerLocaleData(localeAz, "az"); -registerLocaleData(localeBe, "be"); -registerLocaleData(localeBg, "bg"); -registerLocaleData(localeBn, "bn"); -registerLocaleData(localeBs, "bs"); -registerLocaleData(localeCa, "ca"); -registerLocaleData(localeCs, "cs"); -registerLocaleData(localeDa, "da"); -registerLocaleData(localeDe, "de"); -registerLocaleData(localeEl, "el"); -registerLocaleData(localeEnGb, "en-GB"); -registerLocaleData(localeEnIn, "en-IN"); -registerLocaleData(localeEo, "eo"); -registerLocaleData(localeEs, "es"); -registerLocaleData(localeEt, "et"); -registerLocaleData(localeEu, "eu"); -registerLocaleData(localeFa, "fa"); -registerLocaleData(localeFi, "fi"); -registerLocaleData(localeFil, "fil"); -registerLocaleData(localeFr, "fr"); -registerLocaleData(localeHe, "he"); -registerLocaleData(localeHi, "hi"); -registerLocaleData(localeHr, "hr"); -registerLocaleData(localeHu, "hu"); -registerLocaleData(localeId, "id"); -registerLocaleData(localeIt, "it"); -registerLocaleData(localeJa, "ja"); -registerLocaleData(localeKa, "ka"); -registerLocaleData(localeKm, "km"); -registerLocaleData(localeKn, "kn"); -registerLocaleData(localeKo, "ko"); -registerLocaleData(localeLv, "lv"); -registerLocaleData(localeMe, "me"); -registerLocaleData(localeMl, "ml"); -registerLocaleData(localeNb, "nb"); -registerLocaleData(localeNl, "nl"); -registerLocaleData(localeNn, "nn"); -registerLocaleData(localePl, "pl"); -registerLocaleData(localePtBr, "pt-BR"); -registerLocaleData(localePtPt, "pt-PT"); -registerLocaleData(localeRo, "ro"); -registerLocaleData(localeRu, "ru"); -registerLocaleData(localeSi, "si"); -registerLocaleData(localeSk, "sk"); -registerLocaleData(localeSl, "sl"); -registerLocaleData(localeSr, "sr"); -registerLocaleData(localeSv, "sv"); -registerLocaleData(localeTh, "th"); -registerLocaleData(localeTr, "tr"); -registerLocaleData(localeUk, "uk"); -registerLocaleData(localeVi, "vi"); -registerLocaleData(localeZhCn, "zh-CN"); -registerLocaleData(localeZhTw, "zh-TW"); - @NgModule({ imports: [SharedModule, AppRoutingModule, VaultFilterModule], declarations: [ diff --git a/apps/desktop/src/app/locales.ts b/apps/desktop/src/app/locales.ts new file mode 100644 index 0000000000..c8ecfad0b0 --- /dev/null +++ b/apps/desktop/src/app/locales.ts @@ -0,0 +1,112 @@ +import { registerLocaleData } from "@angular/common"; +import localeAf from "@angular/common/locales/af"; +import localeAr from "@angular/common/locales/ar"; +import localeAz from "@angular/common/locales/az"; +import localeBe from "@angular/common/locales/be"; +import localeBg from "@angular/common/locales/bg"; +import localeBn from "@angular/common/locales/bn"; +import localeBs from "@angular/common/locales/bs"; +import localeCa from "@angular/common/locales/ca"; +import localeCs from "@angular/common/locales/cs"; +import localeDa from "@angular/common/locales/da"; +import localeDe from "@angular/common/locales/de"; +import localeEl from "@angular/common/locales/el"; +import localeEnGb from "@angular/common/locales/en-GB"; +import localeEnIn from "@angular/common/locales/en-IN"; +import localeEo from "@angular/common/locales/eo"; +import localeEs from "@angular/common/locales/es"; +import localeEt from "@angular/common/locales/et"; +import localeEu from "@angular/common/locales/eu"; +import localeFa from "@angular/common/locales/fa"; +import localeFi from "@angular/common/locales/fi"; +import localeFil from "@angular/common/locales/fil"; +import localeFr from "@angular/common/locales/fr"; +import localeHe from "@angular/common/locales/he"; +import localeHi from "@angular/common/locales/hi"; +import localeHr from "@angular/common/locales/hr"; +import localeHu from "@angular/common/locales/hu"; +import localeId from "@angular/common/locales/id"; +import localeIt from "@angular/common/locales/it"; +import localeJa from "@angular/common/locales/ja"; +import localeKa from "@angular/common/locales/ka"; +import localeKm from "@angular/common/locales/km"; +import localeKn from "@angular/common/locales/kn"; +import localeKo from "@angular/common/locales/ko"; +import localeLv from "@angular/common/locales/lv"; +import localeMl from "@angular/common/locales/ml"; +import localeNb from "@angular/common/locales/nb"; +import localeNl from "@angular/common/locales/nl"; +import localeNn from "@angular/common/locales/nn"; +import localePl from "@angular/common/locales/pl"; +import localePtBr from "@angular/common/locales/pt"; +import localePtPt from "@angular/common/locales/pt-PT"; +import localeRo from "@angular/common/locales/ro"; +import localeRu from "@angular/common/locales/ru"; +import localeSi from "@angular/common/locales/si"; +import localeSk from "@angular/common/locales/sk"; +import localeSl from "@angular/common/locales/sl"; +import localeSr from "@angular/common/locales/sr"; +import localeMe from "@angular/common/locales/sr-Latn-ME"; +import localeSv from "@angular/common/locales/sv"; +import localeTh from "@angular/common/locales/th"; +import localeTr from "@angular/common/locales/tr"; +import localeUk from "@angular/common/locales/uk"; +import localeVi from "@angular/common/locales/vi"; +import localeZhCn from "@angular/common/locales/zh-Hans"; +import localeZhTw from "@angular/common/locales/zh-Hant"; + +registerLocaleData(localeAf, "af"); +registerLocaleData(localeAr, "ar"); +registerLocaleData(localeAz, "az"); +registerLocaleData(localeBe, "be"); +registerLocaleData(localeBg, "bg"); +registerLocaleData(localeBn, "bn"); +registerLocaleData(localeBs, "bs"); +registerLocaleData(localeCa, "ca"); +registerLocaleData(localeCs, "cs"); +registerLocaleData(localeDa, "da"); +registerLocaleData(localeDe, "de"); +registerLocaleData(localeEl, "el"); +registerLocaleData(localeEnGb, "en-GB"); +registerLocaleData(localeEnIn, "en-IN"); +registerLocaleData(localeEo, "eo"); +registerLocaleData(localeEs, "es"); +registerLocaleData(localeEt, "et"); +registerLocaleData(localeEu, "eu"); +registerLocaleData(localeFa, "fa"); +registerLocaleData(localeFi, "fi"); +registerLocaleData(localeFil, "fil"); +registerLocaleData(localeFr, "fr"); +registerLocaleData(localeHe, "he"); +registerLocaleData(localeHi, "hi"); +registerLocaleData(localeHr, "hr"); +registerLocaleData(localeHu, "hu"); +registerLocaleData(localeId, "id"); +registerLocaleData(localeIt, "it"); +registerLocaleData(localeJa, "ja"); +registerLocaleData(localeKa, "ka"); +registerLocaleData(localeKm, "km"); +registerLocaleData(localeKn, "kn"); +registerLocaleData(localeKo, "ko"); +registerLocaleData(localeLv, "lv"); +registerLocaleData(localeMe, "me"); +registerLocaleData(localeMl, "ml"); +registerLocaleData(localeNb, "nb"); +registerLocaleData(localeNl, "nl"); +registerLocaleData(localeNn, "nn"); +registerLocaleData(localePl, "pl"); +registerLocaleData(localePtBr, "pt-BR"); +registerLocaleData(localePtPt, "pt-PT"); +registerLocaleData(localeRo, "ro"); +registerLocaleData(localeRu, "ru"); +registerLocaleData(localeSi, "si"); +registerLocaleData(localeSk, "sk"); +registerLocaleData(localeSl, "sl"); +registerLocaleData(localeSr, "sr"); +registerLocaleData(localeSv, "sv"); +registerLocaleData(localeTh, "th"); +registerLocaleData(localeTr, "tr"); +registerLocaleData(localeUk, "uk"); +registerLocaleData(localeVi, "vi"); +registerLocaleData(localeZhCn, "zh-CN"); +registerLocaleData(localeZhTw, "zh-TW");