-
Notifications
You must be signed in to change notification settings - Fork 288
DocsDevLangMapper
Language mappings are configured per project using the pootle.core.lang_mappers
key on the
project config, which should be a dictionary of upstream_code
to pootle_code
mappings.
Named presets can also be configured site-wide with the key pootle.core.lang_mapping_presets
.
Presets can be used by a Project
by setting pootle.core.use_lang_mapping_presets
on the
Project
configuration, with a list containing the name of the preset. Project
configuration
will always override any settings in presets.
Mappings are 1 to 1, and you cannot have 2 upstream codes the same.
>>> from pootle_project.models import Project
>>> from pootle.core.delegate import lang_mapper
>>> project = Project.objects.get(code="tutorial")
>>> mapper = lang_mapper.get(Project, instance=project)
There are no custom configs set up so the lang mapper will map pootle_code <> upstream_code exactly. It can also be used as a dict to retrieve langs for a give upstream_code if they exist
>>> mapper.get_pootle_code("en")
"en"
>>> mapper.get_upstream_code("en")
"en"
>>> mapper["en"]
<Language english />
You can add a custom configuration for the project to map a lang to specific upstream code
>>> mapper["en_FOO"] is None
True
>>> from pootle_config utils import ObjectConfig
>>> conf = ObjectConfig(project)
>>> conf["pootle.core.lang_mappings"] = dict(en_FOO="en")
The mapper caches mapping so we need to get a fresh copy after changing config
>>> mapper = lang_mapper.get(Project, instance=project)
>>> mapper["en_FOO"]
<Language english />
>>> mapper.get_upstream_code("en")
"en_FOO"
>>> mapper.get_pootle_code("en_FOO")
"en"