Source

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

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
{% extends "projects/project_detail_childs.html" %}
{% load i18n %}
{% load permissions %}
{% load txcommontags %}

{% block breadcrumb %}
{% homelink %} » 
<a href="{% url project_list_recent %}">{% trans "Projects" %}</a>
 » <a href="{% url project_detail project.slug %}">{{project}}</a>
{% if resource %} » <a href="{% url resource_detail project.slug resource.slug %}">{{resource}}</a>{% endif %}
{% blocktrans with target_language.name as lang %}Translate to {{ lang }}{% endblocktrans %}
{% endblock %}

{% get_permission "project_perm.maintain" for request.user and resource.project as "is_maintainer" %}

{% block extra_head %}
  <link media="screen" href="{{ STATIC_URL }}lotte/css/webtrans.css" type="text/css" rel="stylesheet" />
  <link media="screen" href="{{ STATIC_URL }}lotte/css/dataTable.css" type="text/css" rel="stylesheet" />
  <link media="screen" href="{{ STATIC_URL }}lotte/css/ui.tabs.lotte.css" type="text/css" rel="stylesheet"/>
  <link media="screen" href="{{ STATIC_URL }}lotte/css/jquery.whitespaceHighlight.css" type="text/css" rel="stylesheet"/>
  <!--[if IE]>
    <link media="screen" href="{{ STATIC_URL }}lotte/css/ie.lotte.css" type="text/css" rel="stylesheet"/>
  <![endif]-->
  <script type="text/javascript" src="{{ STATIC_URL }}lotte/js/jquery.dataTables.min.js"></script>
  <script type="text/javascript" src="{{ STATIC_URL }}lotte/js/jquery.dataTables.fnSetFilteringDaley.js"></script>
  <script type="text/javascript" src="{{ STATIC_URL }}lotte/js/jquery.dotimeout.min.js"></script>
  <script type="text/javascript" src="{{ STATIC_URL }}lotte/js/shortcut.js"></script>
  <script type="text/javascript" src="{{ STATIC_URL }}lotte/js/tx.lotte2.js"></script>
  <script type="text/javascript" src="{{ STATIC_URL }}lotte/js/footpanel.js"></script>
  <script type="text/javascript" src="{{ STATIC_URL }}lotte/js/jquery.hoverIntent.js"></script>
  <script type="text/javascript" src="{{ STATIC_URL }}lotte/js/jquery.whitespaceHighlight.js"></script>
  <script type="text/javascript" src="{{ STATIC_URL }}lotte/js/jquery.textarea-expander.js"></script>
  <script type="text/javascript" src="http://www.google.com/jsapi"></script>
  <script type="text/javascript">
    google.load("language", "1");
  </script>

