Skip to content

Commit

Permalink
feat(common): expose getLocaleCurrencyCode publicly (#34946)
Browse files Browse the repository at this point in the history
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
cexbrayat authored and AndrewKushnir committed Jan 24, 2020
1 parent 62e1186 commit 622737c
Showing 5 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/common/src/common.ts
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ export {formatDate} from './i18n/format_date';
export {formatCurrency, formatNumber, formatPercent} from './i18n/format_number';
export {NgLocaleLocalization, NgLocalization} from './i18n/localization';
export {registerLocaleData} from './i18n/locale_data';
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';
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';
export {parseCookieValue as ɵparseCookieValue} from './cookie';
export {CommonModule} from './common_module';
export {NgClass, NgClassBase, NgForOf, NgForOfContext, NgIf, NgIfContext, NgPlural, NgPluralCase, NgStyle, NgStyleBase, NgSwitch, NgSwitchCase, NgSwitchDefault, NgTemplateOutlet, NgComponentOutlet} from './directives/index';
18 changes: 17 additions & 1 deletion packages/common/src/i18n/locale_data_api.ts
Original file line number Diff line number Diff line change
@@ -6,9 +6,11 @@
* found in the LICENSE file at https://angular.io/license
*/

import {ɵCurrencyIndex, ɵExtraLocaleDataIndex, ɵLocaleDataIndex, ɵfindLocaleData, ɵgetLocalePluralCase} from '@angular/core';
import {ɵCurrencyIndex, ɵExtraLocaleDataIndex, ɵLocaleDataIndex, ɵfindLocaleData, ɵgetLocaleCurrencyCode, ɵgetLocalePluralCase} from '@angular/core';

import {CURRENCIES_EN, CurrenciesSymbols} from './currencies';


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

/**
* Retrieves the default currency code for the given locale.
*
* The default is defined as the first currency which is still in use.
*
* @param locale The code of the locale whose currency code we want.
* @returns The code of the default currency for the given locale.
*
* @publicApi
*/
export function getLocaleCurrencyCode(locale: string): string|null {
return ɵgetLocaleCurrencyCode(locale);
}

/**
* Retrieves the currency values for a given locale.
* @param locale A locale code for the locale format rules to use.
2 changes: 1 addition & 1 deletion packages/core/src/core_private_export.ts
Original file line number Diff line number Diff line change
@@ -33,5 +33,5 @@ export {makeDecorator as ɵmakeDecorator} from './util/decorators';
export {isObservable as ɵisObservable, isPromise as ɵisPromise} from './util/lang';
export {clearOverrides as ɵclearOverrides, initServicesIfNeeded as ɵinitServicesIfNeeded, overrideComponentView as ɵoverrideComponentView, overrideProvider as ɵoverrideProvider} from './view/index';
export {NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR as ɵNOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR} from './view/provider';
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';
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';
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';
1 change: 0 additions & 1 deletion packages/core/src/i18n/locale_data_api.ts
Original file line number Diff line number Diff line change
@@ -71,7 +71,6 @@ export function findLocaleData(locale: string): any {
* @param locale The code of the locale whose currency code we want.
* @returns The code of the default currency for the given locale.
*
* @publicApi
*/
export function getLocaleCurrencyCode(locale: string): string|null {
const data = findLocaleData(locale);
2 changes: 2 additions & 0 deletions tools/public_api_guard/common/common.d.ts
Original file line number Diff line number Diff line change
@@ -51,6 +51,8 @@ export declare enum FormStyle {

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

export declare function getLocaleCurrencyCode(locale: string): string | null;

export declare function getLocaleCurrencyName(locale: string): string | null;

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

0 comments on commit 622737c

Please sign in to comment.