timeago icon indicating copy to clipboard operation
timeago copied to clipboard

Add support for translations

Open notramo opened this issue 7 years ago • 13 comments

notramo avatar Dec 16 '17 13:12 notramo

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?

vi avatar Dec 16 '17 14:12 vi

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

hoodie avatar Dec 17 '17 09:12 hoodie

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'.

notramo avatar Feb 05 '18 12:02 notramo

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 avatar Feb 05 '18 13:02 vi

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

vi avatar Feb 05 '18 14:02 vi

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.

notramo avatar Feb 05 '18 16:02 notramo

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?

vi avatar Feb 07 '18 00:02 vi

@vi have you looked at crowbook-intl?

hoodie avatar Feb 07 '18 11:02 hoodie

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 avatar Feb 07 '18 12:02 vi

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.

vi avatar Mar 26 '18 01:03 vi

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:

  • https://projectfluent.org/fluent/guide/
  • https://github.com/projectfluent/fluent/wiki/Fluent-vs-gettext
  • https://www.yetanothertechblog.com/2018/04/05/why-fluent-matters-for-localization/
  • https://github.com/projectfluent/fluent-web/blob/master/examples/localization/pl/main.ftl

joseluis avatar Apr 08 '19 16:04 joseluis

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

vi avatar Apr 08 '19 17:04 vi

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

joseluis avatar Apr 08 '19 17:04 joseluis