Skip to content

Commit

Permalink
feat(common): Add and enable the Intl implementation for the i18n sub…
Browse files Browse the repository at this point in the history
…-system.

Angular's i18n subsystem is responsible for providing localised formatting of numbers, percents, percentages and dates.
This feature replaces the default implementation of the i18N subsystem.

The new implementation relies on the platform-provided [`Intl` API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl).

With the formatting now relying on a platform API, it is not necessary anymore the load locale files (See #20487) .

* For numbers, percents and currencies, the `Intl` implementation replaces the exisiting one.
* For dates, the feature is being introduced as an **opt-out** : `useLegacyDateFormatting()`, new application will rely on the Intl implementation by default.
  *  Existing applications will be migrated to opt-out of this change and rely on the previously existing implementation.

BREAKING CHANGE: Formatting output might be altered for dates.
* Expect changes for formats `cccccc`, `EEEEEE`, `aaaaa`, `b` to `bbbbb` and `B` to `BBBBB`. Extensive details are available in the changes of `format_date_spec.ts`.
* The `DatePipe` will not support offset `timezone` anymore, use IANA timezones instead .
  • Loading branch information
JeanMeche committed Apr 12, 2024
1 parent 9b6cedd commit 767753e
Show file tree
Hide file tree
Showing 20 changed files with 952 additions and 871 deletions.
7 changes: 5 additions & 2 deletions goldens/public-api/common/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class DecimalPipe implements PipeTransform {
export const DOCUMENT: InjectionToken<Document>;

// @public
export function formatCurrency(value: number, locale: string, currency: string, currencyCode?: string, digitsInfo?: string): string;
export function formatCurrency(value: number, locale: string, display: 'code' | 'symbol' | 'symbol-narrow' | string, currencyCode?: string, digitsInfo?: string): string;

// @public
export function formatDate(value: string | number | Date, format: string, locale: string, timezone?: string): string;
Expand Down Expand Up @@ -895,7 +895,7 @@ export const provideImgixLoader: (path: string) => Provider[];
// @public
export function provideNetlifyLoader(path?: string): Provider[];

// @public
// @public @deprecated
export function registerLocaleData(data: any, localeId?: string | any, extraData?: any): void;

// @public
Expand Down Expand Up @@ -958,6 +958,9 @@ export class UpperCasePipe implements PipeTransform {
static ɵpipe: i0.ɵɵPipeDeclaration<UpperCasePipe, "uppercase", true>;
}

// @public (undocumented)
export function useLegacyDateFormatting(): void;

// @public (undocumented)
export const VERSION: Version;

Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ export * from './location/index';
export {formatDate} from './i18n/format_date';
export {formatCurrency, formatNumber, formatPercent} from './i18n/format_number';
export {NgLocaleLocalization, NgLocalization} from './i18n/localization';
export {useLegacyDateFormatting} from './i18n/format_date';
export {registerLocaleData} from './i18n/locale_data';
export {
Plural,
NumberFormatStyle,
FormStyle,
Time,
TranslationWidth,
FormatWidth,
NumberSymbol,
WeekDay,
Expand All @@ -48,6 +47,7 @@ export {
getLocaleCurrencySymbol,
getLocaleDirection,
} from './i18n/locale_data_api';
export {FormStyle, TranslationWidth} from './i18n/format_date_interface';
export {parseCookieValue as ɵparseCookieValue} from './cookie';
export {CommonModule} from './common_module';
export {
Expand Down

0 comments on commit 767753e

Please sign in to comment.