tko icon indicating copy to clipboard operation
tko copied to clipboard

Internationalization

Open brianmhunt opened this issue 9 years ago • 6 comments

KO needs some internationalization

Note:

  • http://formatjs.io/
  • http://i18next.com/
  • http://stackoverflow.com/questions/11436685/
  • http://stackoverflow.com/questions/16882171

brianmhunt avatar Nov 16 '16 16:11 brianmhunt

I worked with i18next and its adapters to angular a lot in the past. To me it feels really slick and natural. If you take knockout.punches into account you could solve it through piping as in angular:

<span>{{'general.greet' | translate::username}}</span>

Though the way the filter parameters are passed in ko.punches could be improved like so:

<span>{{'general.greet' | translate: {name: username} }}</span>

That way you would have named parameters and you wouldn't introduce a new syntax, instead you'd have an ordinary JavaScript object.

Number and Date formatting is not provided by i18next afaik. edit: apparently it does: http://i18next.com/translate/formatting/

krnlde avatar Dec 04 '16 14:12 krnlde

Given a binding translator (like i18next), there are three ways I think it could be employed:

  1. A binding provider (i.e. tko.provider.i18n) - converts text nodes by running them through a binding-translator based on some criteria/regex/etc
  2. an explicit i18n binding works like, or pairs with, the text binding
  3. one or more i18n filters that pluralize/etc

A sane strategy for one or more of these probably requires delving into what others do.

brianmhunt avatar May 12 '17 18:05 brianmhunt

I wouldn't suggest using an explicit i18n-binding since it limits the possibilities to work with i18n. Think of attribute-values like placeholder or title. Think of combining multiple keys. The rest is totally cool :)

krnlde avatar May 13 '17 15:05 krnlde

To limit documentation effort, and despite API inconsistency, I'd suggest a provider of the exactly same syntax as https://github.com/i18next/jquery-i18next with the extra requiment that data-i18n-options might be subscribable and trigger a new translation when changing. Also this syntax is supported by https://github.com/i18next/i18next-parser

miellaby avatar Dec 28 '17 15:12 miellaby

@miellaby those are fantastic suggestions, thank you

brianmhunt avatar Dec 28 '17 20:12 brianmhunt

Noting: https://metacpan.org/pod/distribution/Locale-Maketext/lib/Locale/Maketext/TPJ13.pod?_ke=eyJrbF9lbWFpbCI6ICJicmlhbm1odW50QGdtYWlsLmNvbSIsICJrbF9jb21wYW55X2lkIjogImU3WUMzdSJ9#A_Localization_Horror_Story:_It_Could_Happen_To_You

brianmhunt avatar Nov 28 '18 17:11 brianmhunt