-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33922 from Zeit-Labs/plugins-i18n
feat: atlas pull plugins translation | FC-0012
- Loading branch information
Showing
14 changed files
with
308 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
19 changes: 19 additions & 0 deletions
19
openedx/core/djangoapps/plugins/management/commands/compile_plugin_translations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
""" | ||
Compile the translation files for the edx_django_utils.plugins. | ||
""" | ||
|
||
from django.core.management.base import BaseCommand | ||
from django.conf import settings | ||
|
||
|
||
from ...constants import plugins_locale_root | ||
|
||
from ... import i18n_api | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
Compile the translation files for the edx_django_utils.plugins. | ||
""" | ||
def handle(self, *args, **options): | ||
i18n_api.compile_po_files(settings.REPO_ROOT / plugins_locale_root) |
36 changes: 36 additions & 0 deletions
36
openedx/core/djangoapps/plugins/management/commands/pull_plugin_translations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
Download the translations via atlas for the edx-platform plugins (edx_django_utils.plugins). | ||
For the XBlock command check the `pull_xblock_translations` command. | ||
""" | ||
|
||
from django.conf import settings | ||
|
||
from openedx.core.djangoapps.plugins.i18n_api import BaseAtlasPullCommand | ||
|
||
from ...constants import plugins_locale_root | ||
|
||
from ...i18n_api import ( | ||
plugin_translations_atlas_pull, | ||
) | ||
|
||
|
||
class Command(BaseAtlasPullCommand): | ||
""" | ||
Pull the edx_django_utils.plugins translations via atlas. | ||
For detailed information about atlas pull options check the atlas documentation: | ||
- https://github.com/openedx/openedx-atlas | ||
""" | ||
|
||
def handle(self, *args, **options): | ||
plugin_translations_root = settings.REPO_ROOT / plugins_locale_root | ||
self.ensure_empty_directory(plugin_translations_root) | ||
|
||
atlas_pull_options = self.get_atlas_pull_options(**options) | ||
|
||
plugin_translations_atlas_pull( | ||
pull_options=atlas_pull_options, | ||
locale_root=plugin_translations_root, | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
""" | ||
Production environment variables for `edx_django_utils.plugins` plugins. | ||
""" | ||
|
||
from ..constants import plugins_locale_root | ||
|
||
|
||
def plugin_settings(settings): | ||
""" | ||
Settings for the `edx_django_utils.plugins` plugins. | ||
""" | ||
locale_root = settings.REPO_ROOT / plugins_locale_root | ||
if locale_root.isdir(): | ||
for plugin_locale in locale_root.listdir(): | ||
# Add the plugin locale directory only if it's a non-empty directory | ||
if plugin_locale.isdir() and plugin_locale.listdir(): | ||
settings.LOCALE_PATHS.append(plugin_locale) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
""" | ||
Tests for the plugins.i18n_api Django commands module. | ||
""" | ||
from unittest.mock import patch | ||
|
||
from django.core.management import call_command | ||
|
||
|
||
def test_pull_plugin_translations_command(settings, tmp_path): | ||
""" | ||
Test the `pull_plugin_translations` Django command. | ||
""" | ||
plugins_locale_root = tmp_path / 'conf/plugins-locale/plugins' | ||
plugins_locale_root.mkdir(parents=True) | ||
settings.REPO_ROOT = tmp_path | ||
|
||
with patch('subprocess.run') as mock_run: | ||
call_command( | ||
'pull_plugin_translations', | ||
verbose=True, | ||
filter='ar,es_ES', | ||
repository='custom_repo', | ||
) | ||
|
||
assert mock_run.call_count == 1, 'Expected to call `subprocess.run` once' | ||
call_kwargs = mock_run.call_args.kwargs | ||
|
||
assert call_kwargs['check'] is True | ||
assert call_kwargs['cwd'] == plugins_locale_root | ||
assert call_kwargs['args'][:8] == [ | ||
'atlas', 'pull', '--expand-glob', | ||
'--filter', 'ar,es_ES', | ||
'--repository', 'custom_repo', | ||
'--verbose' | ||
], 'Pass arguments to atlas pull correctly' | ||
|
||
assert 'translations/*/edx_proctoring/conf/locale:edx_proctoring' in call_kwargs['args'], ( | ||
'Pull edx-proctoring translations by Python module name using the "--expand-glob" option' | ||
) | ||
|
||
|
||
def test_compile_plugin_translations_command(settings): | ||
""" | ||
Test the `compile_plugin_translations` Django command. | ||
""" | ||
with patch('openedx.core.djangoapps.plugins.i18n_api.compile_po_files') as mock_compile_po_files: | ||
call_command('compile_plugin_translations') | ||
|
||
mock_compile_po_files.assert_called_once_with(settings.REPO_ROOT / 'conf/plugins-locale/plugins') |
Oops, something went wrong.