<script type="text/javascript">

    /* Global variables */

    /* The instance of the StringSet class which has references to all the objects of the table */
    var stringset = null;
    /* Flags used for the auto-suggest function */
    var is_supported_source_lang = null;
    var is_supported_lang = null;
    /* DataTable instance var */
    var oTable;
    /* vars for string calcs */
    var translated;
    var untranslated;
    var translated_strings = {{ translated_strings }} 
    var untranslated_strings = {{ untranslated_strings }} 
    var total_strings = translated_strings + untranslated_strings;
    /* obj for holding default values of edited text areas. works like a hastable/dict */
    var current_defaults = {};
    /* var to keep filter state */
    var filter_var = null;
    var user_filters_values = null;
    var resource_filters_values = null;
    var more_languages_values = null;
    /* url for details requests */
    /* FIXME: Find a more clever way to do this resolving. */
    var entity_details_urlp_tmpl = "{% url translation_details_snippet 1111111111 target_language.code %}";
    var entity_suggestions_urlp_tmpl = "{% url entity_suggestions_snippet 1111111111 target_language.code %}";
    /* Global vars holding the source and target language codes */
    var source_lang = '{{ resource.source_language.code }}';
    var target_lang = '{{ target_language.code }}';

    function unique(a){
        /* Drop duplicated entries from an array (list) */
        var r = new Array();
        o:for(var i = 0, n = a.length; i < n; i++){
            for(var x = 0, y = r.length; x < y; x++){
                if(r[x]==a[i]) continue o;
            }
            r[r.length] = a[i];
        }
        return r;
    }

    function supported_language(code_aliases){
        // Drop spaces in the beginning/end of the string
        code_aliases = code_aliases.replace(/^ /,'').replace(/ $/,'');
        // Transform codes like 'pt_BR' into 'pt', dropping the locale, which is not supported by google translate
        code_aliases = code_aliases.replace(/\-+[\w]+/,'').replace(/_+[\w]+/,'').replace(/@+[\w]+/,'')
        // Remove duplicated elements
        code_list = unique(code_aliases.split(' '));
        for (i=0; i<code_list.length; i++){
            if (google.language.isTranslatable(code_list[i])){
                return code_list[i];
            }
        }
    }

    // Concatenate the code and aliases to check all of them one by one for availability.
    target_source_codes = source_lang + ' {{ resource.source_language.code_aliases }}';
    target_codes = target_lang + ' {{ target_language.code_aliases }}';

    google.setOnLoadCallback(function() {
        /* Global variables */
        source_lang = supported_language(target_source_codes)
        target_lang = supported_language(target_codes)
        if(source_lang && target_lang){
            is_supported_source_lang = true;
            is_supported_lang = true;
        }else{
            is_supported_source_lang = false;
            is_supported_lang = false;
        }

    /* document ready. do stuff */
    $(document).ready(function(){

        oTable = $('#stringset_table').dataTable({
            "oLanguage": {
                "sProcessing":   '{% trans "Processing..."|escapejs %}',
                "sLengthMenu":   '{% trans "Show _MENU_ entries"|escapejs %}',
                "sZeroRecords":  '{% trans "No matching records found"|escapejs %}',
                "sInfo":         '{% trans "Showing _START_ to _END_ of _TOTAL_ entries"|escapejs %}',
                "sInfoEmpty":    '{% trans "Nothing to show"|escapejs %}',
                "sInfoFiltered": '{% trans "(filtered from _MAX_ total entries)"|escapejs %}',
                "sInfoPostFix":  "",
                "sSearch":       '{% trans "Search:"|escapejs %}',
                "sUrl":          "",
                "oPaginate": {
                        "sFirst":    '{% trans "First"|escapejs %}',
                        "sPrevious": '{% trans "Previous"|escapejs %}',
                        "sNext":     '{% trans "Next"|escapejs %}',
                        "sLast":     '{% trans "Last"|escapejs %}'
                }
            },
            "bJQueryUI": false,
            "sPaginationType": "full_numbers",
            "aaSorting": [[ 0, "asc" ]],
            "bServerSide": true,
            "bProcessing": true,
            "iDisplayLength": 25,
            {% if resource %}
                "sAjaxSource": "{%  url stringset_handling project.slug resource.slug target_language.code %}",
            {% else %} 
                "sAjaxSource": "{%  url stringset_handling project.slug target_language.code %}",
            {% endif %}
            "sDom": '<"top"fi><"clear">rt<"bottom"pl><"clear">', 
            "bAutoWidth": false,
            "aoColumns" : [
                // Holds the Translation id (hidden)
                { "bVisible":false },
                // Holds the SourceEntity string
                { "bVisible":false, "bSortable": false, },
                // Holds the source Translation string/s mapped to the plural rules
                // It may also hold the similar language translations.
                { "sClass": "msg", "asSorting": [ "desc", "asc" ],  "sWidth": "350px",
                  "fnRender": function(oObj){
                    // Escape recursively all the strings in the array
                    var clean_array = array_escape({"key":oObj.aData[1], "source_dict":oObj.aData[2]});
                    var source_divs = '';
                    var plurals_counter = 0;
                    var plural_types = ['zero', 'one', 'two', 'few', 'many', 'other']
                    // Provide the necessary html fragment for each plural rule
                    for(rule in plural_types){
                        if(plural_types[rule] in clean_array["source_dict"]["source_strings"]){
                            if(plural_types[rule]=='other'){
                              source_divs += '<div class="source_string" id="sourcestring_'+ oObj.iDataRow +'" title="{% trans "Source string" %}">';
                              if(plurals_counter>0)
                                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" title="{% trans "Source string" %}"><span class="plural_title">'+plural_types[rule]+': </span>' + html_escape(clean_array["source_dict"]["source_strings"][plural_types[rule]]) + '</p>'
                            plurals_counter++;
                        }
                    }

                    // If we have pluralized translation row, indicate this with a label.
                    var plural_indicator = '';
                    if(plurals_counter>1)
                        plural_indicator = '<div class="plural_indicator">Pluralized Translations</div>';

                    // Concatenate the similar language translations with the
                    // html fragment which holds the source strings.
                    for(lang in clean_array["source_dict"]["similar_lang_strings"]){
                      lang_strings = "";
                      for(rule in clean_array["source_dict"]["similar_lang_strings"][lang]){
                        if(rule=='other')
                          lang_strings += '<p>' + html_escape(clean_array["source_dict"]["similar_lang_strings"][lang][rule]) + '</p>'
                        else
                          lang_strings += '<p><span class="plural_title">'+rule+': </span>' + html_escape(clean_array["source_dict"]["similar_lang_strings"][lang][rule]) + '</p>'
                      }
                      if(!lang_strings==""){
                        source_divs += '<h3 class="similar_lang_title">In '+lang+':</h3>';
                        source_divs += lang_strings;
                      }
                    }

                    // Provide the amount (number) of suggestions and a
                    // bold flag to be used in case we have empty translation
                    // textareas.
                    var suggestions_num = '';
                    if(oObj.aData[4] > 0)
                        suggestions_num = ' ('+oObj.aData[4]+')';
                    var bold_flag = false;
                    if(suggestions_num!='' && oObj.aData[3]['other']=='')
                        bold_flag = true;

                    // Concatenate the plural indicator, the (hidden) key,
                    // the source strings and the row tabs.
                    return '<div class="source_string_wrapper">'
                           + plural_indicator
                           + ' <div class="source_entity nodisplay" id="sourceentity_'+ oObj.iDataRow +'" ><span title="{% trans "Key" %}">'+ clean_array["key"] +'</span></div>'
                           + source_divs
                           + ' <div class="row_tabs">'
                           + '  <ul>'
                           + '    <li>'
                           + '     <a class="tabs_trigger show_details" href="#">{% trans "details" %}</a>'
                           + '    </li>'
                           + '    <li>'
                           + '     <a class="tabs_trigger show_suggestions" href="#">'+(bold_flag?'<strong>':'')+'{% trans "suggestions" %}'+suggestions_num+(bold_flag?'</strong>':'')+'</a>'
                           + '    </li>'
                           + '  </ul>'
                           + ' </div>'
                           + '</div>';
                  }
                },
                // Holds the target Translation string/s mapped to the plural rules
                { "sClass": "trans", "bSortable": false,  "sWidth": "350px",
                  "fnRender": function(oObj){
                      // Escape recursively all the strings in the array
                      var clean_array = array_escape({"translations":oObj.aData[3]});
                      var textareas = '';
                      var plural_types = ['zero', 'one', 'two', 'few', 'many', 'other'];
                      var plurals_counter = 0;
                      // Provide the necessary html fragment for each plural rule
                      for(rule in plural_types){
                          if(plural_types[rule] in clean_array["translations"]){
                              if(plural_types[rule]=='other'){
                                textareas += '<div class="translation_wrapper"><span class="rule nodisplay">'+plural_types[rule]+'</span><textarea class="translation default_translation" id="translation_' + oObj.iDataRow + '" title="{% trans "Fill in a new translation" %}">' + html_escape(clean_array["translations"][plural_types[rule]]) + '</textarea>';
                                if(plurals_counter>0)
                                    textareas += '<span class="plural_label tag" title="Translation plural form for '+plural_types[rule]+' items (equation: {{ target_language.rule_other}})">'+plural_types[rule]+'</span>';
                                textareas += '</div>';
                              }else{
                                textareas += '<div class="translation_wrapper"><span class="rule nodisplay">'+plural_types[rule]+'</span><textarea class="translation" title="{% trans "Fill in a new translation" %}">' + html_escape(clean_array["translations"][plural_types[rule]]) + '</textarea>';
                                if(plural_types[rule]=='zero'){
                                    textareas += '<span class="plural_label tag" title="Translation plural form for '+plural_types[rule]+' items (equation: {{ target_language.rule_zero }})">'+plural_types[rule]+'</span>';
                                }else if(plural_types[rule]=='one'){
                                    textareas += '<span class="plural_label tag" title="Translation plural form for '+plural_types[rule]+' item (equation: {{ target_language.rule_one }})">'+plural_types[rule]+'</span>';
                                }else if(plural_types[rule]=='two'){
                                    textareas += '<span class="plural_label tag" title="Translation plural form for '+plural_types[rule]+' items (equation: {{ target_language.rule_two }})">'+plural_types[rule]+'</span>';
                                }else if(plural_types[rule]=='few'){
                                    textareas += '<span class="plural_label tag" title="Translation plural form for '+plural_types[rule]+' items (equation: {{ target_language.rule_few }})">'+plural_types[rule]+'</span>';
                                }else if(plural_types[rule]=='many'){
                                    textareas += '<span class="plural_label tag" title="Translation plural form for '+plural_types[rule]+' items (equation: {{ target_language.rule_many }})">'+plural_types[rule]+'</span>';
                                }
                                textareas += '</div>';
                              }
                              plurals_counter++;
                          }
                      }

                      // Concatenate translation textareas with action buttons
                      return textareas
                      + '<div class="error_notes"></div>'
                      + '<div class="lotte-actions">'
                      + '  <p id="auto_translate_wrapper"><a class="i16 action buttonized suggest">{% trans "auto translate" %}</a></p>'
                      + '  <p id="copy_source_wrapper"><a class="i16 next buttonized copy_source">{% trans "copy source" %}</a></p>'
                      + '</div>';
                    }
                },
                // Holds the amount of Suggestions provided for this source string/s
                { "bVisible":false, "bSortable": false, },
                // Holds an HTML snippet for save, undo buttons and hidden context
                { "sClass": "notes", "bSortable": false, "bVisible":true, "sWidth": "40px",}
            ],
            "fnServerData": function (sSource, aoData, fnCallback) {

              /*
               * Here we issue the AJAX request to get the table data and
               * then we create the StringSet object which holds all the 
               * Translation objects in memory.
              */

              // Show the loading indicator
              $("div#notification-container div").html('{% trans "Loading strings..."|escapejs %}');
              $("div#notification-container").fadeIn("slow");

              // Add filtering parameters to the POST data dictionary
              if (filter_var) {
                aoData.push( { "name" : "filters", "value": filter_var});
              }
              if (user_filters_values){
                aoData.push( { "name" : "user_filters", "value": user_filters_values});
              }
              if (resource_filters_values){
                aoData.push( { "name" : "resource_filters", "value": resource_filters_values});
              }
              if (more_languages_values){
                aoData.push( { "name" : "more_languages", "value": more_languages_values});
              }

              // Issue the actual AJAX request to fetch the data to be rendered.
              $.ajax ( {
                  "dataType": 'json',
                  "type": "POST",
                  "url": sSource,
                  "data": aoData,
                  "complete": function(xmlhttpreq, status) {

                    /*
                     * When we have the data, create the Stringset instance and
                     * trigger the fnDrawCallback to render one by one the rows!
                    */

                    var parsed_data = JSON.parse(xmlhttpreq.responseText);
                    var push_url = '{% url push_translation project.slug target_language.code %}';

                    // Fill the statistics variable
                    if ( stringset ) {
                        // Modified strings should be saved or dropped on page change.
                        translated = stringset.translated; // - stringset.translated_modified;
                        untranslated = stringset.untranslated; // - stringset.untranslated_modified;
                    } else { 
                        translated = translated_strings;
                        untranslated = untranslated_strings;
                    }

                    // Create StringSet instance
                    stringset = new StringSet(parsed_data, push_url, '{{resource.source_language}}', '{{target_language.code}}');
                    stringset.translated = translated;
                    stringset.untranslated = untranslated;

                    // Draw the table
                    fnCallback(parsed_data);

                    // Hide the loading indicator
                    setTimeout('$("div#notification-container").fadeOut();',1000);

                    }
                  });

             },
            "fnDrawCallback": function() {

                // Put the table object as an class attribute in StringSet.
                stringset.bindToTable("stringset_table");

                // Draw the colors for textareas and hide/show save buttons
                stringset.updateColors_Buttons();
                
                // Enable the onkeyup mark as modified and show save button
                stringset.bindKeyupTextArea();

                // Enable the onfocus "make current in StringSet"
                stringset.bindFocusTextArea();

                if ($("#toggle_autosave").is(":checked")){ 
                    // Enable the save button push upstream.
                    stringset.unbindSaveButton();
                    stringset.bindBlurTextArea();
                } else { 
                    stringset.unbindBlurTextArea();
                    stringset.bindSaveButton();
                }

                // Enable the undo button.
                stringset.bindUndoButton();

                if ($("#toggle_verbose").is(":checked")){ 
                    // Enable the save button push upstream.
                    $('.source_entity').show();
                } else { 
                    $('.source_entity').hide();
                }

                // Statistics and filtering by flag table 
                stringset.bindStatsAndFilter("stats_table");
                stringset.updateStats(); /* Update statistics */

                // Bind toolbar
                stringset.toolbar();

                stringset.current_box = null;

                // Highlight source strings.
                $('.source_string, .source_string_plural').whitespaceHighlight();

                // Auto expanding textareas.
                $("textarea.translation").TextAreaExpander();
            }
        }).fnSetFilteringDelay(500);

        /* move to the next page */
        shortcut.add('Alt+l', function(evt) {
            if ( stringset.current_box ) {
                stringset.current_box.blur();
            }
            oTable.fnPageChange('next');
        },{
            'type':'keydown',
        });
        /* move to the previous page */
        shortcut.add('Alt+j', function(evt) {
            if ( stringset.current_box ) {
                stringset.current_box.blur();
            }
            oTable.fnPageChange('previous')
        },{
            'type':'keydown',
        });
        /* move up in the trans boxes */
        shortcut.add('Alt+i', function(evt) {
            if ( ! stringset.current_box ) {
                $("#stringset_table").find('tr:not(.metatr):last-child').find('textarea.default_translation').focus();
            } else { 
                stringset.current_box.blur();
                stringset.current_box.parents('.trans').parent().prevAll(':not(.metatr):first').find('textarea.default_translation').focus();
            }
        },{
            'type':'keydown',
        });
        /* move down in the trans boxes */
        shortcut.add('Alt+k', function(evt) {
            if ( ! stringset.current_box ) {
                $("#stringset_table").find('tr:not(.metatr):nth-child(1)').find('textarea.default_translation').focus();
            } else { 
                stringset.current_box.blur();
                stringset.current_box.parents('.trans').parent().nextAll(':not(.metatr):first').find('textarea.default_translation').focus();
            }
        },{
            'type':'keydown',
        });
        /* copy source */
        shortcut.add('Alt+g', function(evt) {
            if ( ! stringset.current_box ) {
                return false;
            }
            // Trigger the copy source action
            stringset.current_box.parents('.trans').find(".copy_source").click();
        });
        /* auto translate */
        shortcut.add('Alt+t', function(evt) {
            if ( ! stringset.current_box ) {
                return false;
            }
            // Trigger the auto translate action
            stringset.current_box.parents('.trans').find(".suggest").click();
        });

        /* SETTINGS togglers */
        $("#toggle_verbose").click( function() {
            if ($(this).is(":checked")){ 
                $('.source_entity').show();
            } else { 
                $('.source_entity').hide();
            }
        });

        /* Toggle autosave of textarea value */
        $("#toggle_autosave").click( function() {
            if ($(this).is(":checked")){ 
                stringset.unbindSaveButton();
                stringset.bindBlurTextArea();
                stringset.push();
                alert('{% trans "Translation text will be saved automatically."|escapejs %}');
            } else { 
                stringset.unbindBlurTextArea();
                stringset.bindSaveButton();
                alert('{% trans "Translation text will no longer be saved automatically."|escapejs %}');
            }
        });

        /* Save at once all the changed translation values */
        $("#save_all_2").click(function(){ stringset.push(); });

        {% if is_maintainer or request.user.is_superuser%}
        /* Delete at once all the translations in this page */
        $("#delete_all_2").click(function(){ delete_these(); });
        function delete_these(){
            var to_delete = [];
            for (j=0; j<this_stringset.strings.length; j++) {
                if(this_stringset.strings[j].isTranslated())
                to_delete.push( $("span#sourceid_"+j).text() );
            }
            if(to_delete.length == 0){
                alert('{% trans "This page does not have any translations (to delete)!"|escapejs %}');
            }else if(confirm("{% trans 'This action will delete all translations in this page. Are you sure you want to proceed?' %}")){
                {% if resource %}
                var delete_url = '{% url delete_translation project.slug resource.slug target_language.code %}';
                {% else %}
                var delete_url = '{% url delete_translation project.slug target_language.code %}';
                {% endif %}
                
                $.ajax({
                    url: delete_url,
                    data: JSON.stringify({to_delete: to_delete}), 
                    dataType : "text", // "json" is strict and we get 500
                    type: "POST",
                    contentType: "application/json",
                    success: function(){
                        stringset.translated -= to_delete.length;
                        stringset.untranslated += to_delete.length;
                        oTable.fnDraw();
                    }
                });
            }
        }
        {% endif %}

        /* Save all the updated translation and exit Lotte */
        $("#save_and_exit").click(function(){
            {% if resource_slug %}
                {% url exit_lotte resource.project.slug resource_slug target_language.code as url_exit_lotte %}
            {% else%}
                {% url exit_lotte resource.project.slug target_language.code as url_exit_lotte %}
            {% endif %}

            //Save & exit
            stringset.push(
                false,
                function(updated){
                    $.ajax({
                        url: "{{ url_exit_lotte }}",
                        data: JSON.stringify({updated:updated}),
                        dataType : "json",
                        type: "POST",
                        contentType: "application/json",
                        success: function(data, textStatus) {
                            if (textStatus=='success'){
                                window.location = data['redirect'];
                            }
                        }
                    });
                });
        });


        /* Wrapper ... to be DRY */
        function traverse_filters(){
            filter_var = "";
            $(".filters").each( function() {
                if (! $(this).attr('checked')) {
                    filter_var += $(this).attr('id')+',';
                }
            });
            user_filters_values = "";
            // Parse one by one to reuse the older applied filters
            $(".user_filters").each( function() {
                if ($(this).attr('checked')) {
                    user_filters_values += $(this).attr('id')+',';
                }
            });
            resource_filters_values = "";
            // Parse one by one to reuse the older applied filters
            $(".resource_filters").each( function() {
                if ($(this).attr('checked')) {
                    resource_filters_values += $(this).attr('id')+',';
                }
            });
            more_languages_values = "";
            // Parse one by one to reuse the older applied filters
            $(".more_languages").each( function() {
                if ($(this).attr('checked')) {
                    more_languages_values += $(this).attr('id')+',';
                }
            });
            oTable.fnDraw();
        }

        /* Bind checkbox change event  for translated/untranslated */
        // Just a extra check for IE8 (this will be fixed with jQuery 1.4)
        $(".filters").bind($.browser.msie ? 'propertychange': 'change',
            function(e) {
            if (e.type == "change" || (e.type == "propertychange" &&
                                       window.event.propertyName == "checked")) {
                traverse_filters();
            }
        });

        /* Bind checkbox change event for user filters*/
        // Just a extra check for IE8 (this will be fixed with jQuery 1.4)
        $(".user_filters").bind($.browser.msie ? 'propertychange': 'change',
            function(e) {
            if (e.type == "change" || (e.type == "propertychange" &&
                                       window.event.propertyName == "checked")) {
                traverse_filters();
            }
        });

        /* Bind checkbox change event for resource filters*/
        // Just a extra check for IE8 (this will be fixed with jQuery 1.4)
        $(".resource_filters").bind($.browser.msie ? 'propertychange': 'change',
            function(e) {
            if (e.type == "change" || (e.type == "propertychange" &&
                                       window.event.propertyName == "checked")) {
                traverse_filters();
            }
        });

        /* Bind checkbox change event for more languages*/
        // Just a extra check for IE8 (this will be fixed with jQuery 1.4)
        $(".more_languages").bind($.browser.msie ? 'propertychange': 'change',
            function(e) {
            if (e.type == "change" || (e.type == "propertychange" &&
                                       window.event.propertyName == "checked")) {
                traverse_filters();
            }
        });

        /* Bind menu filters for more languages */
        $('#filtermenu0 .filtermenu-trigger').toggle(function(){
            $('#more_languages_menu').show();
        }, function(){
            $('#more_languages_menu').hide();
        });

        /* Bind menu filters for users */
        $('#filtermenu1 .filtermenu-trigger').toggle(function(){
            $('#filtermenu_users').show();
        }, function(){
            $('#filtermenu_users').hide();
        });

        {% ifnotequal resources|length 1 %}
        /* Bind menu filters for resources */
        $('#filtermenu2 .filtermenu-trigger').toggle(function(){
            $('#filtermenu_resources').show();
        }, function(){
            $('#filtermenu_resources').hide();
        });
        {% endifnotequal %}

        $("#settingspanel a:first").click(function() {
            if($(this).next(".subpanel").is(':visible')){ //If subpanel is already active...
                $(this).next(".subpanel").hide(); //Hide active subpanel
                $("#footpanel li a").removeClass('active'); //Remove active class on the subpanel trigger
            }
            else { //if subpanel is not active...
                $(".subpanel").hide(); //Hide all subpanels
                $(this).next(".subpanel").toggle(); //Toggle the subpanel to make active
                $("#footpanel li a").removeClass('active'); //Remove active class on all subpanel trigger
                $(this).toggleClass('active'); //Toggle the active class on the subpanel trigger
            }
            return false; //Prevent browser jump to link anchor
        });

        //Click event outside of subpanel
        $(document).click(function() { //Click anywhere and...
            $(".subpanel").hide(); //hide subpanel
            $("#footpanel li a").removeClass('active'); //remove active class on subpanel trigger
        });
        $('.subpanel ul').click(function(e) {
            e.stopPropagation(); //Prevents the subpanel ul from closing on click
        });

        // Enable tooltips with tipsy
        $(".tipsy_enable").tipsy({'html':true, 'gravity':'s'});

    });

    });

</script>


{% endblock %}

{% block title %}
{{ block.super }} | 
{{resource}}
{% endblock %}

{% block body_class %}project_list{% endblock %}

{% block content_header_sec %}
  {% url search_translations as search_translations %}
  <p class="i16 view nomargin"><a href="{{ search_translations }}" target="_new" title="{% trans "Search in Transifex memory for existing translations (uses a new tab/window)" %}">
    {% trans "Search translations" %}</a>
  </p>
{% endblock %}

{% block content_main %}
{% get_permission "project_perm.maintain" for request.user and resource.project as "is_maintainer" %}

<div class="floatright filtermenu-wrapper">

  <div id="filtermenu0" class="filtermenu tipsy_enable" title="{% trans "Show translations in<br /> the selected languages" %}">
    <a class="filtermenu-trigger buttonized" href="#">
    <span class="filtermenu-icon"> </span>
    <span class="filtermenu-title">{% trans "More languages" %}</span>
    </a>
  </div>
  {% include "more_languages.html" %}

  <div id="filtermenu1" class="filtermenu tipsy_enable" title="{% trans "Show only the translations<br /> by the selected users" %}">
    <a class="filtermenu-trigger buttonized" href="#">
    <span class="filtermenu-icon"> </span>
    <span class="filtermenu-title">{% trans "Filter by users" %}</span>
    </a>
  </div>
  {% include "filters_menu_users.html" %}

  {% ifnotequal resources|length 1 %}
  <div id="filtermenu2" class="filtermenu tipsy_enable" title="{% trans "Show only the strings from<br /> the selected resources." %}">
    <a class="filtermenu-trigger buttonized" href="#">
    <span class="filtermenu-icon"> </span>
    <span class="filtermenu-title">{% trans "Filter by resources" %}</span>
    </a>
  </div>
  {% include "filters_menu_resources.html" %}
  {% endifnotequal %}

</div>

  <table class="definition stats_totals" id="stats_table">
  <input id="filter_entries" type="hidden" name="filter_entries"/>
  {% with untranslated_strings|add:translated_strings as total_strings %}
  <tr>
    <th class="translated">{% trans "Translated" %}</th>

      <td id="total_translated">{{ translated_strings }}</td>
      <td id="total_translated_perc">?</td>
      <td><input id="translated" class="filters" type="checkbox"  checked="checked"  name="only_translated"/></td>
  </tr>

  <tr>
    <th class="untranslated">{% trans "Untranslated" %}</th>
      <td id="total_untranslated">{{ untranslated_strings }} </td>
      <td id="total_untranslated_perc">?</td>

      <td><input id="untranslated" class="filters" type="checkbox" checked="checked" name="only_untranslated"/></td>
  </tr>
  <tr>
    <th class="fuzzy">{% trans "Modified" %}</th>
      <td id="total_fuzzy">0</td>
      <td id="total_fuzzy_perc">0.00%</td>
  </tr>
  <tr class="last">
    <th>{% trans "Total" %}</th>
      <td id="total_sum">{{ total_strings }}</td>
  </tr>
  {% endwith %}
  </table>



<table id='stringset_table'>
    <thead>
        <tr>
        <th></th>
        <th></th>
        <th>{% trans "Source String" %}</th>
        <th>{% trans "Translation" %}</th>
        <th></th>
        <th>&nbsp;</th>
        </tr>
    </thead>
</table>

<div id="footer_lotte">
    <a id="save_all_2" class="i16 save_all buttonized2">{% trans 'Save all' %}</a>

    {% if is_maintainer or request.user.is_superuser %}
    &nbsp;&nbsp;<a id="delete_all_2" class="i16 delete buttonized2">{% trans 'Delete translations' %}</a>
    {% endif %}
    &nbsp;&nbsp;<a id="save_and_exit" class="i16 save buttonized2">{% trans 'Save and Exit' %}</a>
</div>

<div id="footpanel">
    <ul id="mainpanel">
        <li id="settingspanel">
            <a href="#" class="settings">{% trans "General Settings" %}</a>
            <div class="subpanel">
                <ul>
                    <li class="verbose">
                        <input id="toggle_verbose" type="checkbox" />
                        <span>{% trans "Verbose editing" %}</span>
                    </li>
                    <li class="auto_save">
                        <input id="toggle_autosave" type="checkbox" />
                        <span>{% trans "Auto save" %}</span>
                    </li>
                </ul>
            </div>
        </li>
    </ul>
</div>

{% endblock %}

{% block content_footer %}
{% endblock %}