Skip to content

Commit

Permalink
Merge pull request #88 from appsembler/omar/fallback-to-gettext
Browse files Browse the repository at this point in the history
Fallback to gettext if amc admin did not provide translations
  • Loading branch information
OmarIthawi authored Aug 7, 2019
2 parents 6523a73 + 7e8e163 commit 05ba3b5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
<%namespace file='/theme-variables.html' import="translate" />

<%!
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_lazy as _
%>

<%page args="template_settings, course_vars" />

<%
course_image = course_vars['course_image']

courseware_button_already_enrolled_text = translate(template_settings.get('courseware-button-already-enrolled-text', _("You are enrolled in this course")))
courseware_button_view_courseware_text = translate(template_settings.get('courseware-button-view-courseware-text', _("View Course")))
courseware_button_in_cart_text = translate(template_settings.get('courseware-button-in-cart-text', _("Course is in your cart.")))
courseware_button_course_full_text = translate(template_settings.get('courseware-button-course-full-text', _("Course is full")))
courseware_button_invitation_only_text = translate(template_settings.get('courseware-button-invitation-only-text', _("Enrollment in this course is by invitation only")))
courseware_button_enrollment_closed_text = translate(template_settings.get('courseware-button-enrollment-closed-text', _("Enrollment is Closed")))
courseware_button_add_to_cart_text = u"{text} {price}".format(text=translate(template_settings.get('courseware-button-add-to-cart-text', _("Add to Cart / Price: "))), price=course_vars['course_price'])
courseware_button_enroll_text = u"{text} {price}".format(text=translate(template_settings.get('courseware-button-enroll-text', _("Enroll in "))), price=course_vars['course_name'])
view_in_studio_button_text = translate(template_settings.get('view-in-studio-button-text', _("View About Page in studio")))
courseware_button_already_enrolled_text = translate(template_settings.get('courseware-button-already-enrolled-text'), default=_("You are enrolled in this course"))
courseware_button_view_courseware_text = translate(template_settings.get('courseware-button-view-courseware-text'), default=_("View Course"))
courseware_button_in_cart_text = translate(template_settings.get('courseware-button-in-cart-text'), default=_("Course is in your cart."))
courseware_button_course_full_text = translate(template_settings.get('courseware-button-course-full-text'), default=_("Course is full"))
courseware_button_invitation_only_text = translate(template_settings.get('courseware-button-invitation-only-text'), default=_("Enrollment in this course is by invitation only"))
courseware_button_enrollment_closed_text = translate(template_settings.get('courseware-button-enrollment-closed-text'), default=_("Enrollment is Closed"))
courseware_button_add_to_cart_text = u"{text} {price}".format(text=translate(template_settings.get('courseware-button-add-to-cart-text'), default=_("Add to Cart / Price: ")), price=course_vars['course_price'])
courseware_button_enroll_text = u"{text} {price}".format(text=translate(template_settings.get('courseware-button-enroll-text'), default=_("Enroll in ")), price=course_vars['course_name'])
view_in_studio_button_text = translate(template_settings.get('view-in-studio-button-text'), default=_("View About Page in studio"))
%>

<section class="a--course-about-01__header">
Expand Down
52 changes: 35 additions & 17 deletions lms/templates/theme-variables.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,32 @@
<%! from django.contrib.staticfiles.templatetags.staticfiles import static %>
<%! from django.utils.encoding import force_text %>
<%! from django.utils import translation %>
<%! from django.utils.translation import ugettext as _ %>
<%! from django.utils.translation import ugettext, ugettext_lazy as _ %>
<%! from django.utils import six %>
<%! from django.utils.functional import lazy %>
<%! from datetime import date %>


<%!
theme_name = "edx-theme-codebase"

def _translate(translations_object, default=''):
current_language = translation.get_language()
fallback_language = get_value('LANGUAGE_CODE', 'en')

if not translations_object:
return default

if not isinstance(translations_object, dict):
translations_object = {fallback_language: translations_object}

default_text = default if default else force_text(translations_object.get(fallback_language, ''))
return force_text(translations_object.get(current_language)) or default_text
%>


<%def name="translate(translations_object)"><%
if isinstance(translations_object, dict):
current_language = translation.get_language()
language_code = get_value('LANGUAGE_CODE', 'en')
return force_text(translations_object.get(current_language, translations_object.get(language_code, '')))
else:
return force_text(translations_object)
endif
<%def name="translate(translations_object, default='')"><%
return _translate(translations_object, default)
%></%def>


