timeago.js
timeago.js copied to clipboard
locale translations are needed
The locales is here, you can add the miss name.
- Please sort by dictionary.
- Please ensure the accuracy.
- Please keep file size tiny.
How to ?
- Add you locale file into locales dir.
- Add you locale key into file.
- Add testcases into tests/lang dir.
- Then run
npm test, if all passed, then commit the pr.
- [x] ar
- [ ] az
- [ ] az
- [x] be
- [x] bg
- [ ] bs
- [x] ca
- [ ] cs
- [ ] cy
- [x] da
- [x] de
- [ ] dv
- [x] el
- [x] en
- [x] en_short
- [x] es
- [ ] et
- [x] eu
- [x] fa
- [ ] fi
- [x] fr
- [x] gl
- [x] he
- [ ] hr
- [x] hu
- [ ] hy
- [ ] id
- [x] in_BG
- [x] in_HI
- [x] in_ID
- [ ] is
- [x] it
- [x] ja
- [ ] jv
- [x] ko
- [ ] ky
- [ ] lt
- [ ] lv
- [ ] mk
- [x] ml
- [x] my
- [x] nb_NO
- [x] nl
- [x] nn_NO
- [ ] no
- [x] pl
- [x] pt_BR
- [ ] pt
- [x] ro
- [ ] rs
- [x] ru
- [ ] rw
- [ ] si
- [ ] sk
- [ ] sl
- [ ] sr
- [x] sv
- [x] ta
- [x] th
- [x] tr
- [x] uk
- [ ] uz
- [x] vi
- [x] zh_CN
- [x] zh_TW
Thanks ^_^
Polish locale has mistakes @jcubic .
@craftystudio what mistakes?
Russian locale doesn't work
post.timePassed = timeago.format(new Date(dateStringUTC), 'ru');
echoes 4 hours ago
while zh_CN locale echoes 4 小时前
@alexbutav I could reproduce your issue by using a CDN. Is that what you did?
Actually I didn't know how it works (I'm the maintainer of the python version) and I had the same error.
If you look at CDNJS (for instance), you will see following:

The min version only contains en and zh. I guess that this is related to #204
I took the full and ru was working:

Greetings. No, i didn't use CDN, i installed it with npm
"dependencies": {
"axios": "^0.19",
"chart.js": "^2.9.3",
"js-cookie": "^2.2.1",
"json-bigint": "^0.3.0",
"laravel-echo": "^1.7.0",
"laravel-echo-server": "^1.6.1",
"nanobar": "^0.4.2",
"timeago.js": "^4.0.2",
"socket.io-client": "^2.3.0",
"vue": "^2.6.11",
"vue-analytics": "^5.22.1",
"vue-i18n": "^8.12.0",
"vue-router": "^3.1.5",
"vuex": "^3.1.2"
}
then imported in Vue Component
import * as timeago from 'timeago.js';
build with webpack
and then run
For now i took original ru locale and adapted it according to the doc. So after importing of timeago.js i register it manually:
import localeRU from '../library/timeago_ru';
timeago.register('ru', localeRU);
timeago_ru,js
function formatNum(f1, f, s, t, n) {
const n10 = n % 10;
let str = t;
if (n === 1) {
str = f1;
} else if (n10 === 1 && n > 20) {
str = f;
} else if (n10 > 1 && n10 < 5 && (n > 20 || n < 10)) {
str = s;
}
return str;
}
const seconds = formatNum.bind(null, 'секунду', '%s секунду', '%s секунды', '%s секунд'),
minutes = formatNum.bind(null, 'минуту', '%s минуту', '%s минуты', '%s минут'),
hours = formatNum.bind(null, 'час', '%s час', '%s часа', '%s часов'),
days = formatNum.bind(null, 'день', '%s день', '%s дня', '%s дней'),
weeks = formatNum.bind(null, 'неделю', '%s неделю', '%s недели', '%s недель'),
months = formatNum.bind(null, 'месяц', '%s месяц', '%s месяца', '%s месяцев'),
years = formatNum.bind(null, 'год', '%s год', '%s года', '%s лет');
export default function(number, index, totalSec) {
// number: the time ago / time in number;
// index: the index of array below;
// totalSec: total seconds between date to be formatted and today's date;
return [
['только что', 'через несколько секунд'],
[seconds(number) + ' назад', 'через ' + seconds(number)],
[minutes(number) + ' назад', 'через ' + minutes(number)],
[minutes(number) + ' назад', 'через ' + minutes(number)],
[hours(number) + ' назад', 'через ' + hours(number)],
[hours(number) + ' назад', 'через ' + hours(number)],
['вчера', 'завтра'],
[days(number) + ' назад', 'через ' + days(number)],
[weeks(number) + ' назад', 'через ' + weeks(number)],
[weeks(number) + ' назад', 'через ' + weeks(number)],
[months(number) + ' назад', 'через ' + months(number)],
[months(number) + ' назад', 'через ' + months(number)],
[years(number) + ' назад', 'через ' + years(number)],
[years(number) + ' назад', 'через ' + years(number)],
][index];
};
Interesting thing is that i can see 'ru' locale installed with package inside lib directory

Is that not what you're looking for? https://github.com/hustcc/timeago.js/issues/175#issuecomment-455328067
Found it, might be an idea to add it to the documentation import { nl as locale_NL } from 'timeago.js/lib/lang';
So I would import it and then register it (without copying the locale code)
Feel myself very stupid... great thanks!
Hey, @hustcc I just added tk locale.
here is the PR #220
#259 hr, rs