mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Translation Fixes (#4433)
* Change 'zh-cn' to 'zh-hans' * Enforce consistent naming scheme when rendering translated javascript files * More intelligent lookup of translated javascript files - Ensure that the language code is lower-case (to match translated files) - Provide fallback if specified langauge code is not found * Replace underscore characters * remove debug hook
This commit is contained in:
parent
fdfc3e5e7e
commit
ec66e5351b
@ -12,8 +12,15 @@ from django.utils.translation import override as lang_over
|
|||||||
|
|
||||||
def render_file(file_name, source, target, locales, ctx):
|
def render_file(file_name, source, target, locales, ctx):
|
||||||
"""Renders a file into all provided locales."""
|
"""Renders a file into all provided locales."""
|
||||||
|
|
||||||
for locale in locales:
|
for locale in locales:
|
||||||
|
|
||||||
|
# Enforce lower-case for locale names
|
||||||
|
locale = locale.lower()
|
||||||
|
locale = locale.replace('_', '-')
|
||||||
|
|
||||||
target_file = os.path.join(target, locale + '.' + file_name)
|
target_file = os.path.join(target, locale + '.' + file_name)
|
||||||
|
|
||||||
with open(target_file, 'w') as localised_file:
|
with open(target_file, 'w') as localised_file:
|
||||||
with lang_over(locale):
|
with lang_over(locale):
|
||||||
renderd = render_to_string(os.path.join(source, file_name), ctx)
|
renderd = render_to_string(os.path.join(source, file_name), ctx)
|
||||||
|
@ -718,7 +718,7 @@ LANGUAGES = [
|
|||||||
('th', _('Thai')),
|
('th', _('Thai')),
|
||||||
('tr', _('Turkish')),
|
('tr', _('Turkish')),
|
||||||
('vi', _('Vietnamese')),
|
('vi', _('Vietnamese')),
|
||||||
('zh-cn', _('Chinese')),
|
('zh-hans', _('Chinese')),
|
||||||
]
|
]
|
||||||
|
|
||||||
# Testing interface translations
|
# Testing interface translations
|
||||||
|
@ -2,7 +2,7 @@ msgid ""
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: inventree\n"
|
"Project-Id-Version: inventree\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2023-02-28 21:17+0000\n"
|
"POT-Creation-Date: 2023-03-01 10:01+0000\n"
|
||||||
"PO-Revision-Date: 2023-02-28 22:38\n"
|
"PO-Revision-Date: 2023-02-28 22:38\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: Chinese Simplified\n"
|
"Language-Team: Chinese Simplified\n"
|
||||||
@ -11550,7 +11550,8 @@ msgstr ""
|
|||||||
|
|
||||||
#: templates/socialaccount/signup.html:10
|
#: templates/socialaccount/signup.html:10
|
||||||
#, python-format
|
#, python-format
|
||||||
msgid "You are about to use your %(provider_name)s account to login to\n"
|
msgid ""
|
||||||
|
"You are about to use your %(provider_name)s account to login to\n"
|
||||||
"%(site_name)s.<br>As a final step, please complete the following form:"
|
"%(site_name)s.<br>As a final step, please complete the following form:"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
@ -11737,4 +11738,3 @@ msgstr "编辑项目权限"
|
|||||||
#: users/models.py:231
|
#: users/models.py:231
|
||||||
msgid "Permission to delete items"
|
msgid "Permission to delete items"
|
||||||
msgstr "删除项目权限"
|
msgstr "删除项目权限"
|
||||||
|
|
@ -570,7 +570,30 @@ class I18nStaticNode(StaticNode):
|
|||||||
self.original = self.path.var
|
self.original = self.path.var
|
||||||
|
|
||||||
if hasattr(context, 'request'):
|
if hasattr(context, 'request'):
|
||||||
self.path.var = self.original.format(lng=context.request.LANGUAGE_CODE)
|
|
||||||
|
# Convert the "requested" language code to a standard format
|
||||||
|
language_code = context.request.LANGUAGE_CODE.lower().strip()
|
||||||
|
language_code = language_code.replace('_', '-')
|
||||||
|
|
||||||
|
# Find the first "best" match:
|
||||||
|
# - First, try the original requested code, e.g. 'pt-br'
|
||||||
|
# - Next, try a simpler version of the code e.g. 'pt'
|
||||||
|
# - Finally, fall back to english
|
||||||
|
options = [
|
||||||
|
language_code,
|
||||||
|
language_code.split('-')[0],
|
||||||
|
'en',
|
||||||
|
]
|
||||||
|
|
||||||
|
for lng in options:
|
||||||
|
lng_file = os.path.join(
|
||||||
|
djangosettings.STATIC_ROOT,
|
||||||
|
self.original.format(lng=lng)
|
||||||
|
)
|
||||||
|
|
||||||
|
if os.path.exists(lng_file):
|
||||||
|
self.path.var = self.original.format(lng=lng)
|
||||||
|
break
|
||||||
|
|
||||||
ret = super().render(context)
|
ret = super().render(context)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user