Skip to content

Instantly share code, notes, and snippets.

@natea
Created October 7, 2015 13:51
Show Gist options
  • Save natea/fe1297ac70936499d43a to your computer and use it in GitHub Desktop.
Save natea/fe1297ac70936499d43a to your computer and use it in GitHub Desktop.
Preview the translation on a particular site: take URL and append ?preview-lang=LC
e.g. learning.nyif.com?preview-lang=zh-cn (for chinese)
Wrap all custom text in:
${_("text")}
Handle links:
${_("blah blah blah {link_start}blah blah{link_end} blah blah").format(link_start=u"<a href='example.com'>", link_end=u"</a>")}
Error: ___ is not callable. Add:
<%! from django.utils.translation import ugettext as _ %>
to top of template (e.g. theme-footer.html)
Generating the translation files:
This is all done in devstack.
sudo su edxapp
cd /edx/app/edxapp/edx-platform
cp -r ../themes/ThemeName/templates/* lms/templates
i18n_tools extract
This will pull all of the text out of those curly braces and put them into a .po file; specifically: edx-platform/conf/locale/en/LC_MESSAGES/mako.po
You need to manually copy and paste the strings to the django.po file of whichever language you want (e.g. edx-platform/conf/locale/zh_CN/LC_MESSAGES/django.po)
run:
i18n_tools generate
which will compile the django.po into a django.mo file
(optional) check to make sure that it worked: paver devstack --fast lms
commit the .po and .mo files and clean the repo
git add conf/
git
Caveats:
don't have duplicate strings in the .po file. If you have the same string more than once, bad things will happen.
useful:
https://docs.djangoproject.com/en/1.8/topics/i18n/translation/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment