语言包相关问题汇总

官方的翻译指南

官方Wiki的其他文章

https://openedx.atlassian.net/wiki/spaces/PLAT/pages/161849365/Django+1.11+-+changing+zh-cn+to+zh-hans

https://openedx.atlassian.net/wiki/spaces/LOC/pages/113607033/LMS+Studio+Translation+Process

https://openedx.atlassian.net/wiki/spaces/EDUCATOR/pages/159568233/Internationalization+How-To

https://openedx.atlassian.net/wiki/spaces/OXA/pages/159985023/Why+are+my+translations+not+being+shown+for+JavaScript

1 加载edxapp环境

sudo -H -u edxapp bash
source /edx/app/edxapp/edxapp_env
cd /edx/app/edxapp/edx-platform

2 配置~/.transifexrc

[https://www.transifex.com]
hostname = https://www.transifex.com
username = user
password = pass
token =

3 可以单独下载中文语言包

tx pull -l zh_CN --all

这会覆盖conf/locale/zh_CN /LC_MESSAGES 下的内容

编辑conf/locale/zh_CN /LC_MESSAGES中的文件,进行附加翻译。完成后重新编译翻译文件

paver i18n_fastgenerate

paver i18n_fastgenerate和paver i18n_generate的区别在于,paver i18n_generate会首先paver i18n_extract然后编译,而paver i18n_fastgenerate会直接编译。

PS 在brith release里面并没有包含i18n_fastgenerate参数,所以需要编辑 pavelib/i18n.py 增加这个方法,只需把i18n_generate前面的need i18n_extract 行去掉即可。

4 一次下载多个语言

配置 conf/locale/config.yaml ,把需要的语言的注释去掉。
修改 EDXAPP_LANGUAGE_CODE 在files: https://github.com/edx/configuration/blob/master/playbooks/roles/edxapp/defaults/main.yml#L282
这是否必须??
运行

 $ paver i18n_robot_pull

如果需要下载未经审阅的,编辑/edx/app/edxapp/venvs/edxapp/src/i18n-tools/i18n/transifex.py 中的 execute('tx pull --mode=reviewed -l ' + lang)execute('tx pull -l' + lang)

*这一步在H2版没有这个文件。
5 重启edX服务,重启Nginx,清除浏览器缓存。

6 对于zh-hans,由于做了conf/locale/config.yaml中

edx_lang_map:
    zh_CN: zh_HANS

所以语言会被自动拷贝

INFO:i18n.generate:Copying mapped locale /edx/app/edxapp/edx-platform/conf/locale/zh_CN/LC_MESSAGES to /edx/app/edxapp/edx-platform/conf/locale/zh_HANS/LC_MESSAGES

7 compilejsi18n会出错

python manage.py lms --settings=devstack compilejsi18n
Traceback (most recent call last):
  File "manage.py", line 118, in <module>
    startup.run()
  File "/edx/app/edxapp/edx-platform/lms/startup.py", line 19, in run
    django.setup()
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/apps/config.py", line 94, in create
    module = import_module(entry)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named debug_toolbar

因为用的是devstack参数,改为aws重新运行

python manage.py cms compilejsi18n --settings=aws
python manage.py lms compilejsi18n --settings=aws
paver update_assets lms --settings=aws
paver update_assets cms --settings=aws

关于这个问题的帖子
https://openedx.atlassian.net/browse/CRI-128

edxapp@edustack-h2:~/edx-platform$ . ../venvs/edxapp/bin/activate

(edxapp) edxapp@edustack-h2:~/edx-platform$ pip install git+https://github.com/edx/edx-ora2.git@2.1.18

Collecting git+https://github.com/edx/edx-ora2.git@2.1.18

Cloning https://github.com/edx/edx-ora2.git (to 2.1.18) to /tmp/pip-wewWSm-build

Requirement already satisfied: defusedxml&lt;1.0.0,&gt;=0.4.1 in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from ora2==2.1.18)

Requirement already satisfied: lxml&lt;4.0.0,&gt;=3.4.4 in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from ora2==2.1.18)

Requirement already satisfied: boto&lt;3.0.0,&gt;=2.39.0 in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from ora2==2.1.18)

Requirement already satisfied: python-dateutil&lt;3.0,&gt;=2.1 in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from ora2==2.1.18)

Requirement already satisfied: bleach==1.4 in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from ora2==2.1.18)

Requirement already satisfied: loremipsum&lt;2.0.0,&gt;=1.0.5 in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from ora2==2.1.18)

Requirement already satisfied: voluptuous&lt;1.0.0,&gt;=0.10.5 in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from ora2==2.1.18)

Collecting edx-i18n-tools==0.4.6 (from ora2==2.1.18)

Downloading https://files.pythonhosted.org/packages/18/db/ef9864ec6618caf300444f4a5f58e0c63732b88c8f0ff1c0bcbdadf6992a/edx_i18n_tools-0.4.6-py2.py3-none-any.whl

Requirement already satisfied: django&lt;2.0,&gt;=1.8 in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from ora2==2.1.18)

Requirement already satisfied: python-swiftclient&lt;4.0.0,&gt;=3.1.0 in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from ora2==2.1.18)

Requirement already satisfied: lazy&lt;2.0,&gt;=1.1 in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from ora2==2.1.18)

Requirement already satisfied: django-model-utils&gt;=2.3.1 in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from ora2==2.1.18)

Requirement already satisfied: pytz in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from ora2==2.1.18)

Requirement already satisfied: libsass&lt;1.0.0,&gt;=0.10.0 in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from ora2==2.1.18)

Requirement already satisfied: path.py&lt;9.0.0,&gt;=8.2.1 in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from ora2==2.1.18)

Requirement already satisfied: jsonfield&lt;3.0.0,&gt;=2.0.2 in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from ora2==2.1.18)

Requirement already satisfied: dogapi&lt;2.0.0,&gt;=1.2.1 in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from ora2==2.1.18)

Requirement already satisfied: edx-submissions&lt;3.0.0,&gt;=2.0.12 in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from ora2==2.1.18)

Requirement already satisfied: html5lib==0.999 in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from ora2==2.1.18)

Requirement already satisfied: six&gt;=1.5 in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from python-dateutil&lt;3.0,&gt;=2.1-&gt;ora2==2.1.18)

Requirement already satisfied: pyYaml in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from edx-i18n-tools==0.4.6-&gt;ora2==2.1.18)

Requirement already satisfied: polib in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from edx-i18n-tools==0.4.6-&gt;ora2==2.1.18)

Requirement already satisfied: requests&gt;=1.1 in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from python-swiftclient&lt;4.0.0,&gt;=3.1.0-&gt;ora2==2.1.18)

Requirement already satisfied: futures&gt;=3.0; python_version == "2.7" or python_version == "2.6" in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from python-swiftclient&lt;4.0.0,&gt;=3.1.0-&gt;ora2==2.1.18)

Requirement already satisfied: setuptools in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from lazy&lt;2.0,&gt;=1.1-&gt;ora2==2.1.18)

Requirement already satisfied: simplejson&gt;=2.0.9 in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from dogapi&lt;2.0.0,&gt;=1.2.1-&gt;ora2==2.1.18)

Requirement already satisfied: decorator&gt;=3.3.2 in /edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages (from dogapi&lt;2.0.0,&gt;=1.2.1-&gt;ora2==2.1.18)

Installing collected packages: edx-i18n-tools, ora2

Found existing installation: edx-i18n-tools 0.4.5

Uninstalling edx-i18n-tools-0.4.5:

Successfully uninstalled edx-i18n-tools-0.4.5

Found existing installation: ora2 2.1.17

Uninstalling ora2-2.1.17:

Successfully uninstalled ora2-2.1.17

Running setup.py install for ora2 ... done

Successfully installed edx-i18n-tools-0.4.6 ora2-2.1.18

You are using pip version 9.0.3, however version 19.0.1 is available.

You should consider upgrading via the 'pip install --upgrade pip' command.

