-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: use XBlockI18NService js translations | FC-0012 #441
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 | ||||
---|---|---|---|---|---|---|
|
@@ -87,6 +87,7 @@ | |||||
external_user_id_1p1_launches_enabled, | ||||||
database_config_enabled, | ||||||
EXTERNAL_ID_REGEX, | ||||||
DummyTranslationService, | ||||||
) | ||||||
|
||||||
log = logging.getLogger(__name__) | ||||||
|
@@ -257,6 +258,7 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock): | |||||
""" | ||||||
|
||||||
block_settings_key = 'lti_consumer' | ||||||
i18n_js_namespace = 'LtiI18N' | ||||||
|
||||||
display_name = String( | ||||||
display_name=_("Display Name"), | ||||||
|
@@ -663,10 +665,13 @@ def workbench_scenarios(): | |||||
return scenarios | ||||||
|
||||||
@staticmethod | ||||||
def _get_statici18n_js_url(loader): # pragma: no cover | ||||||
def _get_deprecated_i18n_js_url(loader): | ||||||
""" | ||||||
Returns the Javascript translation file for the currently selected language, if any found by | ||||||
Returns the deprecated JavaScript translation file for the currently selected language, if any found by | ||||||
`pkg_resources` | ||||||
|
||||||
This method returns pre-OEP-58 i18n files and is deprecated in favor | ||||||
of `get_javascript_i18n_catalog_url`. | ||||||
""" | ||||||
lang_code = translation.get_language() | ||||||
if not lang_code: | ||||||
|
@@ -678,10 +683,23 @@ def _get_statici18n_js_url(loader): # pragma: no cover | |||||
return text_js.format(lang_code=code) | ||||||
return None | ||||||
|
||||||
def _get_statici18n_js_url(self, loader): | ||||||
""" | ||||||
Return the JavaScript translation file provided by the XBlockI18NService. | ||||||
""" | ||||||
if url_getter_func := getattr(self.i18n_service, 'get_javascript_i18n_catalog_url', None): | ||||||
if javascript_url := url_getter_func(self): | ||||||
return javascript_url | ||||||
|
||||||
if deprecated_url := self._get_deprecated_i18n_js_url(loader): | ||||||
return self.runtime.local_resource_url(self, deprecated_url) | ||||||
|
||||||
return None | ||||||
|
||||||
def validate_field_data(self, validation, data): | ||||||
# Validate custom parameters is a list. | ||||||
if not isinstance(data.custom_parameters, list): | ||||||
_ = self.runtime.service(self, "i18n").ugettext | ||||||
_ = self.runtime.service(self, 'i18n').ugettext | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need
Suggested change
|
||||||
validation.add(ValidationMessage(ValidationMessage.ERROR, str( | ||||||
_("Custom Parameters must be a list") | ||||||
))) | ||||||
|
@@ -776,6 +794,15 @@ def get_pii_sharing_enabled(self): | |||||
# because the service is not defined in those contexts. | ||||||
return True | ||||||
|
||||||
@property | ||||||
def i18n_service(self): | ||||||
""" Obtains translation service """ | ||||||
i18n_service = self.runtime.service(self, "i18n") | ||||||
if i18n_service: | ||||||
return i18n_service | ||||||
else: | ||||||
return DummyTranslationService() | ||||||
|
||||||
@property | ||||||
def editable_fields(self): | ||||||
""" | ||||||
|
@@ -1226,7 +1253,7 @@ def student_view(self, context): | |||||
fragment.add_javascript(loader.load_unicode('static/js/xblock_lti_consumer.js')) | ||||||
statici18n_js_url = self._get_statici18n_js_url(loader) | ||||||
if statici18n_js_url: | ||||||
fragment.add_javascript_url(self.runtime.local_resource_url(self, statici18n_js_url)) | ||||||
fragment.add_javascript_url(statici18n_js_url) | ||||||
fragment.initialize_js('LtiConsumerXBlock') | ||||||
return fragment | ||||||
|
||||||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the make file already uses a name, please change this one