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: Add full i18n support #84

Merged
merged 1 commit into from
Dec 17, 2017
Merged

i18n: Add full i18n support #84

merged 1 commit into from
Dec 17, 2017

Conversation

mooncos
Copy link
Member

@mooncos mooncos commented Dec 13, 2017

This adds i18n support for the app, being
rendered in client-side so that translations
can be loaded dynamically. Implemented language
fallbacks for non-existing translations, plurals
and dynamic placeholders for strings.

Fixes #38

Copy link
Member

@blazeu blazeu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than storing the vendor js files in our repo, load it from somewhere, like cdnjs, jsdelivr or unpkg.

This will avoid the need to ignore those files in our linter, and it's the best that we can do before implementing a build system that takes care of npm/js package in the browser.

.coafile Outdated
@@ -1,6 +1,6 @@
[all]
files = **.js, **.json, **.css, **.yml, **.html, .eslintrc
ignore = node_modules/**, out/**, package-lock.json
ignore = node_modules/**, out/**, package-lock.json, static/js/lib/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do this please, we want those files to be linted

"last-updated": "आखरी अपडेट",
"order-info": "प्रत्येक संगठन (और उनके GitHub खाते, यदि लागू हो) के लिए प्रमुख प्रतिभागी क्रमशः सूचीबद्ध होते हैं",
"tasks-completed": "पूरा कार्य",
"footer-text": "Google Code-in और इसके लोगो Google Inc. के ट्रेडमार्क हैं",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent problem.

"tasks-completed": "Tugas selesai",
"footer-text": "Google Code-in dan logonya adalah merek dagang terdaftar dari Google Inc.",
"orgs-no-listed": "Organisasi tanpa pemimpin yang terdaftar",
"passed": "$1% passed, approximately $2 before task claiming ends",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it isnt translated, it should be omitted, so that we can build checks for percentage translated, and tools to create translations.

does jquery.i18n not support fallback to English for missing messages?

If it doesnt, please dont include languages which you dont know your translation is 100% accurate and complete. We can use http://hosted.weblate.org/ to manage the collection of translations and ensure they are complete before the file is available for the i18n layer.

@@ -0,0 +1,21 @@
{
"page-title": "Google Code-in 2017 वर्तमान नेता",
"last-updated": "आखरी अपडेट",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where did you get this translation from?

Is that translation MIT licensed per #6?
If not, please remove, and we'll acquire the translation again using a method that complies with the intended license of this repo.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we should remove all translation for now and only keep en or 2.

jayvdb
jayvdb previously requested changes Dec 16, 2017
@@ -9,7 +9,7 @@ bears = SpaceConsistencyBear
default_actions = *: ApplyPatchAction

[all.linelength]
ignore += **.html
ignore += **.html, static/js/i18n/**.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh? Why is this?

They should all be unicode, and should all be nicely structured JSON.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON doesn't have linebreaks and the translations for some strings are too long for the linelength limit.

/>
</a>
{{/github}}
{{#mailing_list}}
<a href="{{mailing_list}}">
<img src="images/mail.png" class="chat" alt="Join their mailing list" />
<img src="images/mail.png" class="chat" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why removing all the alt?
jquery.i18n doesnt support them?
English only alt is better than no alt..?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may also be related to the #78 merge

<head>
<meta charset="utf-8">
<title>GCI Leaders</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it is doing something unrelated to the issue you are solving..?
please correct me if I am wrong about that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -1,22 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<html>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lang="mul".

If not, it should still be lang=en, because it is only with JavaScript enabled that it is multilingual, and the JavaScript should update the lang attribute as required.

@jayvdb
Copy link
Member

jayvdb commented Dec 16, 2017

unack 911e838

@mooncos
Copy link
Member Author

mooncos commented Dec 16, 2017

Sorry those were conflicts with rebasing from master as main.html was changed. Will fix now.

@blazeu
Copy link
Member

blazeu commented Dec 17, 2017

Can you add a languange switcher? Maybe using <select>

@@ -0,0 +1,24 @@
var browser_locale = window.navigator.language.split('-')[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelCase please

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops too accustomed to python hehe

updateTranslation(browser_locale)
$('#lang-select').val(browser_locale)
$('#lang-select').on('change', function() {
updateTranslation(this.value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if the user's preference is saved (preferably in localStorage), so that the user doesn't need to change it on every visit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also why is this not in the other file? (language_switcher)

<script src="js/app.js"></script>
<script>
$(window).on('load', function() {
$.getScript('js/app.js')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw you were using defer before, why change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defer was not working properly. I implemented this workaround to make sure that the translation file finished importing before applying the translations

Copy link
Member

@blazeu blazeu Dec 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

translation file finished importing

Then it's not $(window).on('load'), there must be another event from jquery.i18n

Copy link
Member Author

@mooncos mooncos Dec 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to because the text to translate (the HTML) needs to load as well so $(window).on('load') is the correct way.


.chooser {
margin-top: 0.5em;
display: flex;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need flex

console.log('i18n:' + localex + ' locale loaded')
$('body').i18n()
$('html').attr('lang', localex)
$.getScript('js/app.js')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ You have done it here.

})
}

$(window).on('load', function() {
Copy link
Member

@blazeu blazeu Dec 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$(window).on('load') is here ^

var nav = window.navigator
browserLocale =
nav.language.split('-')[0] || nav.language || nav.userLanguage || ''
localStorage.setItem('lang', browserLocale)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only store if the user has specifically selected a language.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

This adds i18n support for the app, being
rendered in client-side so that translations
can be loaded dynamically. Implemented language
fallbacks for non-existing translations, plurals
and dynamic placeholders for strings.

Fixes coala#38
@blazeu
Copy link
Member

blazeu commented Dec 17, 2017

ack 2899de9

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

Successfully merging this pull request may close these issues.

4 participants