Seraphim Mellos avatar Seraphim Mellos committed 1f63019

Half done work for lotte warnings

Comments (0)

Files changed (3)

transifex/addons/lotte/media/js/tx.lotte2.js

 
     // Method for pushing one or more TranslationStrings of this StringSet
     this.push = function(ts, callback) {
+		var messages = false;
         this_stringset = this;
         var to_update = [];
         if (ts) { /* Pushing one TranslationString instance */
                             ts.previous = jQuery.extend(true, {}, ts.translated_strings);
                             
                             // Hide the error div if it is visible
-                            this_stringset.current_box.parents('td.trans').find('div.error_notes').hide();
+                            if ( json_response_dict[ts.id]['message'] != null ) {
+								messages=true;
+								this_stringset.current_box.parents('td.trans').find('div.error_notes').text(json_response_dict[ts.id]['message']);
+								this_stringset.current_box.parents('td.trans').find('div.error_notes').show();
+							} else
+								this_stringset.current_box.parents('td.trans').find('div.error_notes').hide();
                         }else{ // Handle the error
                             this_stringset.current_box.parents('td.trans').find('div.error_notes').text(json_response_dict[ts.id]['message']);
                             this_stringset.current_box.parents('td.trans').find('div.error_notes').show();
                                     // Hide the error div if it is visible
                                     $('textarea#translation_'+j).parents('td.trans').find('div.error_notes').hide();
                                 }else{ // Handle the error
+									messages=true;
                                     $('textarea#translation_'+j).parents('td.trans').find('div.error_notes').text(json_response_dict[this_stringset.strings[j].id]['message']);
                                     $('textarea#translation_'+j).parents('td.trans').find('div.error_notes').show();
                                 }
                 }
             });
         }
-        if (typeof callback === 'function')
-            callback(lotteStatus.updated);
+        if (typeof callback === 'function') {
+			if ( ! messages )
+				callback(lotteStatus.updated);
+			else
+				alert("There were a few warnings or errors. Check them out before exiting lotte.");
+		}
     }
 
 

transifex/addons/lotte/templates/translate.html

                         dataType : "json",
                         type: "POST",
                         contentType: "application/json",