Expand Down Expand Up @@ -130,11 +139,20 @@
<%def name="get_footer_settings()">
<%
footer_options = get_current_site_configuration().page_elements.get('footer', {}).get('options', {})

def _default_copy_right():
return ugettext('{copy_sign} {year} Company Name. All rights reserved.').format(
copy_sign='©',
year=date.today().strftime('%Y'),
)

default_copy_right = lazy(_default_copy_right, six.text_type)

return {
'footer_logo' : get_brand_logos()['icon_black'], ## leave as is, defined above. Can be changed to something custom if needed.
'footer_copyright_text' : translate(footer_options.get('footer_copyright_text', '©' + date.today().strftime('%Y') + ' Company Name. All rights reserved.')), ## leave value empty if you don't want it displayed.
'footer_copyright_text' : translate(footer_options.get('footer_copyright_text'), default=default_copyright()),
'display_edx_disclaimer' : footer_options.get('display_edx_disclaimer', True), ## bool value required
'edx_disclaimer' : translate(footer_options.get('edx_disclaimer', 'edX, Open edX and the edX and Open edX logos are trademarks or registered trademarks of edX Inc.')), ## leave value empty if you don't want it displayed.
'edx_disclaimer' : translate(footer_options.get('edx_disclaimer'), default=_('edX, Open edX and the edX and Open edX logos are trademarks or registered trademarks of edX Inc.')),
'display_poweredby' : footer_options.get('display_poweredby', True), ## bool value required
'display_app_link' : footer_options.get('display_app_link', False),
'app_url' : footer_options.get('app_url', '')
Expand Down Expand Up @@ -333,15 +351,15 @@
'header_logo_width': get_value('certificates', {}).get('header_logo_width', '240px'),
'cert_logo': get_value('certificates', {}).get('cert_logo', get_value('logo_positive', static('images/branding/brand-logo.svg'))),
'logo_width': get_value('certificates', {}).get('cert_logo_width', '160px'),
'platform_name': translate(get_value('certificates', {}).get('platform_name', get_value('PLATFORM_NAME', 'Platform Name'))),
'header_text': translate(get_value('certificates', {}).get('header_text', 'Congratulations! This page summarizes what you accomplished. Show it off to family, friends, and colleagues in your social and professional networks.')),
'platform_name': translate(get_value('certificates', {}).get('platform_name', get_value('PLATFORM_NAME', '')), default=_('Platform Name')),
'header_text': translate(get_value('certificates', {}).get('header_text', ''), default=_('Congratulations! This page summarizes what you accomplished. Show it off to family, friends, and colleagues in your social and professional networks.')),
'short_platform_description': translate(get_value('certificates', {}).get('short_platform_description', '')),
'we_hereby_text': translate(get_value('certificates', {}).get('we_hereby_text', 'We hereby certify that:')),
'successfully_completed_text': translate(get_value('certificates', {}).get('successfully_completed_text', "successfully completed, received a passing grade, and was awarded this platform's Honor Code Certificate of Completion in:")),
'we_hereby_text': translate(get_value('certificates', {}).get('we_hereby_text', ''), default=_('We hereby certify that:')),
'successfully_completed_text': translate(get_value('certificates', {}).get('successfully_completed_text', ''), default=_('successfully completed, received a passing grade, and was awarded this platform\'s Honor Code Certificate of Completion in:')),
'optional_cert_text': translate(get_value('certificates', {}).get('optional_cert_text', '')),
'footer_about_platform_text': translate(get_value('certificates', {}).get('footer_about_platform_text', 'Our platform offers interactive online classes and MOOCs.')),
'footer_about_platform_text': translate(get_value('certificates', {}).get('footer_about_platform_text'), default=_('Our platform offers interactive online classes and MOOCs.')),
'footer_about_platform_url': get_value('certificates', {}).get('footer_about_platform_url', '#'),
'footer_about_accomplishments_text': translate(get_value('certificates', {}).get('footer_about_accomplishments_text', "Our platform acknowledges achievements through certificates, which are awarded for course activities that our platform students complete.")),
'footer_about_accomplishments_text': translate(get_value('certificates', {}).get('footer_about_accomplishments_text'), default=_('Our platform acknowledges achievements through certificates, which are awarded for course activities that our platform students complete.')),
'footer_copyright_text': translate(get_value('certificates', {}).get('footer_copyright_text', "")),
'footer_tos_url': get_value('certificates', {}).get('footer_tos_url', "#"),
'footer_privacy_url': get_value('certificates', {}).get('footer_privacy_url', "#"),
Expand Down

0 comments on commit 05ba3b5

Please sign in to comment.