-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow grammatically correct localisation of the RelativeTime plugin to fusional languages #304
Conversation
It is not grammatically correct. The current localization support in Day.js is insufficient for fusional languages like Slavic ones.
* Redefine the locale object structure to separate expressions for duration, future and past. Allow the proper declension of the noun coming after the numeral. * Automatically convert the old locale object structure to the new one during the first call to a method of the RelativeTime plugin.
Allow using the correct grammar.
Codecov Report
@@ Coverage Diff @@
## master #304 +/- ##
======================================
Coverage 100% 100%
======================================
Files 32 44 +12
Lines 386 488 +102
Branches 53 65 +12
======================================
+ Hits 386 488 +102
Continue to review full report at Codecov.
|
Allow using the correct declension for numerals >=2 and <= 4.
…d forms * Add plural rules and forms from Mozilla localization concepts. * Convert cs and ru locales to the new format.
I extended the localization format to cover all possible languages. The simple adding of a new string key was not enough. Even the common languages were not covered well with the three plural forms and the single rule for them, as @leovp pointed out. Newly, the plural rule (a number or a function) has to be specified and the plural forms are specified as an array of strings, which the plural rule is an index to. relativeTime: {
// Slavic (Slovak, Czech), 3 plural forms for 1, 2-4, 5-
pluralRule: 8,
duration: {
s: 'několik sekund',
m: 'minuta',
mm: ['%d minuta', '%d minuty', '%d minut'],
h: 'hodina',
hh: ['%d hodina', '%d hodiny', '%d hodin'],
d: 'den',
dd: ['%d den', '%d dny', '%d dní'],
M: 'měsíc',
MM: ['%d měsíc', '%d měsíce', '%d měsícú'],
y: 'rok',
yy: ['%d rok', '%d roky', '%d let']
},
future: {
s: 'za několik sekund',
m: 'za minutu',
mm: ['za %d minutu', 'za %d minuty', 'za %d minut'],
h: 'za hodinu',
hh: ['za %d hodinu', 'za %d hodiny', 'za %d hodin'],
d: 'zítra',
dd: ['za %d den', 'za %d dny', 'za %d dní'],
M: 'za měsíc',
MM: ['za %d měsíc', 'za %d měsíce', 'za %d měsícú'],
y: 'za rok',
yy: ['za %d rok', 'za %d roky', 'za %d let']
},
past: {
s: 'před několika sekundami',
m: 'před minutou',
mm: ['před %d minutou', 'před %d minutami', 'před %d minutami'],
h: 'před hodinou',
hh: ['před %d hodinou', 'před %d hodinami', 'před %d hodinami'],
d: 'včera',
dd: ['před %d dnem', 'před %d dny', 'před %d dny'],
M: 'před měsícem',
MM: ['před %d měsícem', 'před %d měsíci', 'před %d měsíci'],
y: 'vloni',
yy: ['před %d rokem', 'před %d roky', 'před %d lety']
}
} The plural rule can be either a number from pluralRule: 8 pluralRule: n => n === 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2 The plural forms are an array of strings, where the first one is for 1 item (singular, or 21, 31 and other numbers, depending on the language) and the others are supposed to match the index returned by the plural rule function. If there is only a single special case how to handle zero, this should be the last one (with the highest index). Singulars for the value 1 are special, because they usually have no number in the text. I upgrade earlier locale format versions to retain the compatibility. |
Number 1 is not formatted using the plural forms as usual. There is an additional text added for this case.
…by using the fast-plural-rules NPM module * Remove the plurakl ule index from the localization object. * Introduce a dependency on the fast-plural-rules NPM module.
Hi! There is any progress for this issue? |
I think RelativeTime plugin has better support for fusional languages now. |
Redefining the locale object structure from the old one:
to the new one solves the problem 1 from #302:
Adding second expressions with three-letter keys for numerals greater or equal to 5 solves the problem 2 from #302:
My Czech localisation is an example how to use the new locale structure to support grammatically correct formatting.