Enabling Translation - Appsembler

Enabling Translation

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_tool 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.

if you have an incorrect line, duplicate message, or some sort of syntax error, i18n_tool generate will silently ignore the django.po file and not convert it into a django.mo file

useful:

https://docs.djangoproject.com/en/1.8/topics/i18n/translation/