From 51b1304eff7dd0e8d6d316160099695bba057ea4 Mon Sep 17 00:00:00 2001 From: Mark Walker Date: Thu, 17 Nov 2022 13:00:40 +0000 Subject: [PATCH] Adding translation to javascript --- .gitignore | 2 ++ djangoproject/static/js/mod/clippify.js | 12 ++++++++---- djangoproject/static/js/mod/fundraising-index.js | 2 +- djangoproject/static/js/mod/list-collapsing.js | 4 ++-- djangoproject/static/js/mod/mobile-menu.js | 3 ++- djangoproject/static/js/mod/stripe-change-card.js | 3 ++- djangoproject/static/js/mod/stripe-donation.js | 4 ++-- djangoproject/templates/base.html | 1 + djangoproject/urls/www.py | 2 ++ 9 files changed, 22 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 6edafa945..a19d16d35 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,8 @@ data *.db locale/*/LC_MESSAGES/django.mo */locale/*/LC_MESSAGES/django.mo +locale/*/LC_MESSAGES/djangojs.mo +*/locale/*/LC_MESSAGES/djangojs.mo .sass-cache/ .coverage .tox diff --git a/djangoproject/static/js/mod/clippify.js b/djangoproject/static/js/mod/clippify.js index d80df7e85..1d231735e 100644 --- a/djangoproject/static/js/mod/clippify.js +++ b/djangoproject/static/js/mod/clippify.js @@ -3,7 +3,8 @@ define(['jquery', 'clipboard'], function($, Clipboard) { var header = $(this); var wrapper = header.parent(); var code = $('.highlight', wrapper); - var btn = $(''); + var copy_str = gettext("Copy this code"); + var btn = $(''); btn.append(''); btn.data('clipboard-text', $.trim(code.text())); header.append(btn); @@ -11,7 +12,8 @@ define(['jquery', 'clipboard'], function($, Clipboard) { // For Django 2.0 docs and older. $('.snippet').each(function() { var code = $('.highlight', this); - var btn = $(''); + var copy_str = gettext("Copy this code"); + var btn = $(''); var header = $('.snippet-filename', this); btn.append(''); @@ -24,14 +26,16 @@ define(['jquery', 'clipboard'], function($, Clipboard) { } }); clip.on('success', function(e) { - var success = $('').text('Copied!') + var copy_str = gettext("Copied!"); + var success = $('').text(copy_str); success.prependTo(e.trigger).delay(1000).fadeOut(); }); clip.on('error', function(e) { // Safari doesn't support the execCommand (yet) but because clipboardjs // also uses Selection API, we can instruct users to just press the keyboard shortcut // See https://clipboardjs.com/#browser-support - var success = $('').text('Press ⌘-C to copy'); + var copy_str = gettext("Press ⌘-C to copy"); + var success = $('').text(copy_str); success.prependTo(e.trigger).delay(5000).fadeOut(); }); }); diff --git a/djangoproject/static/js/mod/fundraising-index.js b/djangoproject/static/js/mod/fundraising-index.js index a3104ac08..7eb1c4b70 100644 --- a/djangoproject/static/js/mod/fundraising-index.js +++ b/djangoproject/static/js/mod/fundraising-index.js @@ -28,7 +28,7 @@ define([ } }, setDonateButtonText: function(event) { - var text = 'Donate'; + var text = gettext('Donate'); var interval = $('#id_interval').val(); if (interval != 'onetime') { text += ' ' + interval; diff --git a/djangoproject/static/js/mod/list-collapsing.js b/djangoproject/static/js/mod/list-collapsing.js index 1d8b7ba82..9806a4f00 100644 --- a/djangoproject/static/js/mod/list-collapsing.js +++ b/djangoproject/static/js/mod/list-collapsing.js @@ -16,8 +16,8 @@ define([ this.items = this.list.children('li'); //get items this.headings = this.items.children('h2'); //get headings - this.buttonExpand = $('Expand All'); //build buttons - this.buttonCollapse = $('Collapse All'); //build buttons + this.buttonExpand = $('' + gettext("Expand All") + ''); //build buttons + this.buttonCollapse = $('' + gettext("Collapse All") + ''); //build buttons this.buttonContainer = $('').insertBefore(this.list); //create a button container this.buttonContainer //append container to label .append(this.buttonExpand) diff --git a/djangoproject/static/js/mod/mobile-menu.js b/djangoproject/static/js/mod/mobile-menu.js index 02bed15e8..a40677344 100644 --- a/djangoproject/static/js/mod/mobile-menu.js +++ b/djangoproject/static/js/mod/mobile-menu.js @@ -11,8 +11,9 @@ define([ MobileMenuExport.prototype = { init: function(){ var self = this; + var label = gettext('Menu'); self.menu.addClass('nav-menu-on'); - self.button = $(''); + self.button = $(''); self.button.insertBefore(self.menuBtn); self.button.on( 'click', function(){ self.menu.toggleClass('active'); diff --git a/djangoproject/static/js/mod/stripe-change-card.js b/djangoproject/static/js/mod/stripe-change-card.js index 80c2fdc00..133343df7 100644 --- a/djangoproject/static/js/mod/stripe-change-card.js +++ b/djangoproject/static/js/mod/stripe-change-card.js @@ -17,6 +17,7 @@ define([ 'donation_id': donationId, 'csrfmiddlewaretoken': csrfToken }; + var success_copy = gettext('Card updated'); $.ajax({ type: "POST", url: $heroForm.data('update-card-url'), @@ -24,7 +25,7 @@ define([ dataType: 'json', success: function (data) { if (data.success) { - $this.parent().find('.change-card-result').text('Card updated'); + $this.parent().find('.change-card-result').text(success_copy); } else { alert(data.error); } diff --git a/djangoproject/static/js/mod/stripe-donation.js b/djangoproject/static/js/mod/stripe-donation.js index ac9d9110d..14dc2981c 100644 --- a/djangoproject/static/js/mod/stripe-donation.js +++ b/djangoproject/static/js/mod/stripe-donation.js @@ -28,11 +28,11 @@ define([ var stripe = Stripe($donationForm.data('stripeKey')) return stripe.redirectToCheckout({sessionId: data.sessionId}) } else { - msg = 'There was an error setting up your donation. ' + msg = gettext('There was an error setting up your donation. '); if (data.error.amount) { msg += data.error.amount } else { - msg += 'Sorry. Please refresh the page and try again.' + msg += gettext('Sorry. Please refresh the page and try again.'); } alert(msg); } diff --git a/djangoproject/templates/base.html b/djangoproject/templates/base.html index 1624c6599..c85f8c9dc 100644 --- a/djangoproject/templates/base.html +++ b/djangoproject/templates/base.html @@ -57,6 +57,7 @@ + {% block head_extra %}{% endblock head_extra %} diff --git a/djangoproject/urls/www.py b/djangoproject/urls/www.py index 0decac2da..d6a8c4706 100644 --- a/djangoproject/urls/www.py +++ b/djangoproject/urls/www.py @@ -8,6 +8,7 @@ from django.urls import include, path, re_path from django.views.decorators.cache import cache_page from django.views.generic import RedirectView, TemplateView +from django.views.i18n import JavaScriptCatalog from django.views.static import serve from accounts import views as account_views @@ -29,6 +30,7 @@ urlpatterns = i18n_patterns( path('', TemplateView.as_view(template_name='homepage.html'), name="homepage"), + path('jsi18n/', JavaScriptCatalog.as_view(), name='javascript-catalog'), path('change-language//', project_views.change_language, name="change_language"), path('start/overview/', TemplateView.as_view(template_name='overview.html'), name="overview"), path('start/', TemplateView.as_view(template_name='start.html'), name="start"),