Skip to content

Commit 622737c

Browse files
cexbrayatAndrewKushnir
authored andcommitted
feat(common): expose getLocaleCurrencyCode publicly (#34946)
It was previously defined in core without being exposed publicly, whereas `getLocaleCurrencyName` and `getLocaleCurrencySymbol` were defined in common, and publicly exposed. This commit now privately exposes `ɵgetLocaleCurrencyCode` from core, and reexports it publicly from common. PR Close #34946
1 parent 62e1186 commit 622737c

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

packages/common/src/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export {formatDate} from './i18n/format_date';
1717
export {formatCurrency, formatNumber, formatPercent} from './i18n/format_number';
1818
export {NgLocaleLocalization, NgLocalization} from './i18n/localization';
1919
export {registerLocaleData} from './i18n/locale_data';
20-
export {Plural, NumberFormatStyle, FormStyle, Time, TranslationWidth, FormatWidth, NumberSymbol, WeekDay, getNumberOfCurrencyDigits, getCurrencySymbol, getLocaleDayPeriods, getLocaleDayNames, getLocaleMonthNames, getLocaleId, getLocaleEraNames, getLocaleWeekEndRange, getLocaleFirstDayOfWeek, getLocaleDateFormat, getLocaleDateTimeFormat, getLocaleExtraDayPeriodRules, getLocaleExtraDayPeriods, getLocalePluralCase, getLocaleTimeFormat, getLocaleNumberSymbol, getLocaleNumberFormat, getLocaleCurrencyName, getLocaleCurrencySymbol} from './i18n/locale_data_api';
20+
export {Plural, NumberFormatStyle, FormStyle, Time, TranslationWidth, FormatWidth, NumberSymbol, WeekDay, getNumberOfCurrencyDigits, getCurrencySymbol, getLocaleDayPeriods, getLocaleDayNames, getLocaleMonthNames, getLocaleId, getLocaleEraNames, getLocaleWeekEndRange, getLocaleFirstDayOfWeek, getLocaleDateFormat, getLocaleDateTimeFormat, getLocaleExtraDayPeriodRules, getLocaleExtraDayPeriods, getLocalePluralCase, getLocaleTimeFormat, getLocaleNumberSymbol, getLocaleNumberFormat, getLocaleCurrencyCode, getLocaleCurrencyName, getLocaleCurrencySymbol} from './i18n/locale_data_api';
2121
export {parseCookieValue as ɵparseCookieValue} from './cookie';
2222
export {CommonModule} from './common_module';
2323
export {NgClass, NgClassBase, NgForOf, NgForOfContext, NgIf, NgIfContext, NgPlural, NgPluralCase, NgStyle, NgStyleBase, NgSwitch, NgSwitchCase, NgSwitchDefault, NgTemplateOutlet, NgComponentOutlet} from './directives/index';

packages/common/src/i18n/locale_data_api.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {ɵCurrencyIndex, ɵExtraLocaleDataIndex, ɵLocaleDataIndex, ɵfindLocaleData, ɵgetLocalePluralCase} from '@angular/core';
9+
import {ɵCurrencyIndex, ɵExtraLocaleDataIndex, ɵLocaleDataIndex, ɵfindLocaleData, ɵgetLocaleCurrencyCode, ɵgetLocalePluralCase} from '@angular/core';
10+
1011
import {CURRENCIES_EN, CurrenciesSymbols} from './currencies';
1112

13+
1214
/**
1315
* Format styles that can be used to represent numbers.
1416
* @see `getLocaleNumberFormat()`.
@@ -473,6 +475,20 @@ export function getLocaleCurrencyName(locale: string): string|null {
473475
return data[ɵLocaleDataIndex.CurrencyName] || null;
474476
}
475477

478+
/**
479+
* Retrieves the default currency code for the given locale.
480+
*
481+
* The default is defined as the first currency which is still in use.
482+
*
483+
* @param locale The code of the locale whose currency code we want.
484+
* @returns The code of the default currency for the given locale.
485+
*
486+
* @publicApi
487+
*/
488+
export function getLocaleCurrencyCode(locale: string): string|null {
489+
return ɵgetLocaleCurrencyCode(locale);
490+
}
491+
476492
/**
477493
* Retrieves the currency values for a given locale.
478494
* @param locale A locale code for the locale format rules to use.

packages/core/src/core_private_export.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ export {makeDecorator as ɵmakeDecorator} from './util/decorators';
3333
export {isObservable as ɵisObservable, isPromise as ɵisPromise} from './util/lang';
3434
export {clearOverrides as ɵclearOverrides, initServicesIfNeeded as ɵinitServicesIfNeeded, overrideComponentView as ɵoverrideComponentView, overrideProvider as ɵoverrideProvider} from './view/index';
3535
export {NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR as ɵNOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR} from './view/provider';
36-
export {LocaleDataIndex as ɵLocaleDataIndex, CurrencyIndex as ɵCurrencyIndex, ExtraLocaleDataIndex as ɵExtraLocaleDataIndex, getLocalePluralCase as ɵgetLocalePluralCase, findLocaleData as ɵfindLocaleData, registerLocaleData as ɵregisterLocaleData, unregisterAllLocaleData as ɵunregisterLocaleData} from './i18n/locale_data_api';
36+
export {LocaleDataIndex as ɵLocaleDataIndex, CurrencyIndex as ɵCurrencyIndex, ExtraLocaleDataIndex as ɵExtraLocaleDataIndex, getLocaleCurrencyCode as ɵgetLocaleCurrencyCode, getLocalePluralCase as ɵgetLocalePluralCase, findLocaleData as ɵfindLocaleData, registerLocaleData as ɵregisterLocaleData, unregisterAllLocaleData as ɵunregisterLocaleData} from './i18n/locale_data_api';
3737
export {allowSanitizationBypassAndThrow as ɵallowSanitizationBypassAndThrow, getSanitizationBypassType as ɵgetSanitizationBypassType, BypassType as ɵBypassType, unwrapSafeValue as ɵunwrapSafeValue, SafeHtml as ɵSafeHtml, SafeResourceUrl as ɵSafeResourceUrl, SafeScript as ɵSafeScript, SafeStyle as ɵSafeStyle, SafeUrl as ɵSafeUrl, SafeValue as ɵSafeValue} from './sanitization/bypass';

packages/core/src/i18n/locale_data_api.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export function findLocaleData(locale: string): any {
7171
* @param locale The code of the locale whose currency code we want.
7272
* @returns The code of the default currency for the given locale.
7373
*
74-
* @publicApi
7574
*/
7675
export function getLocaleCurrencyCode(locale: string): string|null {
7776
const data = findLocaleData(locale);

tools/public_api_guard/common/common.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export declare enum FormStyle {
5151

5252
export declare function getCurrencySymbol(code: string, format: 'wide' | 'narrow', locale?: string): string;
5353

54+
export declare function getLocaleCurrencyCode(locale: string): string | null;
55+
5456
export declare function getLocaleCurrencyName(locale: string): string | null;
5557

5658
export declare function getLocaleCurrencySymbol(locale: string): string | null;

0 commit comments

Comments
 (0)