安装两个包来测试devstack模式

pip install django-debug-toolbar
pip install django-debug-toolbar-mongo

出现错误

RuntimeError: Model class openedx.core.djangoapps.bookmarks.models.Bookmark doesn’t declare an explicit app_label and isn’t in an application in INSTALLED_APPS.

查到https://openedx.atlassian.net/wiki/spaces/OXA/pages/921141469/Devstack+RuntimeError+Model+class+openedx.core.djangoapps.bookmarks.models.Bookmark+doesn+t+declare+an+explicit+app+label+and+isn+t+in+an+application+in+INSTALLED+APPS.

在make clean后会出现这个问题。运行

pip install -e .

8 在django admin的dark lang里增加语言选项

官方wiki的镜像
来自 https://github.com/edx/edx-platform/wiki/Internationalization-and-localization

This page is intended for site developers. For coding help, please see this page.

We are currently hosting all translations of Open edX framework on www.transifex.com. Please feel free to make translation contributions there.

You should also join the openedx-translation Google Group.

In order to run your Open edX instance under a different spoken language, for instance for Spanish (Latin American):

  1. Switch to edxapp environment:
 sudo -H -u edxapp bash
 source /edx/app/edxapp/edxapp_env
 cd /edx/app/edxapp/edx-platform
  1. Configure your ~/.transifexrc file:
 [https://www.transifex.com]
 hostname = https://www.transifex.com
 username = user
 password = pass
 token =

Token is left blank. You have to have permissions for the project (edx-platform) AFAIK - https://www.transifex.com/projects/p/edx-platform/ (it is free to sign up and join this project as a translator).For help with Transifex configuration, see the Transifex documentation: http://docs.transifex.com/developer/client/setup#configuration
3. Make sure all languages you wish to download are present and uncommented in conf/locale/config.yaml . For example, if you wish to download Arabic and Chinese (China), make sure your config.yaml file looks like this:

 locales:
     - ar  # Arabic
     - zh_CN  # Chinese (China)
  1. Configure LANGUAGE_CODE in your lms/envs/common.py . Or, for development purposes, create a dev file called dev_LANGCODE.py - eg dev_es.py - in the lms/envs directory, with the following:
 from .dev import *
 
 USE_I18N = True
 LANGUAGES = ( ('es-419', 'Spanish'), )
 TIME_ZONE = 'America/Guayaquil'
 LANGUAGE_CODE = 'es-419'

Languages need to be specified with codes Django likes, so a code that is specific on Transifex such as "de_DE" must be specified as "de-de" in these configuration files. See https://groups.google.com/forum/#!topic/openedx-translation/vrOpMKzA0kU

  1. Configure EDXAPP_LANGUAGE_CODE in your configuration files: https://github.com/edx/configuration/blob/master/playbooks/roles/edxapp/defaults/main.yml#L282
  2. Execute the following command in your edx-platform directory with your edx-platform virtualenv (Normally cd /edx/app/edxapp && source edxapp_env && cd edx-platform ). Make sure that at this point your git repository is set up, because the script will attempt to auto-commit the changes.
 $ paver i18n_robot_pull

Note that this command will pull reviewed translations for all languages that are listed in conf/locale/config.yaml . To only pull down some languages, edit conf/locale/config.yaml appropriately.

To pull unreviewed translations along with reviewed translations, edit /edx/app/edxapp/venvs/edxapp/src/i18n-tools/i18n/transifex.py . Particularly, the line execute('tx pull --mode=reviewed -l ' + lang) should be changed to execute('tx pull -l' + lang)

  1. When you launch your LMS instance you can launch it normally and things should display properly. However, if in Step 3 you created a special “dev_LANGUAGECODE” file, you’ll need to launch the LMS with the environment file explicitly stated:
 $ paver lms -s dev_es -p 8000
  1. If you experience issues:
  • Be sure your browser is set to prefer the language set in LANGUAGE_CODE
  • Note that in some cases, a language change may not be apparent because the there are no translations available. You can check that the language has been applied by checking the lang attribute of the <html> element.
  • In common/djangoapps/student/views.py , the user’s language code is tried to be obtained from a saved preferences file. So if you are having issues seeing your language served up, it may be because your User object has a different language saved as a preference. Try creating a new user in your environment, this should clear up the issue.

Releasing A Language

Setting LANGUAGE_CODE sets one language to be your installation’s default language. What if you want to support more than one language?

To “release” a second (or third, or hundredth) language, you have to configure the languages on the admin panel:

YourAwesomeDomain.com/admin/dark_lang/darklangconfig/

The LANGUAGE_CODE variable is for your server’s default language. And then to “release” a language, you have to turn them on in the dark lang config on the admin panel - do that by going to the admin url above, then adding language codes for all additional languages you wish to release in a comma separated list. For example, to release French and Chinese (China), you’d add:

    fr, zh-cn

to the dark lang config list. You don’t need to add the language code for your server’s default language, but it’s no problem if you do.

Confusing, I know. The benefit of this is that you can preview languages before you release them by appending:

    /update_lang/

to the end of the root LMS or Studio URL, and then using the form to set or reset the preview language, Example:

    127.0.0.1:8000/update_lang/    # Shows the Preview Language form with a set and reset option

Remember that language codes with underscores and capital letters need to be converted to using dashes and lower case letters on the edX platform. For example the language code of Chinese (Taiwan) is “zh_TW” on Transifex, but “zh-tw” on the edX system.

Localization Process For A Local Full Stack Installation

If you have installed the Full Stack (rather than the Developer Stack) to provide online courses to your institution, its usually not necessary to pull the translations of all languages from Transifex (in many cases translations of only one language is needed), while the pulled translation may need to be modified to meet your specific requirements. You can follow the steps here to do so:

  1. Follow the steps 1 & 2 listed on top of this document to create a ~/.transifexrc and switch to edxapp environment.
  2. If you only need to pull translations of one language, just execute the following command in your edx-platform directory with your edx-platform virtualenv:
 $ tx pull -l <lang_code>

The <lang_code> here should be replaced by the language code on Transifex of the language you want to pull (for example, zh_CN for Chinese (China) ).Note that this step will overwrite the .po files located in conf/locale/<lang_code>/LC_MESSAGES with the contents retrieved from Transifex, so please only do this step when you just have a new installation, or when you really want a new version of translation from Transifex.
3. If you’ve your own changes of edx-platform’s source code in your local installation, or the source files on Transifex is not up-to-date, you may need to extract strings manually. Just execute the following command in your edx-platform directory with your edx-platform virtualenv:

 $ paver i18n_extract

This command will extract translatable strings into several .po files located in the conf/locale/en/LC_MESSAGES . After the extraction process, you can merge the newly extracted strings into the corresponding .po files (except django.po and djangojs.po , which are generated by i18n tools automatically from other .po files) located in conf/locale/<lang_code>/LC_MESSAGES . For example:

 $ msgmerge conf/locale/zh_CN/LC_MESSAGES/djangojs-partial.po conf/locale/en/LC_MESSAGES/djangojs-partial.po --update
  1. Edit the contents of .po files located in conf/locale/<lang_code>/LC_MESSAGES as you wish. When you finished your modification process, re-compile the translation messages manually by executing the following command in your edx-platform directory with your edx-platform virtualenv:
 $ paver i18n_fastgenerate

Note that there is another command called paver i18n_generate . The difference of paver i18n_fastgenerate and paver i18n_generate is that paver i18n_generate will extract strings first by using paver i18n_extract and then compile them, while paver i18n_fastgenerate just compiles them without extracting.
5. Restart your Full Stack installation according to the commands listed in the page edX Managing the Full Stack. Note that if you want to change the default language code of a Full Stack, you can modify the value of LANGUAGE_CODE inside lms.env.json and/or the cms.env.json located in /edx/app/edxapp before starting your Full Stack.
6. You will see updated translations after the above steps. If not, you can also try to restart the nginx server and/or clear your browser’s cache.