vi / timeago

In Rust, format Duration into a string like "1 hour ago" or "01hou".
https://docs.rs/timeago/
Apache License 2.0
68 stars 17 forks source link

Add support for translations #3

Open notramo opened 6 years ago

vi commented 6 years ago

Of the long format or also for short as well?

How are translations in general handled in Rust world? Is there some sample library crate where translations are implemented?

hoodie commented 6 years ago

There is a crate called crowbook-intl. If any body knows another I'd be interested

notramo commented 6 years ago

I'm not familiar with Rust, but I think translations should be hardcoded, because these are short words that won't likely change, so it don't need a transation system that tracks the changes of the original text. In some languages, the text needs to be changed according to the number: 1 day or 2 days, but in other languages, it don't. Also, in some languages there are special phrases for describing time durations, that are shorter than the loan translation of e.g. '%s days ago'. For example, in Hungarian, the loan translation of '2 days ago' is '2 nappal ezelőtt', which is a quite long, but there is an inflection of the 'day' ('nap') word that is the same: '2 napja'.

vi commented 6 years ago

Shall it allow to choose the language from enum (populated only with English initially) and allow to opt-in more hard coded translations using Cargo features?

vi commented 6 years ago

Is there maybe a crate with authoritative list of languages for localisation as an enum, but which does not enforce any particular scheme?

notramo commented 6 years ago

I think it don't need to be opt-in. I meant hardcoded text that it should be implemented in Rust code instead of external solutions (YAML, .po files), because it is more flexible. All languages should be available at runtime, no need for Cargo features.

vi commented 6 years ago

Please review the proposed API for translation and additional features: https://github.com/vi/timeago/blob/3656ed710edacd13699d147ef6d3dc9ab694dee8/src/lib.rs

Is it going to the right direction?

hoodie commented 6 years ago

@vi have you looked at crowbook-intl?

vi commented 6 years ago

I've glanced there once, saw tricky build script and macros and looked away.

Is the way there a good way do to translations? Can it be opt-in (preserving simplicity for ones who don't care about translations)?

vi commented 6 years ago

Added some support for translations (without build scripts or macros, but with isolangs interface) in version 0.1.1.

Is it the translation support you expect?

I don't think formatting time intervals is to be done by some framework with loadable files. Each language can contain tricks to algotithms.

Currently only provided translations for languages that I personally know/learned.

joseluis commented 5 years ago

I think it may be worth it to implement fluent. I'be been meaning to use it for my things, but I've not played with it yet.

Some links:

vi commented 5 years ago

@joseluis , How do you expect timeago and fluent to interact? Using fluent's functions?

joseluis commented 5 years ago

@vi Oh, easy. This is the rust crate https://crates.io/crates/fluent