]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/locale.helper.ts
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / locale.helper.ts
1 import locale_cs from '@angular/common/locales/cs';
2 import locale_de from '@angular/common/locales/de';
3 import locale_en from '@angular/common/locales/en';
4 import locale_es from '@angular/common/locales/es';
5 import locale_fr from '@angular/common/locales/fr';
6 import locale_id from '@angular/common/locales/id';
7 import locale_pl from '@angular/common/locales/pl';
8 import locale_pt_PT from '@angular/common/locales/pt-PT';
9 import locale_zh_Hans from '@angular/common/locales/zh-Hans';
10 import { LOCALE_ID, TRANSLATIONS, TRANSLATIONS_FORMAT } from '@angular/core';
11
12 declare const require;
13
14 export class LocaleHelper {
15 static getBrowserLang(): string {
16 const lang = navigator.language;
17
18 if (lang.includes('cs')) {
19 return 'cs';
20 } else if (lang.includes('de')) {
21 return 'de-DE';
22 } else if (lang.includes('en')) {
23 return 'en-US';
24 } else if (lang.includes('es')) {
25 return 'es-ES';
26 } else if (lang.includes('fr')) {
27 return 'fr-FR';
28 } else if (lang.includes('id')) {
29 return 'id-ID';
30 } else if (lang.includes('pl')) {
31 return 'pl-PL';
32 } else if (lang.includes('pt')) {
33 return 'pt-PT';
34 } else if (lang.includes('zh')) {
35 return 'zh-CN';
36 } else {
37 return undefined;
38 }
39 }
40
41 static getLocale(): string {
42 return window.localStorage.getItem('lang') || this.getBrowserLang() || 'en-US';
43 }
44
45 static setLocale(lang: string) {
46 window.localStorage.setItem('lang', lang);
47 }
48
49 static getLocaleData() {
50 let localeData = locale_en;
51 switch (this.getLocale()) {
52 case 'cs':
53 localeData = locale_cs;
54 break;
55 case 'de-DE':
56 localeData = locale_de;
57 break;
58 case 'es-ES':
59 localeData = locale_es;
60 break;
61 case 'fr-FR':
62 localeData = locale_fr;
63 break;
64 case 'id-ID':
65 localeData = locale_id;
66 break;
67 case 'pt-PT':
68 localeData = locale_pt_PT;
69 break;
70 case 'pl-PL':
71 localeData = locale_pl;
72 break;
73 case 'zh-CN':
74 localeData = locale_zh_Hans;
75 break;
76 }
77 return localeData;
78 }
79 }
80
81 const i18nProviders = [
82 { provide: LOCALE_ID, useValue: LocaleHelper.getLocale() },
83 {
84 provide: TRANSLATIONS,
85 useFactory: (locale) => {
86 locale = locale || 'en-US';
87 try {
88 return require(`raw-loader!locale/messages.${locale}.xlf`);
89 } catch (error) {
90 return [];
91 }
92 },
93 deps: [LOCALE_ID]
94 },
95 { provide: TRANSLATIONS_FORMAT, useValue: 'xlf' }
96 ];
97
98 export { i18nProviders };