mirror of
https://github.com/pretix/pretix.git
synced 2026-05-03 14:54:04 +00:00
PDF editor: Allow multi-lingual text
This commit is contained in:
committed by
Raphael Michel
parent
02f8bcbe23
commit
ebae275a2d
@@ -55,6 +55,7 @@ from django.utils.functional import SimpleLazyObject
|
||||
from django.utils.html import conditional_escape
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from i18nfield.strings import LazyI18nString
|
||||
from PyPDF2 import PdfFileReader
|
||||
from pytz import timezone
|
||||
from reportlab.graphics import renderPDF
|
||||
@@ -660,8 +661,11 @@ class Renderer:
|
||||
if not o['content']:
|
||||
return '(error)'
|
||||
|
||||
if o['content'] == 'other':
|
||||
text = o['text']
|
||||
if o['content'] == 'other' or o['content'] == 'other_i18n':
|
||||
if o['content'] == 'other_i18n':
|
||||
text = str(LazyI18nString(o['text_i18n']))
|
||||
else:
|
||||
text = o['text']
|
||||
|
||||
def replace(x):
|
||||
if x.group(1) not in self.variables:
|
||||
|
||||
@@ -384,10 +384,16 @@
|
||||
{% trans "Item attribute:" %} {{ p.name }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
<option value="other_i18n">{% trans "Other… (multilingual)" %}</option>
|
||||
<option value="other">{% trans "Other…" %}</option>
|
||||
</select>
|
||||
<textarea type="text" value="" class="input-block-level form-control"
|
||||
id="toolbox-content-other"></textarea>
|
||||
<div class="i18n-form-group" id="toolbox-content-other-i18n">
|
||||
{% for l in request.event.settings.locales %}
|
||||
<textarea id="toolbox-content-other-{{ l }}" rows="3" class="input-block-level form-control" title="{{ l }}" lang="{{ l }}"></textarea>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -169,6 +169,7 @@ var editor = {
|
||||
downward: o.downward || false,
|
||||
content: o.content,
|
||||
text: o.text,
|
||||
text_i18n: o.text_i18n || {},
|
||||
rotation: o.angle,
|
||||
align: o.textAlign,
|
||||
});
|
||||
@@ -246,6 +247,9 @@ var editor = {
|
||||
}
|
||||
if (d.content === "other") {
|
||||
o.setText(d.text);
|
||||
} else if (d.content === "other_i18n") {
|
||||
o.text_i18n = d.text_i18n
|
||||
o.setText(d.text_i18n[Object.keys(d.text_i18n)[0]]);
|
||||
} else {
|
||||
o.setText(editor._get_text_sample(d.content));
|
||||
}
|
||||
@@ -391,6 +395,7 @@ var editor = {
|
||||
editor._update_toolbox();
|
||||
|
||||
$("#toolbox-content-other").hide();
|
||||
$("#toolbox-content-other-i18n").hide();
|
||||
$(".add-buttons button").prop('disabled', false);
|
||||
|
||||
if (dump) {
|
||||
@@ -489,8 +494,13 @@ var editor = {
|
||||
}
|
||||
$("#toolbox-content").val(o.content);
|
||||
$("#toolbox-content-other").toggle($("#toolbox-content").val() === "other");
|
||||
$("#toolbox-content-other-i18n").toggle($("#toolbox-content").val() === "other_i18n");
|
||||
if (o.content === "other") {
|
||||
$("#toolbox-content-other").val(o.text);
|
||||
} else if (o.content === "other_i18n") {
|
||||
$("#toolbox-content-other-i18n textarea").each(function () {
|
||||
$(this).val(o.text_i18n[$(this).attr("lang")] || '');
|
||||
});
|
||||
} else {
|
||||
$("#toolbox-content-other").val("");
|
||||
}
|
||||
@@ -526,9 +536,15 @@ var editor = {
|
||||
o.nowhitespace = $("#toolbox-qrwhitespace").prop("checked") || false;
|
||||
|
||||
$("#toolbox-content-other").toggle($("#toolbox-content").val() === "other");
|
||||
$("#toolbox-content-other-i18n").toggle($("#toolbox-content").val() === "other_i18n");
|
||||
o.content = $("#toolbox-content").val();
|
||||
if ($("#toolbox-content").val() === "other") {
|
||||
o.text = $("#toolbox-content-other").val();
|
||||
} else if ($("#toolbox-content").val() === "other_i18n") {
|
||||
o.text_i18n = {}
|
||||
$("#toolbox-content-other-i18n textarea").each(function () {
|
||||
o.text_i18n[$(this).attr("lang")] = $(this).val();
|
||||
});
|
||||
} else {
|
||||
o.text = editor._get_text_sample($("#toolbox-content").val());
|
||||
}
|
||||
@@ -574,9 +590,16 @@ var editor = {
|
||||
o.downward = $("#toolbox").find("button[data-action=downward]").is('.active');
|
||||
o.rotate(parseFloat($("#toolbox-textrotation").val()));
|
||||
$("#toolbox-content-other").toggle($("#toolbox-content").val() === "other");
|
||||
$("#toolbox-content-other-i18n").toggle($("#toolbox-content").val() === "other_i18n");
|
||||
o.content = $("#toolbox-content").val();
|
||||
if ($("#toolbox-content").val() === "other") {
|
||||
o.setText($("#toolbox-content-other").val());
|
||||
} else if ($("#toolbox-content").val() === "other_i18n") {
|
||||
o.text_i18n = {}
|
||||
$("#toolbox-content-other-i18n textarea").each(function () {
|
||||
o.text_i18n[$(this).attr("lang")] = $(this).val();
|
||||
});
|
||||
o.setText($("#toolbox-content-other-i18n textarea").first().val());
|
||||
} else {
|
||||
o.setText(editor._get_text_sample($("#toolbox-content").val()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user