hustcc / timeago.js

:clock8: :hourglass: timeago.js is a tiny(2.0 kb) library used to format date with `*** time ago` statement.
https://timeago.org
MIT License
5.29k stars 411 forks source link

locale translations are needed #19

Open hustcc opened 7 years ago

hustcc commented 7 years ago

The locales is here, you can add the miss name.

  1. Please sort by dictionary.
  2. Please ensure the accuracy.
  3. Please keep file size tiny.

How to ?

  1. Add you locale file into locales dir.
  2. Add you locale key into file.
  3. Add testcases into tests/lang dir.
  4. Then run npm test, if all passed, then commit the pr.

Thanks ^_^

craftystudio commented 5 years ago

Polish locale has mistakes @jcubic .

jcubic commented 5 years ago

@craftystudio what mistakes?

alexbutav commented 4 years ago

Russian locale doesn't work post.timePassed = timeago.format(new Date(dateStringUTC), 'ru'); echoes 4 hours ago while zh_CN locale echoes 4 小时前

lolobosse commented 4 years ago

@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:

image

The min version only contains en and zh. I guess that this is related to #204

I took the full and ru was working:

image

alexbutav commented 4 years ago

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 Аннотация 2020-04-22 200434

lolobosse commented 4 years ago

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)

alexbutav commented 4 years ago

Feel myself very stupid... great thanks!

gnurgeldiyev commented 4 years ago

Hey, @hustcc I just added tk locale.

here is the PR #220

idc77 commented 1 year ago

259 hr, rs