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 27e2259 commit 65fd161
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 30 deletions.
8 changes: 0 additions & 8 deletions .tx/config

This file was deleted.

33 changes: 13 additions & 20 deletions recommender/recommender.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import bleach
from webob.response import Response
from django.utils import translation

from xblock.core import XBlock
from xblock.exceptions import JsonHandlerError
Expand Down Expand Up @@ -278,6 +277,8 @@ class RecommenderXBlock(HelperXBlock):
'url', 'title', 'description', 'descriptionText'
]

i18n_js_namespace = 'RecommenderXBlockI18N'

def _get_onetime_url(self, filename):
"""
Return one time url for uploaded screenshot
Expand Down Expand Up @@ -948,19 +949,13 @@ def _construct_view_resource(self, resource):

return result

@staticmethod
def _get_statici18n_js_url(): # 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(resource_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 i18n_service := self.runtime.service(self, "i18n"):
if url_getter_func := getattr(i18n_service, 'get_javascript_i18n_catalog_url', None):
if javascript_url := url_getter_func(self):
return javascript_url

return None

def student_view(self, _context=None): # pylint: disable=unused-argument
Expand Down Expand Up @@ -1009,9 +1004,8 @@ def student_view(self, _context=None): # pylint: disable=unused-argument
frag.add_css(self.resource_string("static/css/recommender.css"))
frag.add_css(self.resource_string("static/css/introjs.css"))
frag.add_javascript(self.resource_string("static/js/src/jquery.tooltipster.min.js"))
statici18n_js_url = self._get_statici18n_js_url()
if statici18n_js_url:
frag.add_javascript(self.resource_string(statici18n_js_url))
if statici18n_js_url := self._get_statici18n_js_url():
frag.add_javascript(statici18n_js_url)
frag.add_javascript(self.resource_string("static/js/src/cats.js"))
frag.add_javascript(self.resource_string("static/js/src/recommender.js"))
frag.initialize_js('RecommenderXBlock', self.get_client_configuration())
Expand All @@ -1029,9 +1023,8 @@ def studio_view(self, _context=None): # pylint: disable=unused-argument
))
frag.add_css(load("static/css/recommenderstudio.css"))
frag.add_javascript_url("//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js")
statici18n_js_url = self._get_statici18n_js_url()
if statici18n_js_url:
frag.add_javascript(self.resource_string(statici18n_js_url))
if statici18n_js_url := self._get_statici18n_js_url():
frag.add_javascript(statici18n_js_url)
frag.add_javascript(load("static/js/src/recommenderstudio.js"))
frag.initialize_js('RecommenderXBlock')
return frag
Expand Down
4 changes: 2 additions & 2 deletions translation_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
from __future__ import absolute_import
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
BASE_DIR = os.path.dirname(__file__)


# Quick-start development settings - unsuitable for production
Expand Down Expand Up @@ -81,7 +81,7 @@
('zh_CN', 'Chinese (China)'),
]

LOCALE_PATHS = [os.path.join(BASE_DIR, "locale")]
LOCALE_PATHS = [os.path.join(BASE_DIR, "recommender", "conf", "locale")]

STATICI18N_DOMAIN = 'text'
STATICI18N_NAMESPACE = 'RecommenderXBlockI18N'
Expand Down

0 comments on commit 65fd161

Please sign in to comment.