Skip to content

Commit

Permalink
feat!: remove Transifex calls for FC-0012 - OEP-58
Browse files Browse the repository at this point in the history
  • Loading branch information
shadinaif authored and OmarIthawi committed Mar 17, 2024
1 parent 516d289 commit 1911529
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 52 deletions.
9 changes: 0 additions & 9 deletions .tx/config

This file was deleted.

8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ Please See the `releases tab <https://github.com/openedx/xblock-lti-consumer/rel

Unreleased
~~~~~~~~~~
* Remove Transifex calls and bundled translation files for the OEP-58 proposal.

BREAKING CHANGE: This version breaks translations with Quince and earlier releases.

9.9.0 (2024-01-24)
---------------------------
* XBlockI18NService js translations support

9.8.3 - 2024-01-23
------------------
* Additional NewRelic traces to functions suspected of causing performance issues.
Expand Down
11 changes: 0 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,6 @@ This list is what is used to resolve dependencies when an upstream project is co
this XBlock package. requirements.txt is used to install the same dependencies when running
the tests for this package.

Downloading translations from Transifex
---------------------------------------

If you want to download translations from Transifex install
`transifex client <https://docs.transifex.com/client/installing-the-client/>`_ and run this command while
inside project root directory:

.. code:: bash
$ tx pull -f --mode=reviewed
Further Development Info
------------------------

Expand Down
2 changes: 1 addition & 1 deletion lti_consumer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
from .apps import LTIConsumerApp
from .lti_xblock import LtiConsumerXBlock

__version__ = '9.8.3'
__version__ = '9.9.0'
11 changes: 0 additions & 11 deletions lti_consumer/conf/locale/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@

locales:
- en # English - Source Language
- ar # Arabic
- es_419 # Spanish (Latin America)
- fr # French
- he # Hebrew
- hi # Hindi
- ja_JP # Japanese (Japan)
- ko_KR # Korean (Korea)
- pt_BR # Portuguese (Brazil)
- pt_PT # Portuguese (Portugal)
- ru # Russian
- zh_CN # Chinese (China)

# Directories we don't search for strings.
ignore_dirs:
Expand Down
44 changes: 24 additions & 20 deletions lti_consumer/lti_xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@
import urllib.parse
from collections import namedtuple
from importlib import import_module
import pkg_resources

import bleach
from django.conf import settings
from django.utils import timezone, translation
from django.utils import timezone
from web_fragments.fragment import Fragment

from webob import Response
Expand Down Expand Up @@ -87,6 +86,7 @@
external_user_id_1p1_launches_enabled,
database_config_enabled,
EXTERNAL_ID_REGEX,
DummyTranslationService,
)

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -257,6 +257,7 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
"""

block_settings_key = 'lti_consumer'
i18n_js_namespace = 'XBlockLtiConsumerI18N'

display_name = String(
display_name=_("Display Name"),
Expand Down Expand Up @@ -662,20 +663,14 @@ def workbench_scenarios():
]
return scenarios

@staticmethod
def _get_statici18n_js_url(loader): # pragma: no cover
"""
Returns the Javascript translation file for the currently selected language, if any found by
`pkg_resources`
"""
lang_code = translation.get_language()
if not lang_code:
return None
text_js = 'public/js/translations/{lang_code}/text.js'
country_code = lang_code.split('-')[0]
for code in (translation.to_locale(lang_code), lang_code, country_code):
if pkg_resources.resource_exists(loader.module_name, text_js.format(lang_code=code)):
return text_js.format(lang_code=code)
def _get_statici18n_js_url(self):
"""
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

return None

def validate_field_data(self, validation, data):
Expand Down Expand Up @@ -776,6 +771,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):
"""
Expand Down Expand Up @@ -1197,9 +1201,9 @@ def author_view(self, context):
)
fragment.add_css(loader.load_unicode('static/css/student.css'))
fragment.add_javascript(loader.load_unicode('static/js/xblock_lti_consumer.js'))
statici18n_js_url = self._get_statici18n_js_url(loader)
statici18n_js_url = self._get_statici18n_js_url()
if statici18n_js_url:
fragment.add_javascript_url(self.runtime.local_resource_url(self, statici18n_js_url))
fragment.add_javascript_url(statici18n_js_url)

Check warning on line 1206 in lti_consumer/lti_xblock.py

View check run for this annotation

Codecov / codecov/patch

lti_consumer/lti_xblock.py#L1206

Added line #L1206 was not covered by tests
fragment.initialize_js('LtiConsumerXBlock')
return fragment

Expand All @@ -1224,9 +1228,9 @@ def student_view(self, context):
fragment.add_content(loader.render_mako_template('/templates/html/student.html', context))
fragment.add_css(loader.load_unicode('static/css/student.css'))
fragment.add_javascript(loader.load_unicode('static/js/xblock_lti_consumer.js'))
statici18n_js_url = self._get_statici18n_js_url(loader)
statici18n_js_url = self._get_statici18n_js_url()
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

Expand Down
16 changes: 16 additions & 0 deletions lti_consumer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ def _(text):
return text


def ngettext_fallback(text_singular, text_plural, number):
""" Dummy `ngettext` replacement to make string extraction tools scrape strings marked for translation """
if number == 1:
return text_singular

Check warning on line 37 in lti_consumer/utils.py

View check run for this annotation

Codecov / codecov/patch

lti_consumer/utils.py#L36-L37

Added lines #L36 - L37 were not covered by tests
else:
return text_plural

Check warning on line 39 in lti_consumer/utils.py

View check run for this annotation

Codecov / codecov/patch

lti_consumer/utils.py#L39

Added line #L39 was not covered by tests


def get_lti_api_base():
"""
Returns base url to be used as issuer on OAuth2 flows
Expand Down Expand Up @@ -361,3 +369,11 @@ def model_to_dict(model_object, exclude=None):
return object_fields
except (AttributeError, TypeError):
return {}


class DummyTranslationService:
"""
Dummy drop-in replacement for i18n XBlock service
"""
gettext = _
ngettext = ngettext_fallback

0 comments on commit 1911529

Please sign in to comment.