Set up translation library Polyglot.js #29

Closed
wants to merge 11 commits into
from

Conversation

Projects
None yet
6 participants
@misjoinder
Contributor

misjoinder commented Jan 13, 2014

Uses JavaScript to detect user's language
Uses Polyglot.js ( https://github.com/airbnb/polyglot.js ) to match to translate Twister UI

  • Using Polyglot on the JS side is easy - use polyglot.t("text") in place of a string, and if "text" is one of the words in the dictionary, it will translate the word.
  • A list of words and explanation to add more languages is in interface_localization.js
  • Using Polyglot with the HTML was more complicated. In interface_localization.js, there is a list of selectors for elements that need to be translated, such as ".network h2, .network h3" for the titles on the Network page. Once jQuery(document).ready is called, the HTML is translated. This also means that the templates are translated in time for the updated elements to be used.
  • Right now English and Dutch are available but translation will not be visible unless your default language is in Dutch. If you uncomment lines 172-174 in interface_localization.js, it will replace all strings with filler text. If anything is left untranslated then it should be fixed in JS or the element should be added to the list in interface_localization.js
@basst85

This comment has been minimized.

Show comment
Hide comment
@basst85

basst85 Jan 14, 2014

The label "Followed by" in the div "Who to follow" is not showing the translated text.

The label "Followed by" in the div "Who to follow" is not showing the translated text.

@misjoinder

This comment has been minimized.

Show comment
Hide comment
@misjoinder

misjoinder Jan 15, 2014

Contributor

@basst85 Thank you! I just pushed a change which includes that text in things to translate

Contributor

misjoinder commented Jan 15, 2014

@basst85 Thank you! I just pushed a change which includes that text in things to translate

@toyg toyg referenced this pull request Jan 16, 2014

Closed

internalization support #23

@toyg

This comment has been minimized.

Show comment
Hide comment
@toyg

toyg Jan 16, 2014

Collaborator

Is there any chance that language-specific resources could be separately downloaded when necessary? Putting all translations in one humongous, non-minified JS file is not the best approach in terms of scalability. Yes, I know 90% of users will fetch this from localhost, but some (like me) will run remote nodes.

Collaborator

toyg commented Jan 16, 2014

Is there any chance that language-specific resources could be separately downloaded when necessary? Putting all translations in one humongous, non-minified JS file is not the best approach in terms of scalability. Yes, I know 90% of users will fetch this from localhost, but some (like me) will run remote nodes.

Merge pull request #2 from basst85/polyglot
More Dutch translation, include "Reply to %{username}" in translatable text
@BlockTester

This comment has been minimized.

Show comment
Hide comment
@BlockTester

BlockTester Jan 16, 2014

Contributor

+1 @toyg

Contributor

BlockTester commented Jan 16, 2014

+1 @toyg

@misjoinder

This comment has been minimized.

Show comment
Hide comment
@misjoinder

misjoinder Jan 16, 2014

Contributor

I would be interested in ideas to make the translation file more targeted or smaller. My first thought was to make separate JSON files for each language, but then we would need to start running JS, detect language, and complete an AJAX call before the rest of the page is rendered. My second thought is to use a JS build process, such as Jake, to minify all JS in twister-html.

My final thought is that we do not need to fix this today. It is many lines, but it's about 10KB for each language, unminified. With 9 languages it would be smaller than jQuery.

Contributor

misjoinder commented Jan 16, 2014

I would be interested in ideas to make the translation file more targeted or smaller. My first thought was to make separate JSON files for each language, but then we would need to start running JS, detect language, and complete an AJAX call before the rest of the page is rendered. My second thought is to use a JS build process, such as Jake, to minify all JS in twister-html.

My final thought is that we do not need to fix this today. It is many lines, but it's about 10KB for each language, unminified. With 9 languages it would be smaller than jQuery.

@iShift

This comment has been minimized.

Show comment
Hide comment
@iShift

iShift Jan 16, 2014

Contributor

google compiler can minify js http://closure-compiler.appspot.com/home

Contributor

iShift commented Jan 16, 2014

google compiler can minify js http://closure-compiler.appspot.com/home

@toyg

This comment has been minimized.

Show comment
Hide comment
@toyg

toyg Jan 16, 2014

Collaborator

@msjoinder you're probably right, I'm thinking over-optimisation. Expect an Italian translation soon ;)

Collaborator

toyg commented Jan 16, 2014

@msjoinder you're probably right, I'm thinking over-optimisation. Expect an Italian translation soon ;)

@misjoinder

This comment has been minimized.

Show comment
Hide comment
@misjoinder

misjoinder Jan 16, 2014

Contributor

@iShift the benefit of using a tool like Jake in the future would be to have a consistent minifier that runs on the command line. A developer could make the changes they want to the original JS and run jake to rebuild the one minified file. If there's a similar tool that doesn't require node and npm that might be better.

Contributor

misjoinder commented Jan 16, 2014

@iShift the benefit of using a tool like Jake in the future would be to have a consistent minifier that runs on the command line. A developer could make the changes they want to the original JS and run jake to rebuild the one minified file. If there's a similar tool that doesn't require node and npm that might be better.

@toyg

This comment has been minimized.

Show comment
Hide comment
@toyg

toyg Jan 16, 2014

Collaborator

@msjoinder @iShift @BlockTester it looks like this pull is not going anywhere, our BDFL is not particularly convinced. However, I think we can move it to a separate branch, where I can track commits from master as well as accepting i18n-related pull reqs. When/if Miguel will eventually come around, we'll merge back. We can add a note in docs to say that, if you want a translated UI for languages X/Y/Z you just have to do git checkout i18n to get the right branch.