-                        complete: function(xmlhttpreq, textStatus) {
+                        success: function(xmlhttpreq, textStatus) {
                             if (textStatus=='success'){
                                 response = JSON.parse(xmlhttpreq.responseText);
                                 window.location = response['redirect'];

transifex/addons/lotte/views.py

             ss = unescape(source_string.string)
             tr = unescape(string)
 
-            # Check whether the translation sting only contains spaces
+                    # Check whether the translation sting only contains spaces
             if tr and len(tr.strip()) == 0:
-                push_response_dict[source_id] = { 'status':500,
+                push_response_dict[source_id] = { 'status':200,
                     'message':_("Translation string only contains whitespaces.")}
-                continue
 
             # Test that the number of {[()]} appearing in each string are the
             # same
             try:
                 for char in '[{()}]':
                     if tr and ss.count(char) != tr.count(char):
-                        push_response_dict[source_id] = { 'status':500,
+                        push_response_dict[source_id] = { 'status':200,
                         'message':_("Translation string doesn't contain the same"
                         " number of '%s' as the source string." % char )}
                         raise StopIteration
             except StopIteration:
-                continue
-
+                pass
             # Scan for urls and see if they're in both strings
             urls = re.compile(r'(\S+?://\S+)')
             try:
                 for url in urls.findall(ss):
                     if tr and url not in tr:
-                        push_response_dict[source_id] = { 'status':500,
+                        push_response_dict[source_id] = { 'status':200,
                         'message':_("The following url is either missing form the"
                         " translation os has been translated: '%s'." % url)}
                         raise StopIteration
             except StopIteration:
-                continue
+                pass 
 
             # Scan for urls and see if they're in both strings
             emails = re.compile("([\w\-\.+]+@[\w\w\-]+\.+[\w\-]+)")
             try:
                 for email in emails.findall(ss):
                     if tr and email not in tr:
-                        push_response_dict[source_id] = { 'status':500,
+                        push_response_dict[source_id] = { 'status':200,
                         'message':_("The following email is either missing form the"
                         " translation os has been translated: '%s'." % email)}
                         raise StopIteration
             except StopIteration:
-                continue
+                pass 
 
             # Check whether source string and translation start and end
             # with newlines
             if string and ss.startswith('\n') != tr.startswith('\n'):
                 if ss.endswith('\n'):
-                    push_response_dict[source_id] = { 'status':500,
+                    push_response_dict[source_id] = { 'status':200,
                     'message':_("Translation must start with a newline (\\n)")}
                 else:
-                    push_response_dict[source_id] = { 'status':500,
+                    push_response_dict[source_id] = { 'status':200,
                     'message':_("Translation should not start with a newline (\\n)")}
-                continue
+                pass
             elif string and ss.endswith('\n') != tr.endswith('\n'):
                 if ss.endswith('\n'):
-                    push_response_dict[source_id] = { 'status':500,
+                    push_response_dict[source_id] = { 'status':200,
                     'message':_("Translation must end with a newline (\\n)")}
                 else:
-                    push_response_dict[source_id] = { 'status':500,
+                    push_response_dict[source_id] = { 'status':200,
                     'message':_("Translation should not end with a newline (\\n)")}
-                continue
+                pass
 
             # Check the numbers inside the string
             numbers = re.compile("[-+]?[0-9]*\.?[0-9]+")
             try:
                 for num in numbers.findall(source_string.string):
                     if string and num not in string:
-                        push_response_dict[source_id] = { 'status':500,
+                        push_response_dict[source_id] = { 'status':200,
                             'message':_("Number %s is in the source string but not "\
                             "in the translation." % num )}
                         raise StopIteration
             except StopIteration:
-                continue
+                pass
 
             # Check printf variables
             printf_pattern = re.compile('%((?:(?P<ord>\d+)\$|\((?P<key>\w+)\))'\
             ss_matches = list(printf_pattern.finditer(source_string.string))
             tr_matches = list(printf_pattern.finditer(string))
 
+            # Check number of printf variables
+            if string and len(printf_pattern.findall(source_string.string)) != \
+                len(printf_pattern.findall(string)):
+                push_response_dict[source_id] = { 'status':500,
+                    'message':_('The number of arguments seems to differ '
+                        'between the source string and the translation.')}
+                continue
+
             try:
                 for pattern in ss_matches:
                     if string and pattern.group(0) not in string:
-                        push_response_dict[source_id] = { 'status':500,
+                        push_response_dict[source_id] = { 'status':200,
                             'message':_('The expression \'%s\' is not present '\
                             'in the translation.' % pattern.group(0) )}
                         raise StopIteration
             try:
                 for pattern in tr_matches:
                     if string and pattern.group(0) not in source_string.string:
-                        push_response_dict[source_id] = { 'status':500,
+                        push_response_dict[source_id] = { 'status':200,
                             'message':_('The expression \'%s\' is not present '\
                             'in the source string.' % pattern.group(0) )}
             except StopIteration:
-                continue
+                pass
 
-            # Check number of printf variables
-            if string and len(printf_pattern.findall(source_string.string)) != \
-                len(printf_pattern.findall(string)):
-                push_response_dict[source_id] = { 'status':500,
-                    'message':_('The number of arguments seems to differ '
-                        'between the source string and the translation.')}
-                continue
 
             try:
                 # TODO: Implement get based on context and/or on context too!
 
                 invalidate_stats_cache(source_string.source_entity.resource,
                     target_language, user=request.user)
-
-                push_response_dict[source_id] = { 'status':200,
-                     'message':_("Translation updated successfully in the DB")}
+                if not push_response_dict.has_key(source_id):
+                    push_response_dict[source_id] = { 'status':200}
             except Translation.DoesNotExist:
                 # Only create new if the translation string sent, is not empty!
                 if string != "":
                         user = request.user) # Save the sender as last committer
                     invalidate_stats_cache(source_string.source_entity.resource,
                         target_language, user=request.user)
-                    push_response_dict[source_id] = { 'status':200,
-                         'message':_("New translation stored successfully in the DB")}
+                    if not push_response_dict.has_key(source_id):
+                        push_response_dict[source_id] = { 'status':200}
                 else:
                     push_response_dict[source_id] = { 'status':500,
                          'message':_("The translation string is empty")}
                 push_response_dict[source_id] = { 'status':500,
                     'message':_("Error occurred while trying to save translation.")}
 
+    print push_response_dict
     json_dict = simplejson.dumps(push_response_dict)
     return HttpResponse(json_dict, mimetype='application/json')
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.