Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i18n proposal #1153

Closed
wants to merge 14 commits into from
Closed

i18n proposal #1153

wants to merge 14 commits into from

Conversation

marcelklehr
Copy link
Contributor

This is one possible solution for adding support for translations.

@marcelklehr
Copy link
Contributor Author

It makes use of https://github.com/fabi1cazenave/webL10n, which loads translations dynamically from inside the browser and applies them to the current html.

The route for /locale.ini takes into account the preferred languages of the client, tries to intersect them with the available l10ns and finally returns a suiting translation.

If there are no translations available, all strings will still be in English (English strings are written directly into the template).

L10s are located in src/locales.

@JohnMcLear
Copy link
Member

Poor timeslider.html got left out? :)

@JohnMcLear
Copy link
Member

[2012-11-10 16:24:51.367] [ERROR] console - { [Error: ENOENT, stat '/home/etherpad-lite/src/locales/en.ini']
  errno: 34,
  code: 'ENOENT',
  path: '/home/etherpad-lite/src/locales/en.ini',
  status: 404 }
Error: ENOENT, stat '/home/etherpad-lite/src/locales/en.ini'

@JohnMcLear
Copy link
Member

No option to change language in settings, that afaik is a requirement

@JohnMcLear
Copy link
Member

src/static/js/l10n.js not l18n.js?

I know this is right but briefly what's the dif between l10n and l18n?

@JohnMcLear
Copy link
Member

This adds ability to change language using settings

pad.settings.language needs to be in the language file de.ini
And window.webL10n.loadLocale is wrong, I'm not sure how to access it..

Add to line 74 on pad_editor.js

      $("#languagemenu").change(function()
      {
        window.webL10n.loadLocale($("#languagemenu").val()); // This is wrong and needs fixing
        pad.createCookie("language",$("#languagemenu").val(),null,document.location.pathname);
      });

Add to line 210 on pad.html

               <p data-l10n-id="pad.settings.language">
                    Language:
                    <select id="languagemenu">
                        <option value="en">English</option>
                        <option value="de">Deutsch</option>
                    </select>
                </p>

Because English is the first option people should realize it's a language selector and feel comfortable clicking it to change their window's language option.

@JohnMcLear
Copy link
Member

Btw I should of said this is awesome :) 👍

@marcelklehr
Copy link
Contributor Author

OK, so...

re: timeslider
Yea, didn't have time for timeslider.html...

re: ENOENT, stat 'src/locales/en.ini' -- right. going to rule that out

Secondly: Why would you want an extra setting for the UI languagage? /locale.ini will always serve the best-suiting language based on the browser's 'Accept-Language' header: Globalize.culture( req.header('Accept-Language') || 'en' );

C: The filename issue: There's only i18n and l10n and according to this helpful paragraph "An internationalized system is equipped for use [...] by users of multiple languages, by allowing the co-existence of several languages and character sets for input, display, and UI", so this patch is about i18n, the library is named l10n, though, so i kept that name.

Lastly: Thanks! :)

@marcelklehr
Copy link
Contributor Author

It's probably worth noting, that I tweaked webL10n a bit to suit our needs (e.g. it wouldn't allow for key nesting like foo.bar.bla -- it always assumed you wanted directly access a property of the DOM node. This still works as you may have noticed with keys like pad.foo.title, but only with whitelisted properties.)

@JohnMcLear
Copy link
Member

@marcelklehr RE: B: Because I'm in an Internet cafe in Italy and the browser's language is set to .it but I want .en. We should also save this setting as a cookie so when the user returns they are presented with the correct language.

Do you want me to do the timeslider.html?

@Pita
Copy link
Contributor

Pita commented Nov 11, 2012

Looks good for me. But out of curiosity, can I do translations like "you have {amount} new mails"? Cause this is the point where translation gets really tricky. See here http://www.youtube.com/watch?feature=player_embedded&v=MqqdzJ98q7s . As far as I see we don't have this specific case so far, but it will probably come with extended functionality

@Pita
Copy link
Contributor

Pita commented Nov 11, 2012

Also I don't see any modifications to the client js. How does it work when I set another text with jquery of if I create a new dom element on the fly?

@marcelklehr
Copy link
Contributor Author

@Pita interesting talk! webL10n has some pretty advanced features: https://github.com/fabi1cazenave/webL10n#javascript-api
It provides arguments, include rules, a pluralization macro, and a javascript API which you can use to translate strings in javascript (useful for things like alert()'s).

Nonetheless, if you want to dynamically display a certain text / text inside a DOM node with javascript, it probably makes more sense to simply make a template out of it and make it translatable (btw, that's what she speaks of in the talk, too: i18n helps you separate storage and presentation (and selection and transformation, of course)).

Are there strings in client.js that need to be translated?

@johnyma22 Greetings to you over in Italy. Can't you change your browsers settings? Oh, sorry, if you don't understand Italian that's hard, ok so, I agree, that it might make more sense to allow the user to override the autodetection. So, it'd go like this: Globalize.culture( [ req.cookie('lang'), req.header('Accept-Language'), 'en' ]);

@marcelklehr
Copy link
Contributor Author

@johnyma22 if you want to / are able to you can translate timeslider.html, too

@marcelklehr
Copy link
Contributor Author

Nearly ready, now. just need to make the word timeslider translatable in timeslider.html

@MarkTraceur
Copy link
Contributor

FYI the only feedback I got from the i18n team at WMF was to use this:

https://www.mediawiki.org/wiki/Universal_Language_Selector

@JohnMcLear
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants