|
|
@ -11,6 +11,35 @@ export interface LocaleErrorHandlerData { |
|
|
|
|
|
|
|
|
let localeMap = {} as { [key: string]: string }; |
|
|
let localeMap = {} as { [key: string]: string }; |
|
|
|
|
|
|
|
|
|
|
|
const localeLoaders: Record<string, () => Promise<any>> = { |
|
|
|
|
|
ar: () => import('@angular/common/locales/ar'), |
|
|
|
|
|
cs: () => import('@angular/common/locales/cs'), |
|
|
|
|
|
en: () => import('@angular/common/locales/en'), |
|
|
|
|
|
'en-GB': () => import('@angular/common/locales/en-GB'), |
|
|
|
|
|
es: () => import('@angular/common/locales/es'), |
|
|
|
|
|
de: () => import('@angular/common/locales/de'), |
|
|
|
|
|
fi: () => import('@angular/common/locales/fi'), |
|
|
|
|
|
fr: () => import('@angular/common/locales/fr'), |
|
|
|
|
|
hi: () => import('@angular/common/locales/hi'), |
|
|
|
|
|
hu: () => import('@angular/common/locales/hu'), |
|
|
|
|
|
is: () => import('@angular/common/locales/is'), |
|
|
|
|
|
it: () => import('@angular/common/locales/it'), |
|
|
|
|
|
ja: () => import('@angular/common/locales/ja'), |
|
|
|
|
|
ko: () => import('@angular/common/locales/ko'), |
|
|
|
|
|
pt: () => import('@angular/common/locales/pt'), |
|
|
|
|
|
ro: () => import('@angular/common/locales/ro'), |
|
|
|
|
|
ru: () => import('@angular/common/locales/ru'), |
|
|
|
|
|
sk: () => import('@angular/common/locales/sk'), |
|
|
|
|
|
sl: () => import('@angular/common/locales/sl'), |
|
|
|
|
|
th: () => import('@angular/common/locales/th'), |
|
|
|
|
|
tr: () => import('@angular/common/locales/tr'), |
|
|
|
|
|
vi: () => import('@angular/common/locales/vi'), |
|
|
|
|
|
'zh-Hans': () => import('@angular/common/locales/zh-Hans'), |
|
|
|
|
|
'zh-Hant': () => import('@angular/common/locales/zh-Hant'), |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const localeSupportList = Object.keys(localeLoaders); |
|
|
|
|
|
|
|
|
export interface RegisterLocaleData { |
|
|
export interface RegisterLocaleData { |
|
|
cultureNameLocaleFileMap?: Record<string, string>; |
|
|
cultureNameLocaleFileMap?: Record<string, string>; |
|
|
errorHandlerFn?: (data: LocaleErrorHandlerData) => any; |
|
|
errorHandlerFn?: (data: LocaleErrorHandlerData) => any; |
|
|
@ -19,29 +48,11 @@ export interface RegisterLocaleData { |
|
|
function loadLocale(locale: string) { |
|
|
function loadLocale(locale: string) { |
|
|
// hard coded list works with esbuild. Source https://github.com/angular/angular-cli/issues/26904#issuecomment-1903596563
|
|
|
// hard coded list works with esbuild. Source https://github.com/angular/angular-cli/issues/26904#issuecomment-1903596563
|
|
|
|
|
|
|
|
|
const list = { |
|
|
if (localeSupportList.indexOf(locale) === -1) { |
|
|
ar: () => import('@angular/common/locales/ar'), |
|
|
return Promise.reject(new Error(`Cannot find the ${locale} locale file.`)); |
|
|
cs: () => import('@angular/common/locales/cs'), |
|
|
} |
|
|
en: () => import('@angular/common/locales/en'), |
|
|
|
|
|
'en-GB': () => import('@angular/common/locales/en-GB'), |
|
|
return localeLoaders[locale](); |
|
|
es: () => import('@angular/common/locales/es'), |
|
|
|
|
|
de: () => import('@angular/common/locales/de'), |
|
|
|
|
|
fi: () => import('@angular/common/locales/fi'), |
|
|
|
|
|
fr: () => import('@angular/common/locales/fr'), |
|
|
|
|
|
hi: () => import('@angular/common/locales/hi'), |
|
|
|
|
|
hu: () => import('@angular/common/locales/hu'), |
|
|
|
|
|
is: () => import('@angular/common/locales/is'), |
|
|
|
|
|
it: () => import('@angular/common/locales/it'), |
|
|
|
|
|
pt: () => import('@angular/common/locales/pt'), |
|
|
|
|
|
tr: () => import('@angular/common/locales/tr'), |
|
|
|
|
|
ru: () => import('@angular/common/locales/ru'), |
|
|
|
|
|
ro: () => import('@angular/common/locales/ro'), |
|
|
|
|
|
sk: () => import('@angular/common/locales/sk'), |
|
|
|
|
|
sl: () => import('@angular/common/locales/sl'), |
|
|
|
|
|
'zh-Hans': () => import('@angular/common/locales/zh-Hans'), |
|
|
|
|
|
'zh-Hant': () => import('@angular/common/locales/zh-Hant'), |
|
|
|
|
|
}; |
|
|
|
|
|
return list[locale](); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export function registerLocaleForEsBuild( |
|
|
export function registerLocaleForEsBuild( |
|
|
@ -53,12 +64,6 @@ export function registerLocaleForEsBuild( |
|
|
return (locale: string): Promise<any> => { |
|
|
return (locale: string): Promise<any> => { |
|
|
localeMap = { ...differentLocales, ...cultureNameLocaleFileMap }; |
|
|
localeMap = { ...differentLocales, ...cultureNameLocaleFileMap }; |
|
|
const l = localeMap[locale] || locale; |
|
|
const l = localeMap[locale] || locale; |
|
|
const localeSupportList = |
|
|
|
|
|
'ar|cs|en|en-GB|es|de|fi|fr|hi|hu|is|it|pt|tr|ru|ro|sk|sl|zh-Hans|zh-Hant'.split('|'); |
|
|
|
|
|
|
|
|
|
|
|
if (localeSupportList.indexOf(l) == -1) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
return new Promise((resolve, reject) => { |
|
|
return loadLocale(l) |
|
|
return loadLocale(l) |
|
|
.then(val => { |
|
|
.then(val => { |
|
|
@ -93,7 +98,7 @@ export function registerLocale( |
|
|
return import( |
|
|
return import( |
|
|
/* webpackMode: "lazy-once" */ |
|
|
/* webpackMode: "lazy-once" */ |
|
|
/* webpackChunkName: "locales"*/ |
|
|
/* webpackChunkName: "locales"*/ |
|
|
/* webpackInclude: /[/\\](ar|cs|en|en-GB|es|de|fi|fr|hi|hu|is|it|pt|tr|ru|ro|sk|sl|zh-Hans|zh-Hant)\.(mjs|js)$/ */ |
|
|
/* webpackInclude: /[/\\](ar|cs|en|en-GB|es|de|fi|fr|hi|hu|is|it|ja|ko|pt|ro|ru|sk|sl|th|tr|vi|zh-Hans|zh-Hant)\.(mjs|js)$/ */ |
|
|
/* webpackExclude: /[/\\]global|extra/ */ |
|
|
/* webpackExclude: /[/\\]global|extra/ */ |
|
|
/* @vite-ignore */ |
|
|
/* @vite-ignore */ |
|
|
`@angular/common${localePath}` |
|
|
`@angular/common${localePath}` |
|
|
|