-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: API for checking supported locales and plural forms
Add functions `getSupportedLocales` and `getPluralFormsForLocale`.
- Loading branch information
Showing
13 changed files
with
157 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
import { | ||
getPluralRulesForCardinals, getPluralFormForCardinal, | ||
setPluralFormsForCardinals, populatePluralData | ||
setPluralFormsForCardinals, populatePluralData, | ||
getSupportedLocales, getPluralFormsForLocale | ||
} from './code.js' | ||
import pluralData from './data.js' | ||
|
||
populatePluralData(pluralData) | ||
|
||
export { getPluralRulesForCardinals, getPluralFormForCardinal, setPluralFormsForCardinals } | ||
export { | ||
getPluralRulesForCardinals, getPluralFormForCardinal, | ||
setPluralFormsForCardinals, | ||
getSupportedLocales, getPluralFormsForLocale | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* global it, expect */ | ||
|
||
import { getPluralFormsForLocale } from '../src/index.js' | ||
|
||
it('is exported as a function', () => { | ||
expect(typeof getPluralFormsForLocale === 'function').toBeTruthy() | ||
}) | ||
|
||
it('returns plural form names for a supported locale', () => { | ||
expect(getPluralFormsForLocale('cs')).toEqual(['one', 'few', 'many', 'other']) | ||
}) | ||
|
||
it('returns an undefined for an unsupported locale', () => { | ||
expect(getPluralFormsForLocale('dummy')).toEqual(undefined) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* global it, expect */ | ||
|
||
import { getSupportedLocales } from '../src/index.js' | ||
|
||
it('is exported as a function', () => { | ||
expect(typeof getSupportedLocales === 'function').toBeTruthy() | ||
}) | ||
|
||
it('returns some supported locales', () => { | ||
expect(getSupportedLocales().includes('cs')).toBeTruthy() | ||
}) | ||
|
||
it('returns some supported locales when called once more', () => { | ||
expect(getSupportedLocales().includes('cs')).toBeTruthy() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { | ||
getPluralRulesForCardinals, getPluralFormForCardinal, | ||
setPluralFormsForCardinals, populatePluralData, | ||
getSupportedLocales, getPluralFormsForLocale, | ||
PluralRules | ||
} from '../src/code' | ||
|
||
declare type testCallback = () => void | ||
declare function test (label: string, callback: testCallback) | ||
|
||
test('Type declarations for TypeScript', () => { | ||
populatePluralData({ | ||
rules: [ | ||
'i = 1 and v = 0 @integer 1', | ||
'@integer 0, 2~16, 100, … @decimal 0.0~1.5, 10.0, 100.0, …' | ||
], | ||
cardinals: { | ||
test: { | ||
one: 0, | ||
other: 1 | ||
} | ||
} | ||
}) | ||
let _pluralForm: string | ||
_pluralForm = getPluralFormForCardinal('test', 1) | ||
const rules: PluralRules = getPluralRulesForCardinals('test') | ||
_pluralForm = getPluralFormForCardinal(rules, 1) | ||
setPluralFormsForCardinals('test', { | ||
one: 'i = 1 and v = 0 @integer 1', | ||
'pluralRule-count-other': ' @integer 0, 2~16, 100, … @decimal 0.0~1.5, 10.0, 100.0, …' | ||
}) | ||
const _locales: string[] = getSupportedLocales() | ||
const _pluralForms: string[] | undefined = getPluralFormsForLocale('cs') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,22 @@ | ||
import { | ||
getPluralRulesForCardinals, getPluralFormForCardinal, | ||
setPluralFormsForCardinals, populatePluralData | ||
} from '../src/code' | ||
setPluralFormsForCardinals, | ||
getSupportedLocales, getPluralFormsForLocale, | ||
PluralRules | ||
} from 'plural-rules' | ||
|
||
declare type testCallback = () => void | ||
declare function test (label: string, callback: testCallback) | ||
|
||
test('Type declarations for TypeScript', () => { | ||
populatePluralData({ | ||
rules: [ | ||
'i = 1 and v = 0 @integer 1', | ||
'@integer 0, 2~16, 100, … @decimal 0.0~1.5, 10.0, 100.0, …' | ||
], | ||
cardinals: { | ||
test: { | ||
one: 0, | ||
other: 1 | ||
} | ||
} | ||
}) | ||
getPluralFormForCardinal('test', 1) | ||
const rules = getPluralRulesForCardinals('test') | ||
getPluralFormForCardinal(rules, 1) | ||
let _pluralForm: string | ||
_pluralForm = getPluralFormForCardinal('test', 1) | ||
const rules: PluralRules = getPluralRulesForCardinals('test') | ||
_pluralForm = getPluralFormForCardinal(rules, 1) | ||
setPluralFormsForCardinals('test', { | ||
one: 'i = 1 and v = 0 @integer 1', | ||
'pluralRule-count-other': ' @integer 0, 2~16, 100, … @decimal 0.0~1.5, 10.0, 100.0, …' | ||
}) | ||
const _locales: string[] = getSupportedLocales() | ||
const _pluralForms: string[] | undefined = getPluralFormsForLocale('cs') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters