Skip to content

Commit

Permalink
Merge pull request #20256 from abpframework/auto-merge/prerel-8-3/2815
Browse files Browse the repository at this point in the history
Merge branch dev with prerel-8.3
  • Loading branch information
maliming authored Jul 19, 2024
2 parents ac9e938 + 0563943 commit d165e16
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions npm/ng-packs/packages/core/locale/src/utils/register-locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,72 @@ export interface RegisterLocaleData {
errorHandlerFn?: (data: LocaleErrorHandlerData) => any;
}


function loadLocale(locale: string) {
// hard coded list works with esbuild. Source https://github.com/angular/angular-cli/issues/26904#issuecomment-1903596563

const list = {
'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'),
'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(
{
cultureNameLocaleFileMap = {},
errorHandlerFn = defaultLocalErrorHandlerFn,
} = {} as RegisterLocaleData,
) {
return (locale: string): Promise<any> => {
localeMap = { ...differentLocales, ...cultureNameLocaleFileMap };
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(locale) == -1) {
return;
}
return new Promise((resolve, reject) => {
return loadLocale(l)
.then(val => {
let module = val;
while (module.default) {
module = module.default;
}
resolve({ default: module });
})
.catch(error => {
errorHandlerFn({
resolve,
reject,
error,
locale,
});
});
});
};
}



export function registerLocale(
{
cultureNameLocaleFileMap = {},
Expand Down

0 comments on commit d165e16

Please sign in to comment.