Skip to content

Commit

Permalink
Adding translation to javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
marksweb committed Nov 17, 2022
1 parent 37ac4cb commit 51b1304
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions djangoproject/static/js/mod/clippify.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ define(['jquery', 'clipboard'], function($, Clipboard) {
var header = $(this);
var wrapper = header.parent();
var code = $('.highlight', wrapper);
var btn = $('<span class="btn-clipboard" title="Copy this code">');
var copy_str = gettext("Copy this code");
var btn = $('<span class="btn-clipboard" title="' + copy_str + '">');
btn.append('<i class="icon icon-clipboard">');
btn.data('clipboard-text', $.trim(code.text()));
header.append(btn);
});
// For Django 2.0 docs and older.
$('.snippet').each(function() {
var code = $('.highlight', this);
var btn = $('<span class="btn-clipboard" title="Copy this code">');
var copy_str = gettext("Copy this code");
var btn = $('<span class="btn-clipboard" title="' + copy_str + '">');
var header = $('.snippet-filename', this);

btn.append('<i class="icon icon-clipboard">');
Expand All @@ -24,14 +26,16 @@ define(['jquery', 'clipboard'], function($, Clipboard) {
}
});
clip.on('success', function(e) {
var success = $('<span class="clipboard-success">').text('Copied!')
var copy_str = gettext("Copied!");
var success = $('<span class="clipboard-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 = $('<span class="clipboard-success">').text('Press ⌘-C to copy');
var copy_str = gettext("Press ⌘-C to copy");
var success = $('<span class="clipboard-success">').text(copy_str);
success.prependTo(e.trigger).delay(5000).fadeOut();
});
});
2 changes: 1 addition & 1 deletion djangoproject/static/js/mod/fundraising-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions djangoproject/static/js/mod/list-collapsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ define([
this.items = this.list.children('li'); //get items
this.headings = this.items.children('h2'); //get headings

this.buttonExpand = $('<span class="expandall">Expand All</span>'); //build buttons
this.buttonCollapse = $('<span class="collapseall">Collapse All</span>'); //build buttons
this.buttonExpand = $('<span class="expandall">' + gettext("Expand All") + '</span>'); //build buttons
this.buttonCollapse = $('<span class="collapseall">' + gettext("Collapse All") + '</span>'); //build buttons
this.buttonContainer = $('<span class="form-controls label"></span>').insertBefore(this.list); //create a button container
this.buttonContainer //append container to label
.append(this.buttonExpand)
Expand Down
3 changes: 2 additions & 1 deletion djangoproject/static/js/mod/mobile-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ define([
MobileMenuExport.prototype = {
init: function(){
var self = this;
var label = gettext('Menu');
self.menu.addClass('nav-menu-on');
self.button = $('<div class="menu-button"><i class="icon icon-reorder"></i><span>Menu</span></div>');
self.button = $('<div class="menu-button"><i class="icon icon-reorder"></i><span>' + label + '</span></div>');
self.button.insertBefore(self.menuBtn);
self.button.on( 'click', function(){
self.menu.toggleClass('active');
Expand Down
3 changes: 2 additions & 1 deletion djangoproject/static/js/mod/stripe-change-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ define([
'donation_id': donationId,
'csrfmiddlewaretoken': csrfToken
};
var success_copy = gettext('Card updated');
$.ajax({
type: "POST",
url: $heroForm.data('update-card-url'),
data: data,
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);
}
Expand Down
4 changes: 2 additions & 2 deletions djangoproject/static/js/mod/stripe-donation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions djangoproject/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
</script>
<script src="{% static "js/lib/modernizr.js" %}"></script>
<script src="{% static "js/mod/switch-dark-mode.js" %}"></script>
<script src="{% url 'javascript-catalog' %}"></script>
{% block head_extra %}{% endblock head_extra %}
</head>

Expand Down
2 changes: 2 additions & 0 deletions djangoproject/urls/www.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/<str:lang_code>/', 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"),
Expand Down

0 comments on commit 51b1304

Please sign in to comment.