mirror of
https://github.com/Hopiu/django-rosetta.git
synced 2026-05-16 09:03:08 +00:00
wip cleanup
This commit is contained in:
parent
c1af148e59
commit
6ac75be721
5 changed files with 79 additions and 29 deletions
|
|
@ -14,7 +14,7 @@
|
|||
<script type="text/javascript">
|
||||
//<!--
|
||||
google.load("jquery", "1.3");
|
||||
{% if ENABLE_TRANSLATION_SUGGESTIONS %}google.load("language", "1");{% endif %}
|
||||
{% if rosetta_settings.ENABLE_TRANSLATION_SUGGESTIONS %}google.load("language", "1");{% endif %}
|
||||
{% include 'rosetta/js/rosetta.js' %}
|
||||
//-->
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -7,16 +7,16 @@ google.setOnLoadCallback(function() {
|
|||
$('.hide', $(this).parent()).hide();
|
||||
});
|
||||
|
||||
{% if ENABLE_TRANSLATION_SUGGESTIONS and BING_APP_ID %}
|
||||
{% if rosetta_settings.ENABLE_TRANSLATION_SUGGESTIONS and rosetta_settings.BING_APP_ID %}
|
||||
$('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 sourceLang = '{{ rosetta_settings.MESSAGES_SOURCE_LANGUAGE_CODE }}';
|
||||
var destLang = '{{ rosetta_i18n_lang_code }}';
|
||||
var app_id = '{{ BING_APP_ID }}';
|
||||
var app_id = '{{ rosetta_settings.BING_APP_ID }}';
|
||||
var apiUrl = "http://api.microsofttranslator.com/V2/Ajax.svc/Translate";
|
||||
|
||||
orig = unescape(orig).replace(/<br\s?\/?>/g,'\n').replace(/<code>/,'').replace(/<\/code>/g,'').replace(/>/g,'>').replace(/</g,'<');
|
||||
|
|
@ -50,7 +50,7 @@ google.setOnLoadCallback(function() {
|
|||
$($('.part',td).get(j)).css('top',textareaY + 'px');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
$('.translation textarea').blur(function() {
|
||||
if($(this).val()) {
|
||||
$('.alert', $(this).parents('tr')).remove();
|
||||
|
|
@ -70,7 +70,7 @@ google.setOnLoadCallback(function() {
|
|||
} else {
|
||||
if (!(origs === null && trads === null)) {
|
||||
$(this).before(error);
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
@ -78,5 +78,5 @@ google.setOnLoadCallback(function() {
|
|||
});
|
||||
|
||||
$('.translation textarea').eq(0).focus();
|
||||
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
{% endblock %}
|
||||
|
||||
{% block pagetitle %}{{block.super}} - {{MESSAGES_SOURCE_LANGUAGE_NAME}} - {{rosetta_i18n_lang_name}} ({{ rosetta_i18n_pofile.percent_translated|floatformat:0 }}%){% endblock %}
|
||||
{% block pagetitle %}{{block.super}} - {{rosetta_settings.MESSAGES_SOURCE_LANGUAGE_NAME}} - {{rosetta_i18n_lang_name}} ({{ rosetta_i18n_pofile.percent_translated|floatformat:0 }}%){% endblock %}
|
||||
|
||||
{% block breadcumbs %}
|
||||
<div>
|
||||
|
|
@ -33,15 +33,15 @@
|
|||
|
||||
<ul class="object-tools">
|
||||
<li class="nobubble">{% trans "Display:" %}</li>
|
||||
<li {% ifequal rosetta_i18n_filter 'untranslated' %}class="active"{% endifequal %}><a href="?filter=untranslated">{% trans "Untranslated only" %}</a></li>
|
||||
<li {% ifequal rosetta_i18n_filter 'translated' %}class="active"{% endifequal %}><a href="?filter=translated">{% trans "Translated only" %}</a></li>
|
||||
<li {% ifequal rosetta_i18n_filter 'fuzzy' %}class="active"{% endifequal %}><a href="?filter=fuzzy">{% trans "Fuzzy only" %}</a></li>
|
||||
<li {% ifequal rosetta_i18n_filter 'all' %}class="active"{% endifequal %}><a href="?filter=all">{% trans "All" %}</a></li>
|
||||
<li {% if rosetta_i18n_filter == 'untranslated' %}class="active"{% endif %}><a href="?filter=untranslated">{% trans "Untranslated only" %}</a></li>
|
||||
<li {% if rosetta_i18n_filter == 'translated' %}class="active"{% endif %}><a href="?filter=translated">{% trans "Translated only" %}</a></li>
|
||||
<li {% if rosetta_i18n_filter == 'fuzzy' %}class="active"{% endif %}><a href="?filter=fuzzy">{% trans "Fuzzy only" %}</a></li>
|
||||
<li {% if rosetta_i18n_filter == 'all' %}class="active"{% endif %}><a href="?filter=all">{% trans "All" %}</a></li>
|
||||
</ul>
|
||||
<div id="changelist" class="module{% if rosetta_i18n_lang_bidi %} rtl{% endif %}">
|
||||
<div id="toolbar">
|
||||
<form id="changelist-search" action="" method="post">
|
||||
<div><!-- DIV needed for valid HTML -->
|
||||
<div>
|
||||
{% rosetta_csrf_token %}
|
||||
<label for="searchbar"><img src="{{ADMIN_IMAGE_DIR}}/icon_searchbox.png" alt="{% trans "Search" %}" /></label>
|
||||
<input type="text" size="40" name="query" value="{% if query %}{{query}}{% endif %}" id="searchbar" tabindex="0" />
|
||||
|
|
@ -49,7 +49,7 @@
|
|||
</div>
|
||||
</form>
|
||||
{% comment %}
|
||||
{% if ENABLE_TRANSLATION_SUGGESTIONS %}
|
||||
{% if rosetta_settings.ENABLE_TRANSLATION_SUGGESTIONS %}
|
||||
<form id="translate-all">
|
||||
<div>
|
||||
<input type="submit" class="googleall" value="{% trans "Suggest All Translations" %}" />
|
||||
|
|
@ -110,7 +110,7 @@
|
|||
{% if main_language %}<td class="original">{{ message.main_lang|format_message|linebreaksbr }}</td>{% endif %}
|
||||
<td class="translation">
|
||||
<textarea rows="{{message.msgid|format_message|lines_count}}" cols="40" name="m_{{message.md5hash}}" tabindex="{% increment tab_idx %}">{{message.msgstr}}</textarea>
|
||||
{% if ENABLE_TRANSLATION_SUGGESTIONS %}<a href="#" class="suggest">{% trans "suggest" %}</a>{% endif %}
|
||||
{% if rosetta_settings.ENABLE_TRANSLATION_SUGGESTIONS %}<a href="#" class="suggest">{% trans "suggest" %}</a>{% endif %}
|
||||
</td>
|
||||
{% endif %}
|
||||
<td class="c">
|
||||
|
|
@ -139,15 +139,15 @@
|
|||
{% if needs_pagination %}
|
||||
{% trans "Skip to page:" %}
|
||||
{% for i in page_range %}
|
||||
{% ifequal i '...' %}
|
||||
{% if i == '...' %}
|
||||
<span class="space">{{ i }}</span>
|
||||
{% else %}
|
||||
{% ifequal i page %}
|
||||
{% if i == page %}
|
||||
<span class="this-page">{{i}}</span>
|
||||
{% else %}
|
||||
<a href="?page={{i}}{% if query %}&query={{query}}{% endif %}">{{i}}</a>
|
||||
{% endifequal %}
|
||||
{% endifequal %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{% trans "Displaying:" %}
|
||||
|
|
|
|||
|
|
@ -489,3 +489,38 @@ class RosettaTestCase(TestCase):
|
|||
#print (r.content)
|
||||
self.assertTrue('m_4765f7de94996d3de5975fa797c3451f' in str(r.content))
|
||||
self.assertTrue('m_08e4e11e2243d764fc45a5a4fba5d0f2' in str(r.content))
|
||||
|
||||
def test_0_save_header_data(self):
|
||||
shutil.copy(os.path.normpath(os.path.join(self.curdir, './django.po.template')), self.dest_file)
|
||||
|
||||
unicode_user = User.objects.create_user('test_unicode', 'save_header_data@test.com', 'test_unicode')
|
||||
unicode_user.first_name = "aéaéaé aàaàaàa"
|
||||
unicode_user.last_name = "aâââ üüüü"
|
||||
unicode_user.is_superuser, unicode_user.is_staff = True, True
|
||||
unicode_user.save()
|
||||
|
||||
self.client.login(username='test_unicode', password='test_unicode')
|
||||
|
||||
# Load the template file
|
||||
r = self.client.get(reverse('rosetta-pick-file') + '?filter=third-party')
|
||||
r = self.client.get(reverse('rosetta-language-selection', args=('xx', 0), kwargs=dict()))
|
||||
r = self.client.get(reverse('rosetta-home') + '?filter=untranslated')
|
||||
r = self.client.get(reverse('rosetta-home'))
|
||||
# make sure both strings are untranslated
|
||||
self.assertTrue('dummy language' in str(r.content))
|
||||
self.assertTrue('String 1' in str(r.content))
|
||||
self.assertTrue('String 2' in str(r.content))
|
||||
self.assertTrue('m_e48f149a8b2e8baa81b816c0edf93890' in str(r.content))
|
||||
|
||||
# post a translation
|
||||
r = self.client.post(reverse('rosetta-home'), dict(m_e48f149a8b2e8baa81b816c0edf93890='Hello, world', _next='_next'))
|
||||
# read the result
|
||||
f_ = open(self.dest_file, 'rb')
|
||||
content = six.text_type(f_.read())
|
||||
f_.close()
|
||||
#print (content)
|
||||
# make sure unicode data was properly converted to ascii
|
||||
self.assertTrue('Hello, world' in content)
|
||||
self.assertTrue('save_header_data@test.com' in content)
|
||||
self.assertTrue('aeaeae aaaaaaa aaaa uuuu' in content)
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ def home(request):
|
|||
return out_
|
||||
|
||||
storage = get_storage(request)
|
||||
version = rosetta.get_version(True)
|
||||
query = ''
|
||||
if storage.has('rosetta_i18n_fn'):
|
||||
rosetta_i18n_fn = storage.get('rosetta_i18n_fn')
|
||||
rosetta_i18n_app = get_app_name(rosetta_i18n_fn)
|
||||
|
|
@ -178,7 +178,6 @@ def home(request):
|
|||
if 'page' in request.GET:
|
||||
query_arg += '&page=%d&_next=1' % int(request.GET.get('page'))
|
||||
return HttpResponseRedirect(reverse('rosetta-home') + iri_to_uri(query_arg))
|
||||
rosetta_i18n_lang_name = _(storage.get('rosetta_i18n_lang_name'))
|
||||
rosetta_i18n_lang_code = storage.get('rosetta_i18n_lang_code')
|
||||
|
||||
if 'query' in request.REQUEST and request.REQUEST.get('query', '').strip():
|
||||
|
|
@ -208,9 +207,8 @@ def home(request):
|
|||
return HttpResponseRedirect(reverse('rosetta-home') + iri_to_uri(query_arg))
|
||||
|
||||
rosetta_messages = paginator.page(page).object_list
|
||||
main_language = None
|
||||
if rosetta_settings.MAIN_LANGUAGE and rosetta_settings.MAIN_LANGUAGE != rosetta_i18n_lang_code:
|
||||
|
||||
main_language = None
|
||||
for language in settings.LANGUAGES:
|
||||
if language[0] == rosetta_settings.MAIN_LANGUAGE:
|
||||
main_language = _(language[1])
|
||||
|
|
@ -219,7 +217,6 @@ def home(request):
|
|||
fl = ("/%s/" % rosetta_settings.MAIN_LANGUAGE).join(rosetta_i18n_fn.split("/%s/" % rosetta_i18n_lang_code))
|
||||
po = pofile(fl)
|
||||
|
||||
main_messages = []
|
||||
for message in rosetta_messages:
|
||||
message.main_lang = po.find(message.msgid).msgstr
|
||||
|
||||
|
|
@ -235,15 +232,33 @@ def home(request):
|
|||
except AttributeError:
|
||||
ADMIN_MEDIA_PREFIX = settings.STATIC_URL + 'admin/'
|
||||
ADMIN_IMAGE_DIR = ADMIN_MEDIA_PREFIX + 'img/'
|
||||
ENABLE_TRANSLATION_SUGGESTIONS = rosetta_settings.BING_APP_ID and rosetta_settings.ENABLE_TRANSLATION_SUGGESTIONS
|
||||
BING_APP_ID = rosetta_settings.BING_APP_ID
|
||||
MESSAGES_SOURCE_LANGUAGE_NAME = rosetta_settings.MESSAGES_SOURCE_LANGUAGE_NAME
|
||||
MESSAGES_SOURCE_LANGUAGE_CODE = rosetta_settings.MESSAGES_SOURCE_LANGUAGE_CODE
|
||||
|
||||
if storage.has('rosetta_last_save_error'):
|
||||
storage.delete('rosetta_last_save_error')
|
||||
rosetta_last_save_error = True
|
||||
else:
|
||||
rosetta_last_save_error = False
|
||||
|
||||
return render_to_response('rosetta/pofile.html', locals(), context_instance=RequestContext(request))
|
||||
return render_to_response('rosetta/pofile.html', dict(
|
||||
version=rosetta.get_version(True),
|
||||
ADMIN_MEDIA_PREFIX=ADMIN_MEDIA_PREFIX,
|
||||
ADMIN_IMAGE_DIR=ADMIN_IMAGE_DIR,
|
||||
rosetta_settings=rosetta_settings,
|
||||
rosetta_i18n_lang_name=_(storage.get('rosetta_i18n_lang_name')),
|
||||
rosetta_i18n_lang_code=rosetta_i18n_lang_code,
|
||||
rosetta_i18n_lang_bidi=rosetta_i18n_lang_bidi,
|
||||
rosetta_last_save_error=rosetta_last_save_error,
|
||||
rosetta_i18n_filter=rosetta_i18n_filter,
|
||||
rosetta_i18n_write=rosetta_i18n_write,
|
||||
rosetta_messages=rosetta_messages,
|
||||
page_range=needs_pagination and page_range,
|
||||
needs_pagination=needs_pagination,
|
||||
main_language=main_language,
|
||||
rosetta_i18n_app=rosetta_i18n_app,
|
||||
page=page,
|
||||
query=query,
|
||||
paginator=paginator
|
||||
), context_instance=RequestContext(request))
|
||||
else:
|
||||
return list_languages(request, do_session_warn=True)
|
||||
home = never_cache(home)
|
||||
|
|
|
|||
Loading…
Reference in a new issue