From 9585071da456880c380088307afd972cfd929ad4 Mon Sep 17 00:00:00 2001 From: wasuregusa18 Date: Mon, 9 Jan 2023 11:45:24 +0900 Subject: [PATCH 1/4] feat: add localization context processor --- ecommerce/core/context_processors.py | 19 +++++++++++++++++++ ecommerce/settings/base.py | 1 + 2 files changed, 20 insertions(+) diff --git a/ecommerce/core/context_processors.py b/ecommerce/core/context_processors.py index 6c62ba12ba4..709bff61c16 100644 --- a/ecommerce/core/context_processors.py +++ b/ecommerce/core/context_processors.py @@ -1,5 +1,8 @@ +from babel.numbers import get_currency_symbol +from django.conf import settings + from ecommerce.core.url_utils import get_favicon_url, get_lms_dashboard_url, get_lms_url, get_logo_url @@ -16,3 +19,19 @@ def core(request): 'favicon_url': get_favicon_url(), 'optimizely_snippet_src': site_configuration.optimizely_snippet_src, } + +def localization(_request): + defaults = getattr(settings, "COURSE_MODE_DEFAULTS", {}) + default_currency = defaults.get("currency") + registration_currency = getattr(settings, "PAID_COURSE_REGISTRATION_CURRENCY", None) + currency_code = registration_currency or default_currency or "USD" + + if not isinstance(currency_code, str): + raise ValueError(f"Currency code must be a string; currently: {currency_code}") + + return { + # Note: babel returns code if not found + # get_currency_symbol("XYZ") => "XYZ" + "currency_symbol_": get_currency_symbol(currency_code), + "currency_code_": currency_code, + } \ No newline at end of file diff --git a/ecommerce/settings/base.py b/ecommerce/settings/base.py index 6432d0969a8..76e8e4689ae 100644 --- a/ecommerce/settings/base.py +++ b/ecommerce/settings/base.py @@ -208,6 +208,7 @@ 'oscar.apps.communication.notifications.context_processors.notifications', 'oscar.core.context_processors.metadata', 'ecommerce.core.context_processors.core', + "ecommerce.core.context_processors.localization", 'ecommerce.extensions.analytics.context_processors.analytics', ), 'debug': True, # Django will only display debug pages if the global DEBUG setting is set to True. From 7b58bc7ac0a7614f5378882ae41fed3c099043fb Mon Sep 17 00:00:00 2001 From: wasuregusa18 Date: Wed, 11 Jan 2023 14:33:45 +0900 Subject: [PATCH 2/4] fix: use dynamic localized currency symbol --- .../templates/_course_credit_seats.html | 2 +- ecommerce/static/templates/_course_seat.html | 2 +- .../static/templates/_offer_course_list.html | 4 +- .../audit_course_seat_form_field.html | 2 +- ecommerce/static/templates/coupon_form.html | 697 ++++++++++++------ .../credit_course_seat_form_field_row.html | 2 +- .../templates/enterprise_coupon_detail.html | 4 +- .../templates/enterprise_coupon_form.html | 2 +- .../honor_course_seat_form_field.html | 2 +- .../professional_course_seat_form_field.html | 2 +- ecommerce/templates/base.html | 7 +- 11 files changed, 496 insertions(+), 230 deletions(-) diff --git a/ecommerce/static/templates/_course_credit_seats.html b/ecommerce/static/templates/_course_credit_seats.html index b8d147b2319..804ea19acaa 100644 --- a/ecommerce/static/templates/_course_credit_seats.html +++ b/ecommerce/static/templates/_course_credit_seats.html @@ -21,7 +21,7 @@ <% _.each(creditSeats, function (seat) { %> <%= seat.get('credit_provider_display_name') %> - <%= '$' + Number(seat.get('price')).toLocaleString() %> + <%= currencySymbol + Number(seat.get('price')).toLocaleString() %> <%= seat.get('credit_hours') %> <% var expires = seat.get('expires'); if (expires) { diff --git a/ecommerce/static/templates/_course_seat.html b/ecommerce/static/templates/_course_seat.html index 4391e3107c5..e91fb0bf8fb 100644 --- a/ecommerce/static/templates/_course_seat.html +++ b/ecommerce/static/templates/_course_seat.html @@ -3,7 +3,7 @@
<%= seat.getSeatTypeDisplayName() %>
-
<%= gettext('Price:') + ' $' + Number(seat.get('price')).toLocaleString() %>
+
<%= gettext('Price:') + ' ' + currencySymbol + Number(seat.get('price')).toLocaleString() %>
<% var expires = seat.get('expires'); if(expires) { print(gettext('Upgrade Deadline:') + ' ' + moment.utc(expires).format('lll z')); diff --git a/ecommerce/static/templates/_offer_course_list.html b/ecommerce/static/templates/_offer_course_list.html index 8eb7ffc9142..e02779aba3e 100644 --- a/ecommerce/static/templates/_offer_course_list.html +++ b/ecommerce/static/templates/_offer_course_list.html @@ -52,12 +52,12 @@
- <%= gettext('Price (in USD)') %>: $0.00 + <%= gettext('Price (in USD)') %>: {{ currency_symbol_ }}0.00 diff --git a/ecommerce/static/templates/coupon_form.html b/ecommerce/static/templates/coupon_form.html index 8255d9567fe..eff1568a97c 100644 --- a/ecommerce/static/templates/coupon_form.html +++ b/ecommerce/static/templates/coupon_form.html @@ -1,249 +1,510 @@
-
-
- - -

+
+
+ + +

+
+
+ + +

+
+
+ + +

+
+ +
+
+ +
+
+ +
+
-
- - -

+

+
+
+ +
+
+ +
+
-
- -

+
-
-
- -
-
- -
-

-
-
- -
-
- -
-

-
-
+
+ + +

+
-
- - -

-
+
+ + +

+
-
- - -

-
+
+ + +

+
-
- - -

-
+
+ + +

+
-
- - -

-
+
+ +
+
+ +
+
+ + + + +
+

+
-
- -
-
- -
-
- - - - -
-

-
+
+ + +

+
+
-
- - -

+
+ +
+
+ +
-
- -
- -
-
- - -
-
- - -
-
- - -
-
+
+ +
- -
- - -

+
+ +
+
+
-
- -
-
$
- -
-

-
+
+ + +

+
-
- -
-
- -
-

-
+
+ +
+
$
+ +
+

+
-