feat: add direction property to locale files (#33556)

PR Close #33556
This commit is contained in:
Feliks Khantsis
2019-11-22 15:07:30 +02:00
committed by Miško Hevery
parent 86d5472d91
commit 3c2438425b
8 changed files with 54 additions and 10 deletions

View File

@ -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, getLocaleCurrencyName, getLocaleCurrencySymbol, getLocaleDirection} 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';

View File

@ -561,6 +561,18 @@ export function getLocaleExtraDayPeriods(
return getLastDefinedValue(dayPeriods, width) || [];
}
/**
* Retrieves the writing direction of a specified locale
* @param locale A locale code for the locale format rules to use.
* @publicApi
* @returns 'rtl' or 'ltr'
* @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
*/
export function getLocaleDirection(locale: string): 'ltr'|'rtl' {
const data = ɵfindLocaleData(locale);
return data[ɵLocaleDataIndex.Directionality];
}
/**
* Retrieves the first value that is defined in an array, going backwards from an index position.
*

View File

@ -12,7 +12,8 @@ import localeEn from '@angular/common/locales/en';
import localeFr from '@angular/common/locales/fr';
import localeZh from '@angular/common/locales/zh';
import localeEnAU from '@angular/common/locales/en-AU';
import {getCurrencySymbol, getLocaleDateFormat, FormatWidth, getNumberOfCurrencyDigits} from '../../src/i18n/locale_data_api';
import localeHe from '@angular/common/locales/he';
import {getCurrencySymbol, getLocaleDateFormat, FormatWidth, getNumberOfCurrencyDigits, getLocaleDirection} from '../../src/i18n/locale_data_api';
{
describe('locale data api', () => {
@ -21,6 +22,7 @@ import {getCurrencySymbol, getLocaleDateFormat, FormatWidth, getNumberOfCurrency
ɵregisterLocaleData(localeFr);
ɵregisterLocaleData(localeZh);
ɵregisterLocaleData(localeEnAU);
ɵregisterLocaleData(localeHe);
});
afterAll(() => { ɵunregisterLocaleData(); });
@ -56,5 +58,13 @@ import {getCurrencySymbol, getLocaleDateFormat, FormatWidth, getNumberOfCurrency
it('should find the last defined date format when format not defined',
() => { expect(getLocaleDateFormat('zh', FormatWidth.Long)).toEqual('y年M月d日'); });
});
describe('getDirectionality', () => {
it('should have correct direction for rtl languages',
() => { expect(getLocaleDirection('he')).toEqual('rtl'); });
it('should have correct direction for ltr languages',
() => { expect(getLocaleDirection('en')).toEqual('ltr'); });
});
});
}