Commits

Ratnadeep Debnath committed 9fea4d1

Take plural forms into consideration while copying source in Lotte.

  • Participants
  • Parent commits 01b8989

Comments (0)

Files changed (2)

File transifex/addons/lotte/static/lotte/js/tx.lotte2.js

 		this.pushOnClick = function() {
 				$(document).click(function (e) {
 						if ($(e.target).parents().filter('tr').length && $(e.target).parents('tr').children('td.trans').length){
-							var id = parseInt($(e.target).parents("tr").find("textarea.translation").attr("id").split("_")[1]);
+              var id = parseInt($(e.target).parents("tr").find("textarea.translation").attr("id").split("_")[1]);
 							switch (id) {
 								case this_stringset.current_id : break;
 							default :
             var a=$(this);
             var plural_orig = $('.msg .source_string_plural', a.parents('tr'));
             var orig=$('.msg .source_string', a.parents('tr')).whitespaceHighlight("reset");
-            if(plural_orig.length > 0)
+            var pluralized = false;
+            if(plural_orig.length > 0){
+              pluralized = true;
               orig = orig.substring(orig.indexOf('</span>')+7);
+              plurals_dict = {};
+              plural_orig.each(function(index, element){
+                var s = $(element).whitespaceHighlight("reset");
+                s = s.substring(s.indexOf('</span>')+7);
+                var rule = $(element).attr('rule');
+                plurals_dict[rule] = s;
+              });
+            }
             // Get the default (other) translation textarea and corresponding string object
             var default_textarea = $('textarea.default_translation', a.parents('tr'));
             // Get the id of current textarea -> binding index
             $('textarea.translation', a.parents('tr')).each(function(){
                 var trans=$(this);
                 trans.val(html_unescape(orig));
+                if (pluralized) {
+                  var rule = trans.prev('span').attr('rule');
+                  var s = plurals_dict[rule];
+                  if (s){
+                    s = html_unescape(s);
+                    trans.val(s);
+                  }
+                }
                 /* Mark the translated field as modified */
                 string.translate(trans.val(), trans.prev('span.rule').attr('rule'));
                 if (string.modified) {

File transifex/addons/lotte/templates/translate.html

                                 source_divs += '<span class="plural_title">'+plural_types[rule]+': </span>'
                               source_divs += html_escape(clean_array["source_dict"]["source_strings"][plural_types[rule]]) + '</div>'
                             }else
-                              source_divs += '<p class="source_string_plural"><span class="plural_title">'+plural_types[rule]+': </span>' + html_escape(clean_array["source_dict"]["source_strings"][plural_types[rule]]) + '</p>'
+                              source_divs += '<p class="source_string_plural" rule="'+plural_types[rule]+'"><span class="plural_title">'+plural_types[rule]+': </span>' + html_escape(clean_array["source_dict"]["source_strings"][plural_types[rule]]) + '</p>'
                             plurals_counter++;
                         }
                     }