I think it's a good compromise to keep things going forward, what do you think ?

Collaborator

toyg commented Jan 16, 2014

@msjoinder @iShift @BlockTester it looks like this pull is not going anywhere, our BDFL is not particularly convinced. However, I think we can move it to a separate branch, where I can track commits from master as well as accepting i18n-related pull reqs. When/if Miguel will eventually come around, we'll merge back. We can add a note in docs to say that, if you want a translated UI for languages X/Y/Z you just have to do git checkout i18n to get the right branch.

I think it's a good compromise to keep things going forward, what do you think ?

@iShift

This comment has been minimized.

Show comment
Hide comment
@iShift

iShift Jan 16, 2014

Contributor

@toyg maybe, but why not master branch?

Contributor

iShift commented Jan 16, 2014

@toyg maybe, but why not master branch?

@toyg

This comment has been minimized.

Show comment
Hide comment
@toyg

toyg Jan 16, 2014

Collaborator

I guess Miguel just wants to be free to move stuff around without having to worry about marking translatable strings and the like, it's still early days and a lot of things might move and break. I think if we prove that Polyglot does the job, that the job is manageable, that we can have good-quality popular translations and that we can keep up with changes, we'll eventually end up in master.

Collaborator

toyg commented Jan 16, 2014

I guess Miguel just wants to be free to move stuff around without having to worry about marking translatable strings and the like, it's still early days and a lot of things might move and break. I think if we prove that Polyglot does the job, that the job is manageable, that we can have good-quality popular translations and that we can keep up with changes, we'll eventually end up in master.

@toyg

This comment has been minimized.

Show comment
Hide comment
@toyg

toyg Jan 16, 2014

Collaborator

For the record, I did create a new branch miguelfreitas/i18n , please point to that one when creating pull requests for translations. I've merged all recent commits, so we shouldn't have lost anything. Now, when you do pull requests for i18n work, make sure you're pointing to miguelfreitas/i18n rather than /master and I'll merge straight away.

Collaborator

toyg commented Jan 16, 2014

For the record, I did create a new branch miguelfreitas/i18n , please point to that one when creating pull requests for translations. I've merged all recent commits, so we shouldn't have lost anything. Now, when you do pull requests for i18n work, make sure you're pointing to miguelfreitas/i18n rather than /master and I'll merge straight away.

@toyg toyg closed this Jan 16, 2014

@miguelfreitas

This comment has been minimized.

Show comment
Hide comment
@miguelfreitas

miguelfreitas Jan 16, 2014

Owner

thanks @toyg :-)

Owner

miguelfreitas commented Jan 16, 2014

thanks @toyg :-)

@miguelfreitas

This comment has been minimized.

Show comment
Hide comment
@miguelfreitas

miguelfreitas Jan 16, 2014

Owner

also for the record: on a cursory look, polyglot.js seems like a good solution to me.

Owner

miguelfreitas commented Jan 16, 2014

also for the record: on a cursory look, polyglot.js seems like a good solution to me.

@misjoinder

This comment has been minimized.

Show comment
Hide comment
@misjoinder

misjoinder Jan 23, 2014

Contributor

Excited to see that so many languages are being added! @toyg has been doing a great job bringing them in on the i18n branch and keeping it up to date with changes in the master branch.

Contributor

misjoinder commented Jan 23, 2014

Excited to see that so many languages are being added! @toyg has been doing a great job bringing them in on the i18n branch and keeping it up to date with changes in the master branch.

@miguelfreitas

This comment has been minimized.

Show comment
Hide comment
@miguelfreitas

miguelfreitas Jan 23, 2014

Owner

@msjoinder @toyg I was about to suggest merging i18n to master since my hope to start (or somebody else) a rework of twister-html into a better framework (MVC?) didn't materialize... But I just tried it and i got a few errors, it didn't quite worked.

Uncaught SyntaxError: Unexpected string interface_localization.js:286
Uncaught ReferenceError: polyglot is not defined twister_network.js:125
Uncaught ReferenceError: polyglot is not defined interface_common.js:80

Owner

miguelfreitas commented Jan 23, 2014

@msjoinder @toyg I was about to suggest merging i18n to master since my hope to start (or somebody else) a rework of twister-html into a better framework (MVC?) didn't materialize... But I just tried it and i got a few errors, it didn't quite worked.

Uncaught SyntaxError: Unexpected string interface_localization.js:286
Uncaught ReferenceError: polyglot is not defined twister_network.js:125
Uncaught ReferenceError: polyglot is not defined interface_common.js:80

@misjoinder

This comment has been minimized.

Show comment
Hide comment
@misjoinder

misjoinder Jan 23, 2014

Contributor

Looks like #77 resolved this issue (missing a comma after one of the translations)

Contributor

misjoinder commented Jan 23, 2014

Looks like #77 resolved this issue (missing a comma after one of the translations)

@toyg

This comment has been minimized.

Show comment
Hide comment
@toyg

toyg Jan 23, 2014

Collaborator

Yup, I hadn't reviewed the Chinese too closely (er...).
I'll try to merge now, wish me luck ;)

Collaborator

toyg commented Jan 23, 2014

Yup, I hadn't reviewed the Chinese too closely (er...).
I'll try to merge now, wish me luck ;)

toyg added a commit that referenced this pull request Jan 23, 2014

@miguelfreitas

This comment has been minimized.

Show comment
Hide comment
@miguelfreitas

miguelfreitas Jan 24, 2014

Owner

working fine here, thanks!

Owner

miguelfreitas commented Jan 24, 2014

working fine here, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment