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

JavaScript Translations #9576

Merged
merged 6 commits into from
Dec 16, 2015
Merged

JavaScript Translations #9576

merged 6 commits into from
Dec 16, 2015

Conversation

biyeun
Copy link
Member

@biyeun biyeun commented Dec 15, 2015

@dimagi/js-team Added ability to translate javascript files. In order for django to pick up on changes,
./manage.py makemessages -d djangojs --all will need to be run in addition to the standard makemessages command. compilemessages should be run as normal.

In addition to this, you'll need to run ./manage.py compilejsi18n to make the translation utilities available in all js files.

@biyeun biyeun added the Open for review: do not merge A work in progress label Dec 15, 2015
@biyeun
Copy link
Member Author

biyeun commented Dec 15, 2015

@dimagi/team-commcare-hq when this is merged, you'll need to run manage.py compilejsi18n

@@ -159,7 +161,7 @@ function CommcareSettings(options) {
uniqueNames = names.filter(function(elem, pos) {
return names.indexOf(elem) == pos;
})
return 'Auto-set by ' + uniqueNames.join(', ')
return gettext('Auto-set by ') + uniqueNames.join(', ')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing semicolon.

@proteusvacuum
Copy link
Contributor

cool! does this work the same way that ugettext works? mainly wondering what the failure mode is if a translation doesn't exist in a specific language (I've had issues with js i18n libraries in the past that would spit a bunch of junk into my template if it couldn't find the right translation).

@benrudolph
Copy link
Contributor

amazing!! 😍 much needed. is there a way we can smartly pull down just the translations that we need? or will we have to pull down the entire file each time? i imagine that those files could be pretty hefty over time

@czue
Copy link
Member

czue commented Dec 15, 2015

awesome!! 🇫🇷 🇪🇸 🇮🇹

@dannyroberts
Copy link
Member

Awesome, @biyeun!! This is a huge piece in giving us the freedom to decouple our templates and JS however we want, instead of being forced to put some things in django templates just to be able to use translations! 🌟

@orangejenny
Copy link
Contributor

this is great! also, looks good to merge.

@snopoke
Copy link
Contributor

snopoke commented Dec 15, 2015

Was there a reason you chose to use this lib vs django's builtin support: https://docs.djangoproject.com/en/1.7/topics/i18n/translation/#internationalization-in-javascript-code

@biyeun
Copy link
Member Author

biyeun commented Dec 15, 2015

@snopoke this library has a management command which generates the js translation file and places it in the staticfiles directory. Django's built in support is still there for the translation part, but the way it serves the file it's generated on a per request basis, unless you cache the request.

@biyeun
Copy link
Member Author

biyeun commented Dec 15, 2015

@millerdev
Copy link
Contributor

sweetness!

@biyeun biyeun removed the Open for review: do not merge A work in progress label Dec 15, 2015
@biyeun
Copy link
Member Author

biyeun commented Dec 15, 2015

@benrudolph

is there a way we can smartly pull down just the translations that we need? or will we have to pull down the entire file each time? i imagine that those files could be pretty hefty over time

I think there is a way to, but we'd have to spin off a separate thing from statici18n. Also, once the file is loaded, the browser should cache it anyway.

@benrudolph
Copy link
Contributor

gotcha makes sense. thanks

On Tue, Dec 15, 2015 at 7:53 PM, Biyeun notifications@github.com wrote:

@benrudolph https://github.com/benrudolph

is there a way we can smartly pull down just the translations that we
need? or will we have to pull down the entire file each time? i imagine
that those files could be pretty hefty over time

I think there is a way to, but we'd have to spin off a separate thing from
statici18n. Also, once the file is loaded, the browser should cache it
anyway.


Reply to this email directly or view it on GitHub
#9576 (comment).

@benrudolph benrudolph mentioned this pull request Dec 16, 2015
benrudolph added a commit that referenced this pull request Dec 16, 2015
@benrudolph benrudolph merged commit a6efa31 into master Dec 16, 2015
@benrudolph benrudolph deleted the js-translations branch December 16, 2015 17:41
@benrudolph
Copy link
Contributor

🌏 🌍 🌎

@dannyroberts
Copy link
Member

_("Awesome")!

@czue
Copy link
Member

czue commented Dec 17, 2015

✈️ ✈️ ✈️

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.

9 participants