working on asynch translation handling

This commit is contained in:
El RIDO 2017-03-12 17:08:12 +01:00
parent 1649ff34f5
commit 9deaed9406
No known key found for this signature in database
GPG Key ID: 0F5C940A6BD81F92
4 changed files with 29 additions and 22 deletions

View File

@ -93,7 +93,7 @@
"Anonymous": "Anonymous":
"Anonym", "Anonym",
"Avatar generated from IP address": "Avatar generated from IP address":
"Anvatar (generiert aus der IP-Adresse)", "Avatar (generiert aus der IP-Adresse)",
"Add comment": "Add comment":
"Kommentar hinzufügen", "Kommentar hinzufügen",
"Optional nickname…": "Optional nickname…":

View File

@ -416,7 +416,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
} }
// if no translation string cannot be found (in translations object) // if no translation string cannot be found (in translations object)
if (!translations.hasOwnProperty(messageId)) { if (!translations.hasOwnProperty(messageId) || language === null) {
// if language is still loading and we have an elemt assigned // if language is still loading and we have an elemt assigned
if (language === null && $element !== null) { if (language === null && $element !== null) {
// handle the error by attaching the language loaded event // handle the error by attaching the language loaded event
@ -432,9 +432,9 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
// file is loaded // file is loaded
} }
// for all other langauges than English for which thsi behaviour // for all other langauges than English for which this behaviour
// is expected as it is built-in, log error // is expected as it is built-in, log error
if (language !== 'en') { if (language !== null && language !== 'en') {
console.error('Missing translation for: \'' + messageId + '\' in language ' + language); console.error('Missing translation for: \'' + messageId + '\' in language ' + language);
// fallback to English // fallback to English
} }
@ -463,7 +463,13 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
// if $element is given, apply text to element // if $element is given, apply text to element
if ($element !== null) { if ($element !== null) {
$element.text(output); // get last text node of element
var content = $element.contents();
if (content.length > 1) {
content[content.length - 1].nodeValue = ' ' + output;
} else {
$element.text(output);
}
} }
return output; return output;
@ -1070,13 +1076,10 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
// show text // show text
if (args !== null) { if (args !== null) {
// get last text node of element // add jQuery object to it as first parameter
var content = $element.contents(); args.unshift($element);
if (content.length > 1) { // pass it to I18n
content[content.length - 1].nodeValue = ' ' + I18n._(args); I18n._.apply(this, args);
} else {
$element.text(I18n._(args));
}
} }
// show notification // show notification
@ -1144,7 +1147,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
*/ */
me.showRemaining = function(message) me.showRemaining = function(message)
{ {
console.error('remaining message shown: ', message); console.log('remaining message shown: ', message);
handleNotification(1, $remainingTime, message); handleNotification(1, $remainingTime, message);
} }
@ -1360,7 +1363,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
'This document will expire in %d ' + expiration[1] + 's.' 'This document will expire in %d ' + expiration[1] + 's.'
]; ];
Alert.showRemaining(expirationLabel, expiration[0]); Alert.showRemaining([expirationLabel, expiration[0]]);
$remainingTime.removeClass('foryoureyesonly') $remainingTime.removeClass('foryoureyesonly')
} else { } else {
// never expires // never expires
@ -2283,10 +2286,11 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
Helper.urls2links($commentEntryData); Helper.urls2links($commentEntryData);
// set nickname // set nickname
if (nickname.length > 0){ if (nickname.length > 0) {
$commentEntry.find('span.nickname').text(nickname); $commentEntry.find('span.nickname').text(nickname);
} else { } else {
$commentEntry.find('span.nickname').html('<i>' + I18n._('Anonymous') + '</i>'); $commentEntry.find('span.nickname').html('<i></i>');
I18n._($commentEntry.find('span.nickname i'), 'Anonymous');
} }
// set date // set date
@ -2297,10 +2301,13 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
// if an avatar is available, display it // if an avatar is available, display it
if (comment.meta.vizhash) { if (comment.meta.vizhash) {
$commentEntry.find('span.nickname') $commentEntry.find('span.nickname')
.before( .before(
'<img src="' + comment.meta.vizhash + '" class="vizhash" title="' + '<img src="' + comment.meta.vizhash + '" class="vizhash" /> '
I18n._('Avatar generated from IP address') + '" /> ' );
); $(document).on('languageLoaded', function () {
$commentEntry.find('img.vizhash')
.prop('title', I18n._('Avatar generated from IP address'));
});
} }
// finally append comment // finally append comment

View File

@ -69,7 +69,7 @@ if ($MARKDOWN):
<?php <?php
endif; endif;
?> ?>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-Twits2in/YkEGNmhvYLmBl6zBKLtymFOzwAqxcJHQ0zJBpXCvxxmbIoW0LUWnzTq2hUtPgjAMZznSU2xkMPjjQ==" crossorigin="anonymous"></script> <script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-LYpK88nUEIgIruOud+YW0LKt+V+PVZZ1OEuO6SF49Yo6Dl0q/DCjJlHQ+RhSgkuexdSnpE9+ira9GJ1wih+e5A==" crossorigin="anonymous"></script>
<!--[if lt IE 10]> <!--[if lt IE 10]>
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style> <style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
<![endif]--> <![endif]-->

View File

@ -47,7 +47,7 @@ if ($MARKDOWN):
<?php <?php
endif; endif;
?> ?>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-Twits2in/YkEGNmhvYLmBl6zBKLtymFOzwAqxcJHQ0zJBpXCvxxmbIoW0LUWnzTq2hUtPgjAMZznSU2xkMPjjQ==" crossorigin="anonymous"></script> <script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-LYpK88nUEIgIruOud+YW0LKt+V+PVZZ1OEuO6SF49Yo6Dl0q/DCjJlHQ+RhSgkuexdSnpE9+ira9GJ1wih+e5A==" crossorigin="anonymous"></script>
<!--[if lt IE 10]> <!--[if lt IE 10]>
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style> <style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
<![endif]--> <![endif]-->