Make JavaScript files translatable

This commit is contained in:
Jay Trees 2022-03-22 16:15:56 +01:00
parent 5295af951c
commit 8a17e0de52
6 changed files with 91 additions and 53 deletions

View file

@ -36,8 +36,8 @@ $(function() {
}
$.fn.api.settings.onSuccess = function(response, element, xhr) {
element.dropdown({
values: response.results,
placeholder: 'No wishlist selected.'
values : response.results,
placeholder: text.wishlist_no_selection
})
if ($_GET.wishlist) {
@ -60,7 +60,7 @@ $(function() {
class : '',
actions : [
{
text: 'Thanks for nothing',
text : text.modal_failure_approve,
class: 'primary'
}
],
@ -79,7 +79,7 @@ $(function() {
class : '',
actions : [
{
text: 'Thanks for nothing',
text : text.modal_failure_approve,
class: 'primary'
}
],
@ -94,7 +94,7 @@ $(function() {
$.fn.toast.settings.showProgress = 'bottom';
$.fn.toast.settings.class = 'success';
$.fn.toast.settings.showIcon = true;
$.fn.toast.settings.title = 'Success';
$.fn.toast.settings.title = text.modal_success_title;
/**
* Menu
@ -157,7 +157,7 @@ function showError(error) {
class : '',
actions : [
{
text: 'Thanks for nothing',
text : text.modal_failure_approve,
class: 'primary'
}
],
@ -175,7 +175,7 @@ function showWarning(warning) {
class : '',
actions : [
{
text: 'Understood',
text : text.modal_warning_approve,
class: 'primary'
}
],

View file

@ -14,7 +14,7 @@ $(function() {
rules : [
{
type : 'match[user-password]',
prompt : 'Password must match.'
prompt : text.form_profile_password
}
]
},

View file

@ -85,7 +85,7 @@ $(function () {
fetch('/src/api/wishes.php', {
method: 'PUT',
body: formData
body : formData
})
.then(response => response.json())
.then(response => {
@ -94,7 +94,7 @@ $(function () {
elementModalFetch.modal('hide');
$('body').toast({ message: 'Wish information updated.' });
$('body').toast({ message: text.toast_wish_update });
}
buttonFetch.removeClass('loading');
@ -108,8 +108,8 @@ $(function () {
});
} else {
$('body').toast({
class: 'primary',
message: 'Don\'t forget to save your changes.'
class : 'primary',
message: text.toast_wish_save
});
formWish.removeClass('loading');
@ -137,8 +137,8 @@ $(function () {
$('.form.wish [name="wish_image"]').val(newImageURL);
$('body').toast({
class: 'primary',
message: 'Don\'t forget to save your changes.'
class : 'primary',
message: text.toast_wish_save
});
}
});

View file

@ -7,18 +7,18 @@ $(function() {
if ($('.wishlist-own').length) {
$('body')
.modal({
title: $('.wishlist-own .header').text(),
content: $('.wishlist-own .text').html(),
class: '',
title : $('.wishlist-own .header').text(),
content : $('.wishlist-own .text').html(),
class : '',
blurring: true,
closable: false,
actions: [
actions : [
{
text: 'Close this tab',
text : text.modal_wishlist_warning_approve,
class: 'approve primary'
},
{
text: 'Show wishlist anyway',
text : text.modal_wishlist_warning_deny,
class: 'deny'
}
],
@ -42,16 +42,16 @@ $(function() {
$('body')
.modal({
title: 'Really commit?',
content: 'Would you really like to commit to this purchase? It will no longer appear in the wishlist for others anymore.',
class: 'tiny',
actions: [
title : text.modal_wish_commit_title,
content : text.modal_wish_commit,
class : 'tiny',
actions : [
{
text: 'Yes, commit',
text : text.modal_wish_commit_approve,
class: 'approve primary'
},
{
text: 'Cancel',
text : text.modal_wish_commit_deny,
class: ''
}
],

View file

@ -6,15 +6,15 @@ $(function () {
function wishlistsRefresh() {
$('.ui.dropdown.wishlists').api({
action: 'get wishlists',
method: 'GET',
on: 'now',
action : 'get wishlists',
method : 'GET',
on : 'now',
onSuccess: function (response, element, xhr) {
wishlists = response.results;
element.dropdown({
values: wishlists,
placeholder: 'No wishlist selected.'
values : wishlists,
placeholder: text.wishlist_no_selection
})
if ($_GET.wishlist) {
@ -173,12 +173,12 @@ $(function () {
navigator.clipboard.writeText(wishlist_href).then(function() {
$('body').toast({ message: 'Link copied to clipboard.' });
$('body').toast({ message: text.toast_clipboard_success });
}, function() {
$('body').toast({
class : 'error',
title : 'Error',
message : 'Unable to copy to clipboard. There is likely a permission issue.'
class : 'error',
title : text.toast_clipboard_error_title,
message : text.toast_clipboard_error
});
});
@ -220,7 +220,7 @@ $(function () {
modalRename.modal('hide');
$('body').toast({ message: 'Wishlist successfully renamed.' });
$('body').toast({ message: text.toast_wishlist_rename });
})
.catch(handleFetchCatch)
.finally(function() {
@ -243,16 +243,16 @@ $(function () {
modalDefault
.modal({
title: 'Really delete?',
class: 'tiny',
content: 'Do you really want to delete the wishlist <strong>' + $('.ui.dropdown.wishlists').dropdown('get text') + '</strong>?',
actions: [
title : text.modal_wishlist_delete_title,
class : 'tiny',
content : text.modal_wishlist_delete.replace('WISHLIST_NAME', $('.ui.dropdown.wishlists').dropdown('get text')),
actions : [
{
text: 'Yes, delete',
text : text.modal_wishlist_delete_approve,
class: 'approve red'
},
{
text: 'No, keep',
text : text.modal_wishlist_delete_deny,
class: 'deny'
},
],
@ -274,7 +274,7 @@ $(function () {
urlParams.delete('wishlist');
$('body').toast({ message: 'Wishlist successfully deleted.' });
$('body').toast({ message:text.toast_wishlist_delete });
wishlistsRefresh();
@ -305,19 +305,19 @@ $(function () {
modalDefault
.modal({
title: 'Really delete?',
content: '<p>Would you really like to delete to this wish? It will be gone forever.</p>',
class: 'tiny',
actions: [
title : text.modal_wish_delete_title,
content : text.modal_wish_delete,
class : 'tiny',
actions : [
{
text: 'Yes, delete',
text : text.modal_wish_delete_approve,
class: 'approve primary'
},
{
text: 'Cancel'
text: text.modal_wish_delete_deny
}
],
autoShow: true,
autoShow : true,
onApprove: function (buttonApprove) {
buttonApprove.addClass('loading');
@ -334,7 +334,7 @@ $(function () {
onSuccess: function () {
column.fadeOut();
$('body').toast({ message: 'Wish successfully deleted.' });
$('body').toast({ message: text.toast_wish_delete });
wishlistsRefresh();
@ -377,7 +377,7 @@ $(function () {
.then(handleFetchResponse)
.then(function(response) {
if (response.success) {
$('body').toast({ message: 'Wish successfully added.' });
$('body').toast({ message: text.toast_wish_add });
wishlistsRefresh();
@ -424,7 +424,7 @@ $(function () {
urlParams.set('wishlist', response.data.lastInsertId);
$('body').toast({ message: 'Wishlist successfully created.' });
$('body').toast({ message: text.toast_wish_create });
wishlistsRefresh();
}

View file

@ -231,6 +231,44 @@ class Page
?>
<script type="text/javascript">
var $_GET = JSON.parse('<?= isset($_GET) ? json_encode($_GET) : array() ?>');
var text = {
wishlist_no_selection : '<?= __('No wishlist selected.') ?>',
modal_failure_approve : '<?= __('Thanks for nothing') ?>',
modal_warning_approve : '<?= __('Understood') ?>',
modal_success_title : '<?= __('Success') ?>',
modal_wishlist_warning_approve: '<?= __('Close this tab') ?>',
modal_wishlist_warning_deny : '<?= __('Show wishlist anyway') ?>',
modal_wishlist_delete_title : '<?= __('Really delete?') ?>',
modal_wishlist_delete : '<?= sprintf(__('Do you really want to delete the wishlist %s?'), '<strong>WISHLIST_NAME</strong>') ?>',
modal_wishlist_delete_approve : '<?= __('Yes, delete') ?>',
modal_wishlist_delete_deny : '<?= __('No, keep') ?>',
modal_wish_commit_title : '<?= __('Really commit?') ?>',
modal_wish_commit : '<?= __('Would you really like to commit to this purchase? It will no longer appear in the wishlist for others anymore.') ?>',
modal_wish_commit_approve : '<?= __('Yes, commit') ?>',
modal_wish_commit_deny : '<?= __('Cancel') ?>',
modal_wish_delete_title : '<?= __('Really delete?') ?>',
modal_wish_delete : '<?= __('Would you really like to delete to this wish? It will be gone forever.') ?>',
modal_wish_delete_approve : '<?= __('Yes, delete') ?>',
modal_wish_delete_deny : '<?= __('No, keep') ?>',
form_profile_password : '<?= __('Password must match.') ?>',
toast_wishlist_rename : '<?= __('Wishlist successfully renamed.') ?>',
toast_wishlist_delete : '<?= __('Wishlist successfully deleted.') ?>',
toast_wish_create : '<?= __('Wish successfully created.') ?>',
toast_wish_add : '<?= __('Wish successfully added.') ?>',
toast_wish_update : '<?= __('Wish information updated.') ?>',
toast_wish_save : '<?= __(addslashes('Don\'t forget to save your changes.')) ?>',
toast_wish_delete : '<?= __('Wish successfully deleted.') ?>',
toast_clipboard_error_title : '<?= __('Error') ?>',
toast_clipboard_error : '<?= __('Unable to copy to clipboard. There is likely a permission issue.') ?>',
toast_clipboard_success : '<?= __('Link copied to clipboard.') ?>',
};
</script>
<?php