From b019914fd819e5049282397b8ab3cb211ab81e83 Mon Sep 17 00:00:00 2001 From: Balazs Endresz Date: Sat, 21 Sep 2024 16:37:37 +0200 Subject: [PATCH 1/7] Add eslint, prettier, djhtml to pre-commit --- .eslintrc.js | 11 +++++++++++ .pre-commit-config.yaml | 16 ++++++++++++++++ .prettierrc | 4 ++++ 3 files changed, 31 insertions(+) create mode 100644 .eslintrc.js create mode 100644 .prettierrc diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..76eb3ac --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,11 @@ +module.exports = { + extends: "eslint:recommended", + env: { + browser: true, + node: true, + }, + parserOptions: { ecmaVersion: 9 }, + globals: { + $: "readonly", + }, +}; diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c19019d..884ee46 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,3 +25,19 @@ repos: args: [ --fix ] # Run the formatter. - id: ruff-format + +- repo: https://github.com/pre-commit/mirrors-eslint + rev: v8.56.0 + hooks: + - id: eslint + +- repo: https://github.com/pre-commit/mirrors-prettier + rev: v3.1.0 + hooks: + - id: prettier + types_or: [css, javascript] + +- repo: https://github.com/rtts/djhtml + rev: 3.0.6 + hooks: + - id: djhtml diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..50d5a18 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,4 @@ +{ + "printWidth": 100, + "tabWidth": 4 +} From c54e3392bec8ecdca9d5e95d58a13427acfee8f0 Mon Sep 17 00:00:00 2001 From: Balazs Endresz Date: Sat, 21 Sep 2024 16:17:46 +0200 Subject: [PATCH 2/7] Reformat rosetta.js --- rosetta/static/admin/rosetta/js/rosetta.js | 267 +++++++++++---------- 1 file changed, 143 insertions(+), 124 deletions(-) diff --git a/rosetta/static/admin/rosetta/js/rosetta.js b/rosetta/static/admin/rosetta/js/rosetta.js index a33cae3..3e87965 100644 --- a/rosetta/static/admin/rosetta/js/rosetta.js +++ b/rosetta/static/admin/rosetta/js/rosetta.js @@ -1,140 +1,159 @@ -const rosetta_settings = JSON.parse(document.getElementById('rosetta-settings-js').textContent); - -$(document).ready(function() { - - $('.location a').show().toggle(function() { - $('.hide', $(this).parent()).show(); - }, function() { - $('.hide', $(this).parent()).hide(); - }); - - if (rosetta_settings.ENABLE_TRANSLATION_SUGGESTIONS) { - if (rosetta_settings.server_auth_key) { - $('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 = rosetta_settings.MESSAGES_SOURCE_LANGUAGE_CODE; - var destLang = rosetta_settings.rosetta_i18n_lang_code_normalized; - - orig = unescape(orig).replace(//g,'\n').replace(//,'').replace(/<\/code>/g,'').replace(/>/g,'>').replace(/</g,'<'); - a.attr('class','suggesting').html('...'); - - $.getJSON(rosetta_settings.translate_text_url, { - from: sourceLang, - to: destLang, - text: orig, +const rosetta_settings = JSON.parse(document.getElementById("rosetta-settings-js").textContent); + +$(document).ready(function () { + $(".location a") + .show() + .toggle( + function () { + $(".hide", $(this).parent()).show(); }, - function(data) { - if (data.success){ - trans.val(unescape(data.translation).replace(/'/g,'\'').replace(/"/g,'"').replace(/%\s+(\([^\)]+\))\s*s/g,' %$1s ')); - a.hide(); - } else { - a.text(data.error); - } - } - ); - }); - } else if (rosetta_settings.YANDEX_TRANSLATE_KEY) { - $('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 apiUrl = "https://translate.yandex.net/api/v1.5/tr.json/translate"; - var destLangRoot = rosetta_settings.rosetta_i18n_lang_code.split('-')[0]; - var lang = rosetta_settings.MESSAGES_SOURCE_LANGUAGE_CODE + '-' + destLangRoot; - - a.attr('class','suggesting').html('...'); - - var apiData = { - error: 'onTranslationError', - success: 'onTranslationComplete', - lang: lang, - key: rosetta_settings.YANDEX_TRANSLATE_KEY, - format: 'html', - text: orig - }; - - $.ajax({ - url: apiUrl, - data: apiData, - dataType: 'jsonp', - success: function(response) { - if (response.code == 200) { - trans.val(response.text[0].replace(/
/g, '\n').replace(/<\/?code>/g, '').replace(/</g, '<').replace(/>/g, '>')); - a.hide(); - } else { - a.text(response); - } + function () { + $(".hide", $(this).parent()).hide(); }, - error: function(response) { - a.text(response); - } - }); - }); - } - } + ); - $('td.plural').each(function(i) { - var td = $(this), trY = parseInt(td.closest('tr').offset().top); - $('textarea', $(this).closest('tr')).each(function(j) { - var textareaY= parseInt($(this).offset().top) - trY; - $($('.part',td).get(j)).css('top',textareaY + 'px'); + if (rosetta_settings.ENABLE_TRANSLATION_SUGGESTIONS) { + if (rosetta_settings.server_auth_key) { + $("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 = rosetta_settings.MESSAGES_SOURCE_LANGUAGE_CODE; + var destLang = rosetta_settings.rosetta_i18n_lang_code_normalized; + + orig = unescape(orig) + .replace(//g, "\n") + .replace(//, "") + .replace(/<\/code>/g, "") + .replace(/>/g, ">") + .replace(/</g, "<"); + a.attr("class", "suggesting").html("..."); + + $.getJSON( + rosetta_settings.translate_text_url, + { + from: sourceLang, + to: destLang, + text: orig, + }, + function (data) { + if (data.success) { + trans.val( + unescape(data.translation) + .replace(/'/g, "'") + .replace(/"/g, '"') + .replace(/%\s+(\([^\)]+\))\s*s/g, " %$1s "), + ); + a.hide(); + } else { + a.text(data.error); + } + }, + ); + }); + } else if (rosetta_settings.YANDEX_TRANSLATE_KEY) { + $("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 apiUrl = "https://translate.yandex.net/api/v1.5/tr.json/translate"; + var destLangRoot = rosetta_settings.rosetta_i18n_lang_code.split("-")[0]; + var lang = rosetta_settings.MESSAGES_SOURCE_LANGUAGE_CODE + "-" + destLangRoot; + + a.attr("class", "suggesting").html("..."); + + var apiData = { + error: "onTranslationError", + success: "onTranslationComplete", + lang: lang, + key: rosetta_settings.YANDEX_TRANSLATE_KEY, + format: "html", + text: orig, + }; + + $.ajax({ + url: apiUrl, + data: apiData, + dataType: "jsonp", + success: function (response) { + if (response.code == 200) { + trans.val( + response.text[0] + .replace(/
/g, "\n") + .replace(/<\/?code>/g, "") + .replace(/</g, "<") + .replace(/>/g, ">"), + ); + a.hide(); + } else { + a.text(response); + } + }, + error: function (response) { + a.text(response); + }, + }); + }); + } + } + + $("td.plural").each(function (i) { + var td = $(this); + var trY = parseInt(td.closest("tr").offset().top); + $("textarea", $(this).closest("tr")).each(function (j) { + var textareaY = parseInt($(this).offset().top) - trY; + $($(".part", td).get(j)).css("top", textareaY + "px"); }); }); - $('.translation textarea') - - .blur(function() { - if($(this).val()) { - $('.alert', $(this).parents('tr')).remove(); - var RX = /%(?:\([^\s\)]*\))?[sdf]|\{[\w\d_]+?\}/g, - origs=$(this).parents('tr').find('.original span').html().match(RX), - trads=$(this).val().match(RX), - error = $('Unmatched variables'); - - if (origs && trads) { - for (var i = trads.length; i--;){ - var key = trads[i]; - if (-1 == $.inArray(key, origs)) { - $(this).before(error) + $(".translation textarea") + .blur(function () { + if ($(this).val()) { + $(".alert", $(this).parents("tr")).remove(); + var RX = /%(?:\([^\s\)]*\))?[sdf]|\{[\w\d_]+?\}/g; + var origs = $(this).parents("tr").find(".original span").html().match(RX); + var trads = $(this).val().match(RX); + var error = $('Unmatched variables'); + + if (origs && trads) { + for (var i = trads.length; i--; ) { + var key = trads[i]; + if (-1 == $.inArray(key, origs)) { + $(this).before(error); + return false; + } + } + return true; + } else { + if (!(origs === null && trads === null)) { + $(this).before(error); return false; } } return true; - } else { - if (!(origs === null && trads === null)) { - $(this).before(error); - return false; - } } - return true; - } - }) - - .keyup(function () { - var cb = $(this).parents('tr').find('td.c input[type="checkbox"]'); - if(cb.is(':checked')){ - cb[0].checked = false; - cb.removeAttr( 'checked') - } - - }) - - .eq(0).focus(); - - $('#action-toggle').change(function(){ - jQuery('tbody td.c input[type="checkbox"]').each(function(i, e) { - if($('#action-toggle').is(':checked')) { - $(e).attr('checked', 'checked'); + }) + .keyup(function () { + var cb = $(this).parents("tr").find('td.c input[type="checkbox"]'); + if (cb.is(":checked")) { + cb[0].checked = false; + cb.removeAttr("checked"); + } + }) + .eq(0) + .focus(); + + $("#action-toggle").change(function () { + $('tbody td.c input[type="checkbox"]').each(function (i, e) { + if ($("#action-toggle").is(":checked")) { + $(e).attr("checked", "checked"); } else { - $(e).removeAttr('checked'); + $(e).removeAttr("checked"); } }); }); - }); From e4431a80e1a651c33fe69ae7db7a19058b3da4da Mon Sep 17 00:00:00 2001 From: Balazs Endresz Date: Sat, 21 Sep 2024 16:13:00 +0200 Subject: [PATCH 3/7] Reformat rosetta.css --- rosetta/static/admin/rosetta/css/rosetta.css | 178 +++++++++++++++---- 1 file changed, 139 insertions(+), 39 deletions(-) diff --git a/rosetta/static/admin/rosetta/css/rosetta.css b/rosetta/static/admin/rosetta/css/rosetta.css index fcadb8c..e17d9aa 100644 --- a/rosetta/static/admin/rosetta/css/rosetta.css +++ b/rosetta/static/admin/rosetta/css/rosetta.css @@ -1,47 +1,147 @@ - -#user-tools p span { margin-left:2em; } -table{width:100%;} -td.translation label {font-size: 95%;} -td.translation textarea, td.original { font-size:110%;} -td.translation,td.original {width:30%;} -td.original .plural-container { position:relative} -td .context,td.original .message {display:block;} -td .context { margin-top: 1rem; color: #999; } -td.translation textarea{ width:98.5%; min-height:25px; margin:2px 0; } -.rtl td.translation textarea { direction: rtl;} -.plural span {display:block; margin:2px 0; position:absolute} -td.location code,td.location a { font-size:95%; display:block;} -td.location code.hide { display:none;} -.submit-row {margin-bottom:0;} -li.nobubble,li.nobubble:hover { background-image:none;} -.object-tools li.active, .object-tools li.active a { color:yellow;} -p.paginator input { float:right;} -p.paginator span.space { margin: 0 0.5em;} -.paginator {text-align:left; border:none; background:transparent; } -.paginator strong { margin-left:1em;} -th.r,td.r {text-align:right;} -th.c,td.c {text-align: center;} -td.original code {font-size:90%; padding: 0 1px; } -tr.row2 td.original code {background-color:#FFB2A5; padding: 0 0.3em;} -tr.row1 td.original code {background-color:#FFB2A5;} -.alert { font-weight:bold;padding:4px 5px 4px 25px; margin-left:1em; color: red; background:transparent url(data:image/svg+xml,%3Csvg%20width%3D%2214%22%20height%3D%2214%22%20viewBox%3D%220%200%201792%201792%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%0A%20%20%3Cpath%20fill%3D%22%23efb80b%22%20d%3D%22M1024%201375v-190q0-14-9.5-23.5t-22.5-9.5h-192q-13%200-22.5%209.5t-9.5%2023.5v190q0%2014%209.5%2023.5t22.5%209.5h192q13%200%2022.5-9.5t9.5-23.5zm-2-374l18-459q0-12-10-19-13-11-24-11h-220q-11%200-24%2011-10%207-10%2021l17%20457q0%2010%2010%2016.5t24%206.5h185q14%200%2023.5-6.5t10.5-16.5zm-14-934l768%201408q35%2063-2%20126-17%2029-46.5%2046t-63.5%2017h-1536q-34%200-63.5-17t-46.5-46q-37-63-2-126l768-1408q17-31%2047-49t65-18%2065%2018%2047%2049z%22%2F%3E%0A%3C%2Fsvg%3E%0A) 5px .3em no-repeat; } -p.errornote { margin-top:0.4em;} -#footer { clear:both; color:#999; font-size:9px; margin:0 6px; text-align:left;} -#changelist table tbody td:first-child, #changelist table thead th:first-child {text-align: left;} -td.hint {color: #777;} -div.module {margin-bottom: 20px;} -.checkall {cursor:pointer} -#toolbar { height:20px} -#toolbar #translate-all { float:right} -#toolbar form { float:left; } -#changelist table thead th { padding: 2px 5px; } +#user-tools p span { + margin-left: 2em; +} +table { + width: 100%; +} +td.translation label { + font-size: 95%; +} +td.translation textarea, +td.original { + font-size: 110%; +} +td.translation, +td.original { + width: 30%; +} +td.original .plural-container { + position: relative; +} +td .context, +td.original .message { + display: block; +} +td .context { + margin-top: 1rem; + color: #999; +} +td.translation textarea { + width: 98.5%; + min-height: 25px; + margin: 2px 0; +} +.rtl td.translation textarea { + direction: rtl; +} +.plural span { + display: block; + margin: 2px 0; + position: absolute; +} +td.location code, +td.location a { + font-size: 95%; + display: block; +} +td.location code.hide { + display: none; +} +.submit-row { + margin-bottom: 0; +} +li.nobubble, +li.nobubble:hover { + background-image: none; +} +.object-tools li.active, +.object-tools li.active a { + color: yellow; +} +p.paginator input { + float: right; +} +p.paginator span.space { + margin: 0 0.5em; +} +.paginator { + text-align: left; + border: none; + background: transparent; +} +.paginator strong { + margin-left: 1em; +} +th.r, +td.r { + text-align: right; +} +th.c, +td.c { + text-align: center; +} +td.original code { + font-size: 90%; + padding: 0 1px; +} +tr.row2 td.original code { + background-color: #ffb2a5; + padding: 0 0.3em; +} +tr.row1 td.original code { + background-color: #ffb2a5; +} +.alert { + font-weight: bold; + padding: 4px 5px 4px 25px; + margin-left: 1em; + color: red; + background: transparent + url(data:image/svg+xml,%3Csvg%20width%3D%2214%22%20height%3D%2214%22%20viewBox%3D%220%200%201792%201792%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%0A%20%20%3Cpath%20fill%3D%22%23efb80b%22%20d%3D%22M1024%201375v-190q0-14-9.5-23.5t-22.5-9.5h-192q-13%200-22.5%209.5t-9.5%2023.5v190q0%2014%209.5%2023.5t22.5%209.5h192q13%200%2022.5-9.5t9.5-23.5zm-2-374l18-459q0-12-10-19-13-11-24-11h-220q-11%200-24%2011-10%207-10%2021l17%20457q0%2010%2010%2016.5t24%206.5h185q14%200%2023.5-6.5t10.5-16.5zm-14-934l768%201408q35%2063-2%20126-17%2029-46.5%2046t-63.5%2017h-1536q-34%200-63.5-17t-46.5-46q-37-63-2-126l768-1408q17-31%2047-49t65-18%2065%2018%2047%2049z%22%2F%3E%0A%3C%2Fsvg%3E%0A) + 5px 0.3em no-repeat; +} +p.errornote { + margin-top: 0.4em; +} +#footer { + clear: both; + color: #999; + font-size: 9px; + margin: 0 6px; + text-align: left; +} +#changelist table tbody td:first-child, +#changelist table thead th:first-child { + text-align: left; +} +td.hint { + color: #777; +} +div.module { + margin-bottom: 20px; +} +.checkall { + cursor: pointer; +} +#toolbar { + height: 20px; +} +#toolbar #translate-all { + float: right; +} +#toolbar form { + float: left; +} +#changelist table thead th { + padding: 2px 5px; +} #changelist { - display: block !important; + display: block !important; } .info-tip::after { - content: '?'; + content: "?"; color: white; background-color: #bbb; margin-left: 5px; From c539cca5e66b5f70dca06bf6936dd37c6a7f6189 Mon Sep 17 00:00:00 2001 From: Balazs Endresz Date: Sat, 21 Sep 2024 16:10:40 +0200 Subject: [PATCH 4/7] Reformat html files --- rosetta/templates/rosetta/admin_index.html | 32 ++--- rosetta/templates/rosetta/base.html | 60 ++++---- rosetta/templates/rosetta/file-list.html | 78 +++++----- rosetta/templates/rosetta/form.html | 160 ++++++++++----------- testproject/templates/test.html | 4 +- 5 files changed, 167 insertions(+), 167 deletions(-) diff --git a/rosetta/templates/rosetta/admin_index.html b/rosetta/templates/rosetta/admin_index.html index 4a767a4..976a43a 100644 --- a/rosetta/templates/rosetta/admin_index.html +++ b/rosetta/templates/rosetta/admin_index.html @@ -2,20 +2,20 @@ {% load rosetta i18n %} {% block sidebar %} -{{block.super}} -{% if request.user|can_translate %} - -{% endif %} + {{ block.super }} + {% if request.user|can_translate %} + + {% endif %} {% endblock %} diff --git a/rosetta/templates/rosetta/base.html b/rosetta/templates/rosetta/base.html index 4e6ae8a..e7156bc 100644 --- a/rosetta/templates/rosetta/base.html +++ b/rosetta/templates/rosetta/base.html @@ -1,36 +1,36 @@ {% load static %} - - - {% block pagetitle %}Rosetta{% endblock %} - + + + {% block pagetitle %}Rosetta{% endblock %} + - - - - - - {% block extra_styles %}{% endblock %} - - {{ rosetta_settings_js|json_script:"rosetta-settings-js" }} - - - -
- {% if rosetta_settings.ENABLE_REFLANG %} -
- - -
+
+ + +
{% endif %}
@@ -78,89 +78,89 @@

{% blocktrans %}Translate into {{rosetta_i18n_lang_name}}{% endblocktrans % {% for message in rosetta_messages %} - - {% if message.msgid_plural %} - -
- {{message.msgid|format_message|linebreaksbr}} - {{message.msgid_plural|format_message|linebreaksbr}} -
- - - {% for k, msgstr in message.msgstr_plural.items %} - - - {% endfor %} - - {% else %} - - {% if rosetta_settings.ENABLE_REFLANG %} - {{ message.ref_txt|format_message|linebreaksbr }} - {% else %} - {{ message.msgid|format_message|linebreaksbr }} - {% endif %} - - {% if main_language %}{{ message.main_lang|format_message|linebreaksbr }}{% endif %} - - - {% if rosetta_settings.ENABLE_TRANSLATION_SUGGESTIONS %}{% trans "suggest" %}{% endif %} - - {% endif %} + + {% if message.msgid_plural %} + +
+ {{ message.msgid|format_message|linebreaksbr }} + {{ message.msgid_plural|format_message|linebreaksbr }} +
+ + + {% for k, msgstr in message.msgstr_plural.items %} + + + {% endfor %} + + {% else %} + + {% if rosetta_settings.ENABLE_REFLANG %} + {{ message.ref_txt|format_message|linebreaksbr }} + {% else %} + {{ message.msgid|format_message|linebreaksbr }} + {% endif %} + + {% if main_language %}{{ message.main_lang|format_message|linebreaksbr }}{% endif %} + + + {% if rosetta_settings.ENABLE_TRANSLATION_SUGGESTIONS %}{% trans "suggest" %}{% endif %} + + {% endif %} - + {% if rosetta_settings.SHOW_OCCURRENCES %} - - {% for fn,lineno in message.occurrences %} - {{ fn }}{% if lineno %}:{{lineno}}{% endif %}
- {% endfor %} - {% if message.occurrences|length|gt:"3" %} - … ({% blocktrans count message.occurrences|length|minus:"3" as more_count %}{{more_count}} more{% plural %}{{more_count}} more{% endblocktrans %}) - {% endif %} - {% if message.msgctxt or message.comment %} - - {% trans "Context hint" %}: - {% if message.msgctxt %} - {{message.msgctxt|safe}} + + {% for fn,lineno in message.occurrences %} + {{ fn }}{% if lineno %}:{{ lineno }}{% endif %}
+ {% endfor %} + {% if message.occurrences|length|gt:"3" %} + … ({% blocktrans count message.occurrences|length|minus:"3" as more_count %}{{ more_count }} more{% plural %}{{ more_count }} more{% endblocktrans %}) {% endif %} - {% if message.msgctxt and message.comment %}
{% endif %} - {% if message.comment %} - {{message.comment|safe}} + {% if message.msgctxt or message.comment %} + + {% trans "Context hint" %}: + {% if message.msgctxt %} + {{ message.msgctxt|safe }} + {% endif %} + {% if message.msgctxt and message.comment %}
{% endif %} + {% if message.comment %} + {{ message.comment|safe }} + {% endif %} +
{% endif %} - - {% endif %} - {% endif %} - + {% endif %} + {% endfor %}

{% if query %} - + {% endif %} {% if needs_pagination %} - {% trans "Skip to page:" %} - {% for i in page_range %} - {% if i == '...' %} - {{ i }} - {% else %} - {% if i == page %} - {{i}} - {% else %} - {{i}} - {% endif %} - {% endif %} - {% endfor %} + {% trans "Skip to page:" %} + {% for i in page_range %} + {% if i == '...' %} + {{ i }} + {% else %} + {% if i == page %} + {{ i }} + {% else %} + {{ i }} + {% endif %} + {% endif %} + {% endfor %} {% else %} - {% trans "Displaying:" %} + {% trans "Displaying:" %} {% endif %} {% with paginator.object_list|length as hits %} - {% blocktrans count rosetta_i18n_pofile|length as message_number %}{{hits}}/{{message_number}} message{% plural %}{{hits}}/{{message_number}} messages{% endblocktrans %} + {% blocktrans count rosetta_i18n_pofile|length as message_number %}{{ hits }}/{{ message_number }} message{% plural %}{{ hits }}/{{ message_number }} messages{% endblocktrans %} {% endwith %} diff --git a/testproject/templates/test.html b/testproject/templates/test.html index f056cb9..353b4fb 100644 --- a/testproject/templates/test.html +++ b/testproject/templates/test.html @@ -3,7 +3,7 @@ {% trans "Some text to translate" %} {% blocktrans %} -one bottle of beer on the wall + one bottle of beer on the wall {% plural %} -{{num_bottles}} bottles of beer on the wall + {{ num_bottles }} bottles of beer on the wall {% endblocktrans %} From b7ae32757587d184487071c640f01cc034cd2b9d Mon Sep 17 00:00:00 2001 From: Balazs Endresz Date: Sat, 21 Sep 2024 16:27:52 +0200 Subject: [PATCH 5/7] Use blocktrans trimmed in test.html --- testproject/templates/test.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testproject/templates/test.html b/testproject/templates/test.html index 353b4fb..25b53f4 100644 --- a/testproject/templates/test.html +++ b/testproject/templates/test.html @@ -2,7 +2,7 @@ {% trans "Some text to translate" %} -{% blocktrans %} +{% blocktrans trimmed %} one bottle of beer on the wall {% plural %} {{ num_bottles }} bottles of beer on the wall From f2b93efd6be0bd3e2bb28f58ea8bd3430224e7f3 Mon Sep 17 00:00:00 2001 From: Balazs Endresz Date: Sat, 21 Sep 2024 19:48:21 +0200 Subject: [PATCH 6/7] Fix eslint warnings in rosetta.js --- rosetta/static/admin/rosetta/js/rosetta.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/rosetta/static/admin/rosetta/js/rosetta.js b/rosetta/static/admin/rosetta/js/rosetta.js index 3e87965..5e28c59 100644 --- a/rosetta/static/admin/rosetta/js/rosetta.js +++ b/rosetta/static/admin/rosetta/js/rosetta.js @@ -17,7 +17,6 @@ $(document).ready(function () { $("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 = rosetta_settings.MESSAGES_SOURCE_LANGUAGE_CODE; @@ -44,7 +43,7 @@ $(document).ready(function () { unescape(data.translation) .replace(/'/g, "'") .replace(/"/g, '"') - .replace(/%\s+(\([^\)]+\))\s*s/g, " %$1s "), + .replace(/%\s+(\([^)]+\))\s*s/g, " %$1s "), ); a.hide(); } else { @@ -57,7 +56,6 @@ $(document).ready(function () { $("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 apiUrl = "https://translate.yandex.net/api/v1.5/tr.json/translate"; @@ -101,7 +99,7 @@ $(document).ready(function () { } } - $("td.plural").each(function (i) { + $("td.plural").each(function () { var td = $(this); var trY = parseInt(td.closest("tr").offset().top); $("textarea", $(this).closest("tr")).each(function (j) { @@ -114,7 +112,7 @@ $(document).ready(function () { .blur(function () { if ($(this).val()) { $(".alert", $(this).parents("tr")).remove(); - var RX = /%(?:\([^\s\)]*\))?[sdf]|\{[\w\d_]+?\}/g; + var RX = /%(?:\([^\s)]*\))?[sdf]|\{[\w\d_]+?\}/g; var origs = $(this).parents("tr").find(".original span").html().match(RX); var trads = $(this).val().match(RX); var error = $('Unmatched variables'); From 635745d3a9682140357b2a6f1780197a48bf1ad6 Mon Sep 17 00:00:00 2001 From: Balazs Endresz Date: Fri, 27 Sep 2024 12:56:14 +0200 Subject: [PATCH 7/7] Fix ruff linting errors --- docs/conf.py | 1 - rosetta/translate_utils.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 4d36b8c..81c6bb0 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,7 +12,6 @@ # serve to show the default. import os -import shlex import sys diff --git a/rosetta/translate_utils.py b/rosetta/translate_utils.py index 5e5b08c..c69cba9 100644 --- a/rosetta/translate_utils.py +++ b/rosetta/translate_utils.py @@ -22,7 +22,7 @@ def translate(text, from_language, to_language): if DEEPL_AUTH_KEY: deepl_language_code = None DEEPL_LANGUAGES = getattr(settings, "DEEPL_LANGUAGES", None) - if type(DEEPL_LANGUAGES) is dict: + if isinstance(DEEPL_LANGUAGES, dict): deepl_language_code = DEEPL_LANGUAGES.get(to_language, None) if deepl_language_code is None: