Browse Source

working on asynch translation handling

El RIDO 9 years ago
parent
commit
9deaed9406
4 changed files with 29 additions and 22 deletions
  1. 1 1
      i18n/de.json
  2. 26 19
      js/privatebin.js
  3. 1 1
      tpl/bootstrap.php
  4. 1 1
      tpl/page.php

+ 1 - 1
i18n/de.json

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

+ 26 - 19
js/privatebin.js

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

+ 1 - 1
tpl/bootstrap.php

@@ -69,7 +69,7 @@ if ($MARKDOWN):
 <?php
 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]>
 		<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
 		<![endif]-->

+ 1 - 1
tpl/page.php

@@ -47,7 +47,7 @@ if ($MARKDOWN):
 <?php
 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]>
 		<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
 		<![endif]-->