@@ -14,6 +14,7 @@ import { setImmediate } from './setImmediate';
1414import { isDevMode } from '@angular/core' ;
1515import type { IgxTheme } from '../services/theme/theme.token' ;
1616import { getDateFormatter , getI18nManager , getNumberFormatter , IResourceChangeEventArgs } from 'igniteui-i18n-core' ;
17+ import { isIgxAngularLocalizationEnabled } from './i18n/resources' ;
1718
1819/** @hidden @internal */
1920export const ELEMENTS_TOKEN = /*@__PURE__ */ new InjectionToken < boolean > ( 'elements environment' ) ;
@@ -631,6 +632,8 @@ export function onResourceChangeHandle(destroyObj: Subject<any> | DestroyRef, ca
631632 }
632633}
633634
635+ //#region Localization
636+ const angularDisabledError = new Error ( 'Angular localization disabled!' ) ;
634637const IntlDateTimeStyleValues = {
635638 full : 'Full' ,
636639 long : 'Long' ,
@@ -652,7 +655,11 @@ export function getLocaleDateFormat(locale: string, displayFormat?: string): str
652655 }
653656 let format : string ;
654657 try {
655- format = ngGetLocaleDateFormat ( locale , FormatWidth [ IntlDateTimeStyleValues [ targetKey ] ] ) ;
658+ if ( isIgxAngularLocalizationEnabled ( ) ) {
659+ format = ngGetLocaleDateFormat ( locale , FormatWidth [ IntlDateTimeStyleValues [ targetKey ] ] ) ;
660+ } else {
661+ throw angularDisabledError ;
662+ }
656663 } catch {
657664 // No longer throw warnings. Back up is to use Intl now, which should return the format without registering locales.
658665 format = getDateFormatter ( ) . getLocaleDateTimeFormat ( locale , false , { dateStyle : targetKey } ) ;
@@ -675,7 +682,11 @@ export function getLocaleDateTimeFormat(locale: string, displayFormat?: string)
675682 }
676683 let format : string ;
677684 try {
678- format = ngGetLocaleDateTimeFormat ( locale , FormatWidth [ IntlDateTimeStyleValues [ targetKey ] ] ) ;
685+ if ( isIgxAngularLocalizationEnabled ( ) ) {
686+ format = ngGetLocaleDateTimeFormat ( locale , FormatWidth [ IntlDateTimeStyleValues [ targetKey ] ] ) ;
687+ } else {
688+ throw angularDisabledError ;
689+ }
679690 } catch {
680691 // No longer throw warnings. Back up is to use Intl now, which should return the format without registering locales.
681692 format = getDateFormatter ( ) . getLocaleDateTimeFormat ( locale , false , { dateStyle : targetKey , timeStyle : targetKey } ) ;
@@ -691,7 +702,11 @@ export function getLocaleDateTimeFormat(locale: string, displayFormat?: string)
691702export function formatDate ( value : Date | string | number | null | undefined , format : string , locale : string , timezone ?: string ) : string {
692703 let formattedDate : string ;
693704 try {
694- formattedDate = ngFormatDate ( value , format , locale , timezone ) ;
705+ if ( isIgxAngularLocalizationEnabled ( ) ) {
706+ formattedDate = ngFormatDate ( value , format , locale , timezone ) ;
707+ } else {
708+ throw angularDisabledError ;
709+ }
695710 } catch {
696711 if ( value === null || value === undefined || value === '' ) {
697712 return '' ;
@@ -784,7 +799,11 @@ export function getCurrencyCode(locale: string, overrideCode?: string) {
784799 return overrideCode ;
785800 } else {
786801 try {
787- currencyCode = getLocaleCurrencyCode ( locale )
802+ if ( isIgxAngularLocalizationEnabled ( ) ) {
803+ currencyCode = getLocaleCurrencyCode ( locale ) ;
804+ } else {
805+ throw angularDisabledError ;
806+ }
788807 } catch {
789808 // If not available the user needs to define it.
790809 }
@@ -798,11 +817,16 @@ export function getCurrencySymbol(currencyCode: string, locale?: string, currenc
798817
799818export function getLocaleFirstDayOfWeek ( locale ?: string ) {
800819 try {
801- // Angular returns 0 for Sunday...
802- return ngGetLocaleFirstDayOfWeek ( locale ) ;
820+ if ( isIgxAngularLocalizationEnabled ( ) ) {
821+ // Angular returns 0 for Sunday...
822+ return ngGetLocaleFirstDayOfWeek ( locale ) ;
823+ } else {
824+ throw angularDisabledError ;
825+ }
803826 } catch { }
804827 return getDateFormatter ( ) . getFirstDayOfWeek ( locale ) ;
805828}
829+ //#endregion
806830
807831/** Converts pixel values to their rem counterparts for a base value */
808832export const rem = ( value : number | string ) => {
0 commit comments