diff --git a/build/rollup.config.js b/build/rollup.config.js
index f2e5446ab..58266961a 100644
--- a/build/rollup.config.js
+++ b/build/rollup.config.js
@@ -7,7 +7,7 @@ module.exports = (config) => {
input: {
input,
external: [
- 'dayjs', 'timezone-support'
+ 'dayjs', 'fast-plural-rules', 'timezone-support'
],
plugins: [
babel({
@@ -22,6 +22,7 @@ module.exports = (config) => {
name: name || 'dayjs',
globals: {
dayjs: 'dayjs',
+ 'fast-plural-rules': 'fastPluralRules',
'timezone-support': 'timezone-support'
},
sourcemap: true
diff --git a/docs/en/I18n.md b/docs/en/I18n.md
index c9eff224c..98a2f93e4 100644
--- a/docs/en/I18n.md
+++ b/docs/en/I18n.md
@@ -116,11 +116,10 @@ Old template of the part of a Day.js locale Object for the RelativeTime plugin.
}
```
-New template of the part of a Day.js locale Object for the RelativeTime plugin. It works well for fusional languages which decline nouns and which have two forms of plural. Slavic languages like Czech language, for example. The `duration` expressions will be used if the `withoutSuffix` parameter is set to `true` in the method calls.
+New template of the part of a Day.js locale Object for the RelativeTime plugin. It works well for fusional languages which decline nouns and which have multiple plural forms. Slavic languages like Czech language, for example. The `duration` expressions will be used if the `withoutSuffix` parameter is set to `true` in the method calls.
```javascript
relativeTime: { // relative time format strings, keep %d as the same
- // Plural rule for 3 plural forms in Slavic languages
- pluralRule: 8,
+ // Using 3 plural forms in Slavic languages
duration: {
// Static message, just one singular/plural form needed
s: 'několik sekund',
@@ -165,7 +164,7 @@ New template of the part of a Day.js locale Object for the RelativeTime plugin.
}
}
```
-The plural rule is an index of a function in the array in `src/plugins/relativeTime/pluralRules.js`, or an actual function. The function gets a number and return an index of the plural form to use. The keys with two-letter time units point to arrays with plural forms. The keys with single-letter time units point to a string shown for a single value, usually without any number.
+The keys with single-letter time units point to a string shown for a single value, usually without any number. The keys with two-letter time units point to arrays with plural forms. Before you work on a new localization, make yourself familiar with [plural rules and plural forms for the target language](https://github.com/prantlf/fast-plural-rules/blob/master/docs/languages.md#supported-languages). You will find more information about [plural rules](https://github.com/prantlf/fast-plural-rules/blob/master/docs/design.md#plural-rules) and [plural forms](https://github.com/prantlf/fast-plural-rules/blob/master/docs/design.md#plural-forms) in the [design](https://github.com/prantlf/fast-plural-rules/blob/master/docs/design.md#design-concepts) of the library [fast-plural-rules](https://github.com/prantlf/fast-plural-rules#fast-plural-rules) used for the grammatically correct localization of expressions with cardinal numbers.
Template of a Day.js locale file.
```javascript
diff --git a/docs/en/Plugin.md b/docs/en/Plugin.md
index 99bf6fee4..86316bdc7 100644
--- a/docs/en/Plugin.md
+++ b/docs/en/Plugin.md
@@ -135,6 +135,16 @@ Returns the `string` of relative time to X.
| 11 months to 17months | y | a year ago |
| 18 months+ | yy | 2 years ago ... 20 years ago |
+#### Installation
+
+This plugin has a dependency on the [`fast-plural-rules`](https://www.npmjs.com/package/fast-plural-rules) NPM module. If you are going to use it on a web page directly, add its script to your section of `
+
+
+```
+
### IsLeapYear
- IsLeapYear adds `.isLeapYear` API to returns a `boolean` indicating whether the `Dayjs`'s year is a leap year or not.
diff --git a/package-lock.json b/package-lock.json
index 15e7f48fa..65f3a4219 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -4105,7 +4105,7 @@
"dependencies": {
"finalhandler": {
"version": "1.1.1",
- "resolved": "http://registry.npmjs.org/finalhandler/-/finalhandler-1.1.1.tgz",
+ "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.1.tgz",
"integrity": "sha512-Y1GUDo39ez4aHAw7MysnUD5JzYX+WaIj8I57kO3aEPT1fFRL4sr7mjei97FgnwhAyyzRYmQZaTHb2+9uZ1dPtg==",
"dev": true,
"requires": {
@@ -4267,6 +4267,11 @@
"integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=",
"dev": true
},
+ "fast-plural-rules": {
+ "version": "0.0.1",
+ "resolved": "https://registry.npmjs.org/fast-plural-rules/-/fast-plural-rules-0.0.1.tgz",
+ "integrity": "sha512-0Cxx7LaH7+dNJEBozlisCxqaN5g68VTFT9PyLeFGBHmkPnQ3e46zss+r8pRC94KpzPlitL6m33GVdbMIDiUgqg=="
+ },
"fastparse": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/fastparse/-/fastparse-1.1.1.tgz",
@@ -11425,7 +11430,7 @@
},
"async": {
"version": "2.0.1",
- "resolved": "http://registry.npmjs.org/async/-/async-2.0.1.tgz",
+ "resolved": "https://registry.npmjs.org/async/-/async-2.0.1.tgz",
"integrity": "sha1-twnMAoCpw28J9FNr6CPIOKkEniU=",
"dev": true,
"requires": {
diff --git a/package.json b/package.json
index 823cd2962..1bbdbe81b 100644
--- a/package.json
+++ b/package.json
@@ -144,6 +144,7 @@
"url": "https://github.com/prantlf/dayjs/issues"
},
"dependencies": {
+ "fast-plural-rules": "^0.0.1",
"timezone-support": "^1.5.5"
},
"devDependencies": {
diff --git a/src/locale/cs.js b/src/locale/cs.js
index 0d3630c0d..0e02c5231 100644
--- a/src/locale/cs.js
+++ b/src/locale/cs.js
@@ -14,8 +14,7 @@ const locale = {
LLLL: 'dddd D. MMMM YYYY H:mm'
},
relativeTime: {
- // 3 plural forms for 1, 2-4, 5-
- pluralRule: 8,
+ // Using 3 plural forms for 1, 2-4, 5-
duration: {
s: 'několik sekund',
m: 'minuta',
diff --git a/src/locale/ru.js b/src/locale/ru.js
index c6ff4a7b0..e103f0e44 100644
--- a/src/locale/ru.js
+++ b/src/locale/ru.js
@@ -16,8 +16,7 @@ const locale = {
LLLL: 'dddd, D MMMM YYYY г., H:mm'
},
relativeTime: {
- // 3 plural forms for 1 and x1, 2-4 and x2-4, 5-
- pluralRule: 7,
+ // Using 3 plural forms for 1 and x1, 2-4 and x2-4, 5-
duration: {
s: 'несколько секунд',
m: 'минута',
diff --git a/src/locale/sk.js b/src/locale/sk.js
index 944b58b4a..71a0cd3a0 100644
--- a/src/locale/sk.js
+++ b/src/locale/sk.js
@@ -13,8 +13,7 @@ const locale = {
LLLL: 'dddd D. MMMM YYYY H:mm'
},
relativeTime: {
- // 3 plural forms for 1, 2-4, 5-
- pluralRule: 8,
+ // Using 3 plural forms for 1, 2-4, 5-
duration: {
s: 'niekoľko sekúnd',
m: 'minúta',
diff --git a/src/locale/ua.js b/src/locale/ua.js
index 5cd403d49..66196b0ef 100644
--- a/src/locale/ua.js
+++ b/src/locale/ua.js
@@ -13,8 +13,7 @@ const locale = {
LLLL: 'dddd, D MMMM YYYY р., H:mm'
},
relativeTime: {
- // 3 plural forms for 1 and x1, 2-4 and x2-4, 5-
- pluralRule: 7,
+ // Using 3 plural forms for 1 and x1, 2-4 and x2-4, 5-
duration: {
s: 'кілька секунд',
m: 'хвилина',
diff --git a/src/plugin/relativeTime/index.js b/src/plugin/relativeTime/index.js
index 7e6e80643..491931a35 100644
--- a/src/plugin/relativeTime/index.js
+++ b/src/plugin/relativeTime/index.js
@@ -1,13 +1,6 @@
-import * as C from '../../constant'
-import pluralRules from './pluralRules'
+import { getPluralFormForCardinalByLocale } from 'fast-plural-rules'
-// Special plural rules for upgraded locales, which are not complete
-// Returns 0 for plural for languages with a single plural
-const simplePluralRule = () => 0
-// Returns 0 for plural for 2 <= value <= 4 and 1 for plural
-// for value >= 5, which is sufficient for some languages like Czech
-/* istanbul ignore next line */
-const improvedPluralRule = n => n >= 2 && n <= 4 ? 0 : 1 // eslint-disable-line no-confusing-arrow
+import * as C from '../../constant'
export default (o, c, d) => {
const proto = c.prototype
@@ -42,7 +35,23 @@ export default (o, c, d) => {
// Save the special singular without any number with the single-letter key and the
// single plural to be used with any number greater then 1 with the two-letter key
const text = loc[key]
- result[key] = kl === 1 ? text : [text]
+ if (kl === 1) {
+ result[key] = text
+ // Insert singular for objects with plurals declared before singulars
+ const key2 = key + key
+ let plurals = result[key2]
+ if (!plurals) {
+ plurals = result[key2] = [] // eslint-disable-line no-multi-assign
+ }
+ plurals.unshift(text)
+ } else {
+ // Append plural for objects with plurals declared after singulars
+ let plurals = result[key]
+ if (!plurals) {
+ plurals = result[key] = [] // eslint-disable-line no-multi-assign
+ }
+ plurals.push(text)
+ }
}
// Remove the original locale entry; the original locale object needs
// to be retained to prevent upgrading on every formatting call
@@ -68,8 +77,6 @@ export default (o, c, d) => {
loc.duration = durations
loc.future = futures
loc.past = pasts
- // Recognize only one plural like in English
- loc.pluralRule = simplePluralRule
}
// Upgrade the improved, but not the final version of the localization,
// which supports two plurals by keys with two and three letters
@@ -102,14 +109,12 @@ export default (o, c, d) => {
loc.duration = convertPlurals(loc.duration)
loc.future = convertPlurals(loc.future)
loc.past = convertPlurals(loc.past)
- // Recognize two plurals like in the Czech language
- loc.pluralRule = improvedPluralRule
}
// Upgrades old locale format to provide compatibility with older
// localizations; the grammar may not be correct for fusional languages
// {
// duration: { s: '...', m: '...', mm: ['...', '...', ...] },
- // future: { ... }, past: { ... }, pluralRule: N
+ // future: { ... }, past: { ... }
// }
function upgradeLocale(loc) {
// Do not upgrade already upgraded locales
@@ -120,7 +125,8 @@ export default (o, c, d) => {
}
}
const fromTo = (input, withoutSuffix, instance, isFrom) => {
- const locs = instance.$locale().relativeTime
+ const locale = instance.$locale()
+ const locs = locale.relativeTime
const T = [
{ l: 's', r: 44, d: C.S },
{ l: 'm', r: 89 },
@@ -167,13 +173,9 @@ export default (o, c, d) => {
out = loc[key]
} else {
// Choose the plural form using the index decided by the plural rule
- let { pluralRule } = locs
- if (typeof pluralRule === 'number') {
- pluralRule = pluralRules[pluralRule]
- }
const pluralForms = loc[key]
- const pluralFormIndex = pluralRule(abs)
- out = pluralForms[pluralFormIndex].replace('%d', abs)
+ const pluralForm = getPluralFormForCardinalByLocale(locale.name, abs)
+ out = pluralForms[pluralForm].replace('%d', abs)
}
break
}
diff --git a/src/plugin/relativeTime/pluralRules.js b/src/plugin/relativeTime/pluralRules.js
deleted file mode 100644
index aae193b59..000000000
--- a/src/plugin/relativeTime/pluralRules.js
+++ /dev/null
@@ -1,206 +0,0 @@
-// See the plural rules at https://developer.mozilla.org/en-US/docs/Mozilla/Localization/Localization_and_Plurals#List_of_Plural_Rules
-// See the expressions to identify the plural form at http://docs.translatehouse.org/projects/localization-guide/en/latest/l10n/pluralforms.html#pluralforms-list
-
-/* eslint-disable no-confusing-arrow, no-nested-ternary */
-/* istanbul ignore file */
-
-export default [
- // Plural rule #0 (1 form)
- // Families: Asian (Chinese, Japanese, Korean), Persian, Turkic/Altaic (Turkish), Thai, Lao
- // everything: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
- // 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
- // 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, …
- () => 0,
- // Plural rule #1 (2 forms)
- // Families: Germanic (Danish, Dutch, English, Faroese, Frisian, German, Norwegian, Swedish),
- // Finno-Ugric (Estonian, Finnish, Hungarian),
- // Language isolate (Basque), Latin/Greek (Greek), Semitic (Hebrew),
- // Romanic (Italian, Portuguese, Spanish, Catalan), Vietnamese
- // is 1: 1
- // everything else: 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
- // 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
- // 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, …
- n => n === 1 ? 0 : 1,
- // Plural rule #2 (2 forms)
- // Families: Romanic (French, Brazilian Portuguese)
- // is 0 or 1: 0, 1
- // everything else: 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
- // 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
- // 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, …
- n => n <= 1 ? 0 : 1,
- // Plural rule #3 (3 forms)
- // Families: Baltic (Latvian, Latgalian)
- // ends in 1, excluding 11: 1, 21, 31, 41, 51, 61, 71, 81, 91, 101, 121, 131,
- // 141, 151, 161, 171, 181, 191, 201, 221, 231, 241, 251, 261, 271, 281, 291,
- // …
- // everything else: 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18,
- // 19, 22, 23, 24, 25, 26, 27, 28, 29, 32, 33, 34, 35, 36, 37, 38, 39, 42,
- // 43, 44, 45, 46, 47, 48, 49, 52, 53, …
- // ends in 0: 0
- n => n % 10 === 1 && n % 100 !== 11 ? 0 : n !== 0 ? 1 : 2,
- // Plural rule #4 (4 forms)
- // Families: Celtic (Scottish Gaelic)
- // is 1 or 11: 1, 11
- // is 2 or 12: 2, 12
- // is 3-10 or 13-19: 3, 4, 5, 6, 7, 8, 9, 10, 13, 14, 15, 16, 17, 18, 19
- // everything else: 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
- // 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
- // 51, …
- n => n === 1 || n === 11 ? 0 : n === 2 || n === 12 ? 1 : n > 2 && n < 20 ? 2 : 3,
- // Plural rule #5 (3 forms)
- // Families: Romanic (Romanian)
- // is 1: 1
- // is 0 or ends in 01-19, excluding 1: 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
- // 13, 14, 15, 16, 17, 18, 19, 101, 102, 103, 104, 105, 106, 107, 108, 109,
- // 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 201, 202, 203, 204, 205,
- // 206, 207, 208, 209, 210, 211, 212, …
- // everything else: 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
- // 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
- // 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, …
- n => n === 1 ? 0 : n === 0 || (n % 100 > 0 && n % 100 < 20) ? 1 : 2,
- // Plural rule #6 (3 forms)
- // Families: Baltic (Lithuanian)
- // ends in 1, excluding 11: 1, 21, 31, 41, 51, 61, 71, 81, 91, 101, 121, 131,
- // 141, 151, 161, 171, 181, 191, 201, 221, 231, 241, 251, 261, 271, 281, 291,
- // …
- // ends in 0 or ends in 11-19: 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
- // 30, 40, 50, 60, 70, 80, 90, 100, 110, 111, 112, 113, 114, 115, 116, 117,
- // 118, 119, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 211, 212, 213,
- // 214, 215, 216, 217, 218, 219, 220, …
- // everything else: 2, 3, 4, 5, 6, 7, 8, 9, 22, 23, 24, 25, 26, 27, 28, 29,
- // 32, 33, 34, 35, 36, 37, 38, 39, 42, 43, 44, 45, 46, 47, 48, 49, 52, 53,
- // 54, 55, 56, 57, 58, 59, 62, 63, 64, 65, 66, 67, 68, 69, 72, 73, …
- n => n % 10 === 1 && n % 100 !== 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2,
- // Plural rule #7 (3 forms)
- // Families: Slavic (Belarusian, Bosnian, Croatian, Serbian, Russian, Ukrainian)
- // ends in 1, excluding 11: 1, 21, 31, 41, 51, 61, 71, 81, 91, 101, 121, 131,
- // 141, 151, 161, 171, 181, 191, 201, 221, 231, 241, 251, 261, 271, 281, 291,
- // …
- // ends in 2-4, excluding 12-14: 2, 3, 4, 22, 23, 24, 32, 33, 34, 42, 43, 44,
- // 52, 53, 54, 62, 63, 64, 72, 73, 74, 82, 83, 84, 92, 93, 94, 102, 103, 104,
- // 122, 123, 124, 132, 133, 134, 142, 143, 144, 152, 153, 154, 162, 163, 164,
- // 172, 173, 174, 182, 183, …
- // everything else: 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
- // 20, 25, 26, 27, 28, 29, 30, 35, 36, 37, 38, 39, 40, 45, 46, 47, 48, 49,
- // 50, 55, 56, 57, 58, 59, 60, 65, 66, 67, 68, 69, 70, 75, 76, 77, …, 112,
- // 113, ..., 212, 213, ...
- n => n % 10 === 1 && n % 100 !== 11 ? 0
- : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2,
- // Plural rule #8 (3 forms)
- // Families: Slavic (Slovak, Czech)
- // is 1: 1
- // is 2-4: 2, 3, 4
- // everything else: 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
- // 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
- // 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, …
- n => n === 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2,
- // Plural rule #9 (3 forms)
- // Families: Slavic (Polish)
- // is 1: 1
- // ends in 2-4, excluding 12-14: 2, 3, 4, 22, 23, 24, 32, 33, 34, 42, 43, 44,
- // 52, 53, 54, 62, 63, 64, 72, 73, 74, 82, 83, 84, 92, 93, 94, 102, 103, 104,
- // 122, 123, 124, 132, 133, 134, 142, 143, 144, 152, 153, 154, 162, 163, 164,
- // 172, 173, 174, 182, 183, …
- // everything else: 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
- // 20, 21, 25, 26, 27, 28, 29, 30, 31, 35, 36, 37, 38, 39, 40, 41, 45, 46,
- // 47, 48, 49, 50, 51, 55, 56, 57, 58, 59, 60, 61, 65, 66, 67, 68, …
- n => n === 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2,
- // Plural rule #10 (4 forms)
- // Families: Slavic (Slovenian, Sorbian)
- // ends in 01: 1, 101, 201, …
- // ends in 02: 2, 102, 202, …
- // ends in 03-04: 3, 4, 103, 104, 203, 204, …
- // everything else: 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
- // 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
- // 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, …
- n => n % 100 === 1 ? 0 : n % 100 === 2 ? 1 : n % 100 === 3 || n % 100 === 4 ? 2 : 3,
- // Plural rule #11 (5 forms)
- // Families: Celtic (Irish Gaelic)
- // is 1: 1
- // is 2: 2
- // is 3-6: 3, 4, 5, 6
- // is 7-10: 7, 8, 9, 10
- // everything else: 0, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
- // 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
- // 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, …
- n => n === 1 ? 0 : n === 2 ? 1 : n > 2 && n < 7 ? 2 : n > 6 && n < 11 ? 3 : 4,
- // Plural rule #12 (6 forms)
- // Families: Semitic (Arabic)
- // is 1: 1
- // is 2: 2
- // ends in 03-10: 3, 4, 5, 6, 7, 8, 9, 10, 103, 104, 105, 106, 107, 108, 109,
- // 110, 203, 204, 205, 206, 207, 208, 209, 210, …
- // everything else but is 0 and ends in 00-02, excluding 0-2: 11, 12, 13, 14,
- // 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
- // 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
- // 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, …
- // ends in 00-02, excluding 0-2: 100, 101, 102, 200, 201, 202, …
- // is 0: 0
- n => n === 1 ? 0 : n === 2 ? 1 : n % 100 >= 3 && n % 100 <= 10 ? 2
- : n % 100 >= 11 ? 3 : n !== 0 ? 4 : 5,
- // Plural rule #13 (4 forms)
- // Families: Semitic (Maltese)
- // is 1: 1
- // is 0 or ends in 01-10, excluding 1: 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 101,
- // 102, 103, 104, 105, 106, 107, 108, 109, 110, 201, 202, 203, 204, 205, 206,
- // 207, 208, 209, 210, …
- // ends in 11-19: 11, 12, 13, 14, 15, 16, 17, 18, 19, 111, 112, 113, 114,
- // 115, 116, 117, 118, 119, 211, 212, 213, 214, 215, 216, 217, 218, 219, …
- // everything else: 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
- // 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
- // 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, …
- n => n === 1 ? 0 : n === 0 || (n % 100 > 1 && n % 100 < 11) ? 1
- : n % 100 > 10 && n % 100 < 20 ? 2 : 3,
- // Plural rule #14 (3 forms)
- // Families: unused
- // ends in 1: 1, 11, 21, 31, 41, 51, 61, 71, 81, 91, 101, 111, 121, 131, 141,
- // 151, 161, 171, 181, 191, 201, 211, 221, 231, 241, 251, 261, 271, 281, 291,
- // …
- // ends in 2: 2, 12, 22, 32, 42, 52, 62, 72, 82, 92, 102, 112, 122, 132, 142,
- // 152, 162, 172, 182, 192, 202, 212, 222, 232, 242, 252, 262, 272, 282, 292,
- // …
- // everything else: 0, 3, 4, 5, 6, 7, 8, 9, 10, 13, 14, 15, 16, 17, 18, 19,
- // 20, 23, 24, 25, 26, 27, 28, 29, 30, 33, 34, 35, 36, 37, 38, 39, 40, 43,
- // 44, 45, 46, 47, 48, 49, 50, 53, 54, 55, 56, 57, 58, 59, 60, 63, …
- n => n % 10 === 1 ? 0 : n % 10 === 2 ? 1 : 2,
- // Plural rule #15 (2 forms)
- // Families: Icelandic, Macedonian
- // ends in 1, excluding 11: 1, 21, 31, 41, 51, 61, 71, 81, 91, 101, 121, 131,
- // 141, 151, 161, 171, 181, 191, 201, 221, 231, 241, 251, 261, 271, 281, 291,
- // …
- // everything else: 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
- // 17, 18, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36,
- // 37, 38, 39, 40, 42, 43, 44, 45, 46, 47, 48, 49, 50, 52, 53, 54, …
- n => n % 10 === 1 && n % 100 !== 11 ? 0 : 1,
- // Plural rule #16 (5 forms)
- // Families: Celtic (Breton)
- // ends in 1, excluding 11, 71, 91: 21, 31, 41, 51, 61, 81, 101, 121, 131,
- // 141, 151, 161, 181, 201, 221, 231, 241, 251, 261, 281, ...
- // ends in 2, excluding 12, 72, 92: 2, 22, 32, 42, 52, 62, 82, 102, 122, 132,
- // 142, 152, 162, 182, 202, 222, 232, 242, 252, 262, 282, ...
- // ends in 3, 4 or 9 excluding 13, 14, 19, 73, 74, 79, 93, 94, 99: 3, 4, 9,
- // 23, 24, 29, 33, 34, 39, 43, 44, 49, 53, 54, 59, ...
- // ends in 1000000: 1000000: 1000000, 2000000, 3000000, 4000000, 5000000,
- // 6000000, 7000000, 8000000, 9000000, 10000000, ...
- // everything else: 0, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
- // 20, 25, 26, 27, 28, 30, 35, 36, 37, 38, 40, ...
- n => n <= 1 ? 0 : 1,
- // Plural rule #17 (2 forms)
- // Families: Ecuador indigenous languages (Shuar)
- // everything else: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
- // 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
- // 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, …
- // is 0: 0
- n => n !== 0 ? 0 : 1,
- // Plural rule #18 (6 forms)
- // Families: Welsh
- // is 1: 1
- // is 2: 2
- // is 3: 3
- // is 6: 6
- // everything else: 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
- // 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
- // 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, …
- // is 0: 0
- n => n === 1 ? 0 : n === 2 ? 1 : n === 3 ? 2 : n === 6 ? 3 : n !== 0 ? 4 : 5
-]
diff --git a/test/locale/keys.test.js b/test/locale/keys.test.js
index 3cb3b06d8..a2a034506 100644
--- a/test/locale/keys.test.js
+++ b/test/locale/keys.test.js
@@ -48,7 +48,7 @@ it('Locale keys', () => {
expect(Object.keys(relativeTime).every(key =>
// eslint-disable-next-line implicit-arrow-linebreak
typeof relativeTime[key] === 'string')).toBeTruthy()
- } else if (!relativeTime.pluralRule) {
+ } else if (relativeTime.duration.mmm) {
// Improved locale object structure
expect(Object.keys(relativeTime).sort()).toEqual(['duration', 'future', 'past'].sort());
['duration', 'future', 'past'].forEach(key =>
@@ -63,7 +63,7 @@ it('Locale keys', () => {
expect(typeof relativeTime[key][key2]).toEqual('string')))
} else {
// Ultimate locale object structure
- expect(Object.keys(relativeTime).sort()).toEqual(['duration', 'future', 'past', 'pluralRule'].sort());
+ expect(Object.keys(relativeTime).sort()).toEqual(['duration', 'future', 'past'].sort());
['duration', 'future', 'past'].forEach(key =>
// eslint-disable-next-line implicit-arrow-linebreak
expect(Object.keys(relativeTime[key]).sort())
@@ -77,8 +77,6 @@ it('Locale keys', () => {
expect(Array.isArray(relativeTime[key][key2])).toBeTruthy()
}
}))
- expect(typeof relativeTime.pluralRule === 'number'
- || typeof relativeTime.pluralRule === 'function').toBeTruthy()
}
}
})
diff --git a/test/plugin/relativeTime.test.js b/test/plugin/relativeTime.test.js
index 0258426fa..c414a078c 100644
--- a/test/plugin/relativeTime.test.js
+++ b/test/plugin/relativeTime.test.js
@@ -42,8 +42,9 @@ it('Upgrades old locale objects', () => {
expect(typeof locale.relativeTime.duration).toEqual('object')
expect(typeof locale.relativeTime.duration.m).toEqual('string')
expect(Array.isArray([locale.relativeTime.duration.mm])).toBeTruthy()
+ expect(locale.relativeTime.duration.mm.length).toEqual(2)
expect(typeof locale.relativeTime.duration.mm[0]).toEqual('string')
- expect(typeof locale.relativeTime.pluralRule).toEqual('function')
+ expect(typeof locale.relativeTime.duration.mm[1]).toEqual('string')
})
it('Upgrades improved locale objects', () => {
@@ -114,7 +115,6 @@ it('Upgrades improved locale objects', () => {
expect(typeof locale.relativeTime.duration.m).toEqual('string')
expect(Array.isArray([locale.relativeTime.duration.mm])).toBeTruthy()
expect(typeof locale.relativeTime.duration.mm[0]).toEqual('string')
- expect(typeof locale.relativeTime.pluralRule).toEqual('function')
})
it('Time from X', () => {