Chuvash localization of moment.js
By Anatoly Mironov
For three months ago I added Chuvash localization of moment.js. For 16 days ago moment.js 1.7.0 was officially released which included the Chuvash translation.
Wait a sec… What is moment.js?
moment.js is the best datetime tool for javascript. It supports many languages (now even Chuvash) for displaying date and time. Another very handy functionality is showing relative time which has a simple interface: fromNow().
Here is a simple example from a web browser console:
moment.lang("cv")
moment().subtract("days", 3).calendar()
//"Иртнĕ вырсарникун 07:30 сехетре"
moment().subtract("days", 3).subtract("hours", 10).calendar()
//"Иртнĕ шăматкун 21:31 сехетре"
moment("2011-10-04", "YYYY-MM-DD").fromNow()
//"10 уйăх каялла"
moment("2012-10-04", "YYYY-MM-DD").fromNow()
//"2 уйăхран"
Previous Issues
UPDATE: It has been released an update of moment.js: 1.7.1 where all of the issues with Chuvash localization are gone. For Until now there is was one issue with Chuvash localization of moment.js: wrong suffix in future relative time. In most supported languages in moment.js to express something what will happen in future, prepositions (words before, like in, for, by) are used. In the agglunative languages (Basque, Turkish, Korean and Japanese) postpositions (words after) are used. Chuvash is a bit different, the future is expressed by the ablative case.
ikĕ ujăh (2 months) - ikĕ ujăh**ran** (in two months)
Not a big deal, you think? It wouldn’t be if it there wasn’t vowel harmony (front and back vowels):
ikĕ sehet (2 hours) - ikĕ sehet**ren** (in two hours)
Besides vowel harmony the ablative case affix can be ran/ren (after almost all sounds) and tan/ten (after l n r).
ikĕ şul (2 years) - ikĕ şul**tan** (in two years)
For now it is not possible to provide a function for custom logic for future fromNow (like there is such functions for time units: minutes, montsh, years), something like that:
relativeTime : {
future : function(output) {
var affix = /сехет$/i.exec(output)
? "рен" : /çул$/i.exec(output) ? "тан" : "ран";
return output + affix;
}
//...
And the “humanize” function in moment.js has to be able to handle a function as parameter:
humanize : function (withSuffix) {
var difference = +this,
rel = this.lang().relativeTime,
output = relativeTime(difference, !withSuffix, this.lang());
if (withSuffix) {
var rt = difference <= 0 ? rel.past : rel.future;
//was: output = (difference <= 0 ? rel.past : rel.future).replace(/%s/i, output);
**if (typeof rt === 'function') {
output = rt(output);
}
else {
output = rt.replace(/%s/i, output);
}**
}
return output;
}
Comments from Wordpress.com
Tim Wood (@momentjs) - Aug 2, 2012
Submit a PR with the past/future callback and we’ll definitely pull it in!
Anatoly Mironov - Aug 2, 2012
Thank you, Tim! I will absolutely prepare a pull request.
Chuvash localization - Bool Tech - Jan 2, 2015
[…] momentjs, the most powerful date framework for javascript. […]
MagicMirror2 and Chuvash | CHUVASH.eu - Nov 4, 2020
[…] Chuvash localization of momentjs (blog post from 2015) […]