mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 12:35:46 +00:00
[React] UI Translation Updates (#6257)
* Move locales definition into separate file - Cleanup settings.py a bit * Update docstring * Expose 'default_locale' to info API endpoint * Validate settings.LANGUAGE_CODE * Fix bug in BuildDetail page * Use selected language when making API queries * Translate more strings * Tweak variable name * Update locale config * Remove duplicate code * Remove compiled messages.ts translation files * Fixes for LanguageContext.tsx * Update messages.d.ts for sr locale * Ensure compiled files are served by django runserver * Amend changes to STATICFILES_DIRS * Cleanup prerender.py * Refetch status codes when locale is changed * Fix log msg * Clear out old static files
This commit is contained in:
@ -125,6 +125,7 @@ class InfoView(AjaxView):
|
||||
'platform': InvenTree.version.inventreePlatform() if is_staff else None,
|
||||
'installer': InvenTree.version.inventreeInstaller() if is_staff else None,
|
||||
'target': InvenTree.version.inventreeTarget() if is_staff else None,
|
||||
'default_locale': settings.LANGUAGE_CODE,
|
||||
}
|
||||
|
||||
return JsonResponse(data)
|
||||
|
47
InvenTree/InvenTree/locales.py
Normal file
47
InvenTree/InvenTree/locales.py
Normal file
@ -0,0 +1,47 @@
|
||||
"""Support translation locales for InvenTree.
|
||||
|
||||
If a new language translation is supported, it must be added here
|
||||
After adding a new language, run the following command:
|
||||
python manage.py makemessages -l <language_code> -e html,js,py --no-wrap
|
||||
where <language_code> is the code for the new language
|
||||
Additionally, update the following files with the new locale code:
|
||||
|
||||
- /src/frontend/.linguirc file
|
||||
- /src/frontend/src/context/LanguageContext.tsx
|
||||
"""
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
LOCALES = [
|
||||
('bg', _('Bulgarian')),
|
||||
('cs', _('Czech')),
|
||||
('da', _('Danish')),
|
||||
('de', _('German')),
|
||||
('el', _('Greek')),
|
||||
('en', _('English')),
|
||||
('es', _('Spanish')),
|
||||
('es-mx', _('Spanish (Mexican)')),
|
||||
('fa', _('Farsi / Persian')),
|
||||
('fi', _('Finnish')),
|
||||
('fr', _('French')),
|
||||
('he', _('Hebrew')),
|
||||
('hi', _('Hindi')),
|
||||
('hu', _('Hungarian')),
|
||||
('it', _('Italian')),
|
||||
('ja', _('Japanese')),
|
||||
('ko', _('Korean')),
|
||||
('nl', _('Dutch')),
|
||||
('no', _('Norwegian')),
|
||||
('pl', _('Polish')),
|
||||
('pt', _('Portuguese')),
|
||||
('pt-br', _('Portuguese (Brazilian)')),
|
||||
('ru', _('Russian')),
|
||||
('sl', _('Slovenian')),
|
||||
('sr', _('Serbian')),
|
||||
('sv', _('Swedish')),
|
||||
('th', _('Thai')),
|
||||
('tr', _('Turkish')),
|
||||
('vi', _('Vietnamese')),
|
||||
('zh-hans', _('Chinese (Simplified)')),
|
||||
('zh-hant', _('Chinese (Traditional)')),
|
||||
]
|
@ -58,10 +58,9 @@ class Command(BaseCommand):
|
||||
for file in os.listdir(SOURCE_DIR):
|
||||
path = os.path.join(SOURCE_DIR, file)
|
||||
if os.path.exists(path) and os.path.isfile(path):
|
||||
print(f'render {file}')
|
||||
render_file(file, SOURCE_DIR, TARGET_DIR, locales, ctx)
|
||||
else:
|
||||
raise NotImplementedError(
|
||||
'Using multi-level directories is not implemented at this point'
|
||||
) # TODO multilevel dir if needed
|
||||
print(f'rendered all files in {SOURCE_DIR}')
|
||||
print(f'Rendered all files in {SOURCE_DIR}')
|
||||
|
@ -28,7 +28,7 @@ from InvenTree.config import get_boolean_setting, get_custom_file, get_setting
|
||||
from InvenTree.sentry import default_sentry_dsn, init_sentry
|
||||
from InvenTree.version import checkMinPythonVersion, inventreeApiVersion
|
||||
|
||||
from . import config
|
||||
from . import config, locales
|
||||
|
||||
checkMinPythonVersion()
|
||||
|
||||
@ -160,6 +160,10 @@ STATICFILES_I18_TRG = BASE_DIR.joinpath('InvenTree', 'static_i18n')
|
||||
STATICFILES_DIRS.append(STATICFILES_I18_TRG)
|
||||
STATICFILES_I18_TRG = STATICFILES_I18_TRG.joinpath(STATICFILES_I18_PREFIX)
|
||||
|
||||
# Append directory for compiled react files if debug server is running
|
||||
if DEBUG and 'collectstatic' not in sys.argv:
|
||||
STATICFILES_DIRS.append(BASE_DIR.joinpath('web', 'static'))
|
||||
|
||||
STATFILES_I18_PROCESSORS = ['InvenTree.context.status_codes']
|
||||
|
||||
# Color Themes Directory
|
||||
@ -822,52 +826,26 @@ if type(EXTRA_URL_SCHEMES) not in [list]: # pragma: no cover
|
||||
logger.warning('extra_url_schemes not correctly formatted')
|
||||
EXTRA_URL_SCHEMES = []
|
||||
|
||||
LANGUAGES = locales.LOCALES
|
||||
|
||||
LOCALE_CODES = [lang[0] for lang in LANGUAGES]
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/dev/topics/i18n/
|
||||
LANGUAGE_CODE = get_setting('INVENTREE_LANGUAGE', 'language', 'en-us')
|
||||
|
||||
if (
|
||||
LANGUAGE_CODE not in LOCALE_CODES
|
||||
and LANGUAGE_CODE.split('-')[0] not in LOCALE_CODES
|
||||
): # pragma: no cover
|
||||
logger.warning(
|
||||
'Language code %s not supported - defaulting to en-us', LANGUAGE_CODE
|
||||
)
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
# Store language settings for 30 days
|
||||
LANGUAGE_COOKIE_AGE = 2592000
|
||||
|
||||
# If a new language translation is supported, it must be added here
|
||||
# After adding a new language, run the following command:
|
||||
# python manage.py makemessages -l <language_code> -e html,js,py --no-wrap
|
||||
# where <language_code> is the code for the new language
|
||||
# Additionally, update the /src/frontend/.linguirc file
|
||||
LANGUAGES = [
|
||||
('bg', _('Bulgarian')),
|
||||
('cs', _('Czech')),
|
||||
('da', _('Danish')),
|
||||
('de', _('German')),
|
||||
('el', _('Greek')),
|
||||
('en', _('English')),
|
||||
('es', _('Spanish')),
|
||||
('es-mx', _('Spanish (Mexican)')),
|
||||
('fa', _('Farsi / Persian')),
|
||||
('fi', _('Finnish')),
|
||||
('fr', _('French')),
|
||||
('he', _('Hebrew')),
|
||||
('hi', _('Hindi')),
|
||||
('hu', _('Hungarian')),
|
||||
('it', _('Italian')),
|
||||
('ja', _('Japanese')),
|
||||
('ko', _('Korean')),
|
||||
('nl', _('Dutch')),
|
||||
('no', _('Norwegian')),
|
||||
('pl', _('Polish')),
|
||||
('pt', _('Portuguese')),
|
||||
('pt-br', _('Portuguese (Brazilian)')),
|
||||
('ru', _('Russian')),
|
||||
('sl', _('Slovenian')),
|
||||
('sr', _('Serbian')),
|
||||
('sv', _('Swedish')),
|
||||
('th', _('Thai')),
|
||||
('tr', _('Turkish')),
|
||||
('vi', _('Vietnamese')),
|
||||
('zh-hans', _('Chinese (Simplified)')),
|
||||
('zh-hant', _('Chinese (Traditional)')),
|
||||
]
|
||||
|
||||
|
||||
# Testing interface translations
|
||||
if get_boolean_setting('TEST_TRANSLATIONS', default_value=False): # pragma: no cover
|
||||
# Set default language
|
||||
|
Reference in New Issue
Block a user