diff --git a/CHANGES b/CHANGES index 7a12e09..ddd0d82 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ +Version 0.6.6 +------------- +* Django 1.4 support (Issue #30, #33) +* Better handling of translation callbacks on Bing's translation API and support of composite locales (Issue #26) + Version 0.6.5 ------------- * Updated polib to 0.7.0 diff --git a/rosetta/__init__.py b/rosetta/__init__.py index 1095f4c..12e3b11 100644 --- a/rosetta/__init__.py +++ b/rosetta/__init__.py @@ -1,4 +1,4 @@ -VERSION = (0, 6, 5) +VERSION = (0, 6, 6) def get_version(svn=False, limit=3): diff --git a/rosetta/poutil.py b/rosetta/poutil.py index 05637da..dc1483b 100644 --- a/rosetta/poutil.py +++ b/rosetta/poutil.py @@ -31,28 +31,24 @@ def find_pos(lang, project_apps=True, django_apps=False, third_party_apps=False) django_paths = cache.get('rosetta_django_paths') if django_paths is None: django_paths = [] - for root,dirnames,filename in os.walk(os.path.abspath(os.path.dirname(django.__file__))): + for root, dirnames, filename in os.walk(os.path.abspath(os.path.dirname(django.__file__))): if 'locale' in dirnames: - django_paths.append(os.path.join(root , 'locale')) + django_paths.append(os.path.join(root, 'locale')) continue - cache.set('rosetta_django_paths', django_paths, 60*60) + cache.set('rosetta_django_paths', django_paths, 60 * 60) paths = paths + django_paths - - - # settings + # settings for localepath in settings.LOCALE_PATHS: if os.path.isdir(localepath): paths.append(localepath) - + # project/app/locale for appname in settings.INSTALLED_APPS: - if rosetta_settings.EXCLUDED_APPLICATIONS and appname in rosetta_settings.EXCLUDED_APPLICATIONS: continue - p = appname.rfind('.') if p >= 0: - app = getattr(__import__(appname[:p], {}, {}, [appname[p+1:]]), appname[p+1:]) + app = getattr(__import__(appname[:p], {}, {}, [appname[p + 1:]]), appname[p + 1:]) else: app = __import__(appname, {}, {}, []) diff --git a/rosetta/templates/rosetta/css/rosetta.css b/rosetta/templates/rosetta/css/rosetta.css index 1fff0cf..763ac45 100644 --- a/rosetta/templates/rosetta/css/rosetta.css +++ b/rosetta/templates/rosetta/css/rosetta.css @@ -32,4 +32,5 @@ div.module {margin-bottom: 20px;} .checkall {cursor:pointer} #toolbar { height:20px} #toolbar #translate-all { float:right} -#toolbar form { float:left; } \ No newline at end of file +#toolbar form { float:left; } +#changelist table thead th { padding: 2px 5px; } \ No newline at end of file diff --git a/rosetta/templates/rosetta/js/rosetta.js b/rosetta/templates/rosetta/js/rosetta.js index 74b3162..4399177 100644 --- a/rosetta/templates/rosetta/js/rosetta.js +++ b/rosetta/templates/rosetta/js/rosetta.js @@ -1,56 +1,48 @@ +{% load rosetta %} + google.setOnLoadCallback(function() { $('.location a').show().toggle(function() { $('.hide', $(this).parent()).show(); }, function() { $('.hide', $(this).parent()).hide(); }); + {% if ENABLE_TRANSLATION_SUGGESTIONS and BING_APP_ID %} - $('a.suggest').click(function() { - var a = $(this), - str = a.html(), - orig = $('.original .message', a.parents('tr')).html(), - trans=$('textarea',a.parent()), - sourceLang = '{{MESSAGES_SOURCE_LANGUAGE_CODE}}', - destLang = '{{rosetta_i18n_lang_code|slice:":2"}}', - app_id = '{{BING_APP_ID}}'; - - orig = unescape(orig).replace(//g,'\n').replace(//g,'').replace(/<\/code>/g,'').replace(/>/g,'>').replace(/</g,'<'); + $('a.suggest').click(function(e){ + e.preventDefault(); + var a = $(this); + var str = a.html(); + var orig = $('.original .message', a.parents('tr')).html(); + var trans=$('textarea',a.parent()); + var sourceLang = '{{ MESSAGES_SOURCE_LANGUAGE_CODE }}'; + var destLang = '{{ rosetta_i18n_lang_code }}'; + var app_id = '{{ BING_APP_ID }}'; + var apiUrl = "http://api.microsofttranslator.com/V2/Ajax.svc/Translate"; + + orig = unescape(orig).replace(//g,'\n').replace(//,'').replace(/<\/code>/g,'').replace(/>/g,'>').replace(/</g,'<'); a.attr('class','suggesting').html('...'); window.onTranslationComplete = function(resp) { trans.val(unescape(resp).replace(/'/g,'\'').replace(/"/g,'"').replace(/%\s+(\([^\)]+\))\s*s/g,' %$1s ')); a.hide(); - }; - var s = document.createElement("script"); - s.src = "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?oncomplete=onTranslationComplete&appId="+app_id +"&from=" + sourceLang + "&to=" + destLang + "&text=" + orig; - document.getElementsByTagName("head")[0].appendChild(s); - - /* - google.language.translate(orig, , function(result) { - if (!result.error) { - trans.val(unescape(result.translation).replace(/'/g,'\'').replace(/"/g,'"').replace(/%\s+(\([^\)]+\))\s*s/g,' %$1s ')); - a.hide(); - } else { - a.hide().before($(''+result.error.message+'')); - } - }); - */ - return false; + window.onTranslationError = function(response){ + a.text(response); + }; + var apiData = { + onerror: 'onTranslationError', + appid: app_id, + from: sourceLang, + to: destLang, + oncomplete: "onTranslationComplete", + text: orig + }; + $.ajax({ + url: apiUrl, + data: apiData, + dataType: 'jsonp'}); }); - - - $('#translate-all').submit(function() { - $('a.suggest').click(); - return false; - }); - $('.checkall').click(function(){ - $('td.c input').attr('checked', ''); - $('td.c input').attr('value', '0'); - }); - - - {% endif %} + $('td.plural').each(function(i) { var td = $(this), trY = parseInt(td.closest('tr').offset().top); $('textarea', $(this).closest('tr')).each(function(j) { diff --git a/rosetta/templates/rosetta/pofile.html b/rosetta/templates/rosetta/pofile.html index b7f9edc..5e8405d 100644 --- a/rosetta/templates/rosetta/pofile.html +++ b/rosetta/templates/rosetta/pofile.html @@ -49,7 +49,7 @@