galene icon indicating copy to clipboard operation
galene copied to clipboard

feat: i18n

Open lpetic opened this issue 4 years ago • 12 comments

Hi,

I set up an i18n module. There are no external dependencies. I loaded 2 available languages (en & fr).

Principipaly this is based on (key, value) JSON file. I inspire myself from the jQuery attribute data-i18n.

In the HTML file:

<h1 data-i18n="app"></h1>

In the JavaScript files:

displayError(trans.get('disconnected'), 'error');

Fix: #33

lpetic avatar Mar 06 '21 18:03 lpetic

This only translates messages that come from the Javascript, right? Or am I missing something and does it also translate the parts of the UI that are in HTML?

jech avatar Mar 07 '21 11:03 jech

The translation is supported on both sides.

Only some error messages are not supported, because there are directly given by the server.

https://user-images.githubusercontent.com/40602497/110239150-de101900-7f45-11eb-8efd-f777947d41f5.mov

lpetic avatar Mar 07 '21 12:03 lpetic

How Translation.prototype.selectLanguage = function (language) works? Does it parse all the languages in the header accepted_language or only the first one?

Mejans avatar Mar 07 '21 17:03 Mejans

I didn't use any header as Accepted-Language. Should I (maybe I missed something)? I touched only the client-side. The serve didn't know which language the user uses.

Translation.prototype.selectLanguage = function (language){
    this.language = this.languages.filter(l => l === language).length === 1 ? language : this.default;
}

This method will initialize the field this.language in the constructor. By default, I use the field navigator.language.

The method Translation.prototype.analyse will analyze the HTML and will set the right value related to the key stored by the attribute data-i18n.

lpetic avatar Mar 07 '21 20:03 lpetic

I meant, does it read all the languages a user has chosen or only the first one? I don't see a loop and I don't understand turner things :S

Mejans avatar Mar 08 '21 18:03 Mejans

The patch uses the navigator.language value. As @inlor suggested, it should probably loop over navigator.languages (notice the s at the end) and pick the first language for which a translation is available, but that can be added in a future version.

For now, the important things to decide are:

  • is this feature worth the extra maintenance burden?
  • is this the right approach, or should we be using the English strings as indices in the translation table, as is the case with GNU gettext?

I have little experience with translation (I'm usually into software in English but with full support for non-ASCII scripts), so I'd welcome advice on both points above.

jech avatar Mar 08 '21 21:03 jech

  • I don't think that this feature will grow up the maintainability (after all, there are only messages).
  • I saw examples here, to my mind usage of English string instead of key seems to be fragile. But, if you think that is better, I can change it @jech.

@Mejans seems to have some experience with i18n modules.

lpetic avatar Mar 09 '21 11:03 lpetic

I usually translate and some times I write code :) And often I see some web sites only take the first language then falling back to English whereas the second language was available :(

Mejans avatar Mar 09 '21 18:03 Mejans

@jech Any news related to this PR?

lpetic avatar Apr 02 '21 07:04 lpetic

I'm coming to check if there is news about this feature.

Mejans avatar Apr 16 '21 15:04 Mejans

Sorry. I'm currently aiming at getting a stable 0.3.3 out, with no new features, just fixes. I'll think about this after 0.3.3 is out.

jech avatar Apr 16 '21 19:04 jech

I've just made this PR https://github.com/jech/galene/pull/103 :)

Mejans avatar Aug 26 '21 18:08 Mejans