Add Boxes.translations
to allow geenrators to translate things like labels, too. Adds hidden language parameter to make sure the language selected gets passed down to the generated drawing.
This commit is contained in:
parent
982ca9c498
commit
ea1ac786d5
|
@ -30,6 +30,7 @@ from xml.sax.saxutils import quoteattr
|
|||
|
||||
from shapely.geometry import *
|
||||
from shapely.ops import split
|
||||
import gettext
|
||||
|
||||
from boxes import edges
|
||||
from boxes import formats
|
||||
|
@ -297,6 +298,7 @@ class Boxes:
|
|||
self.edgesettings: dict[Any, Any] = {}
|
||||
self.inkscapefile = None
|
||||
self.non_default_args: dict[Any, Any] = {}
|
||||
self.translations = gettext.NullTranslations()
|
||||
|
||||
self.metadata = {
|
||||
"name" : self.__class__.__name__,
|
||||
|
|
|
@ -17,6 +17,7 @@ Options:
|
|||
|
||||
import os
|
||||
import sys
|
||||
import gettext
|
||||
|
||||
try:
|
||||
import boxes
|
||||
|
@ -58,13 +59,19 @@ def list_grouped_generators():
|
|||
for box in group.generators:
|
||||
print(' * {} - {}'.format(box.__name__, box.__doc__ or ''))
|
||||
|
||||
|
||||
def get_translation():
|
||||
try:
|
||||
return gettext.translation('boxes.py', localedir='locale')
|
||||
except OSError:
|
||||
return gettext.translation('boxes.py', fallback=True)
|
||||
|
||||
def run_generator(name, args):
|
||||
generators = generators_by_name()
|
||||
lower_name = name.lower()
|
||||
|
||||
if lower_name in generators.keys():
|
||||
box = generators[lower_name]()
|
||||
box.translations = get_translation()
|
||||
box.parseArgs(args)
|
||||
box.open()
|
||||
box.render()
|
||||
|
|
|
@ -260,6 +260,8 @@ class BServer:
|
|||
groupid += 1
|
||||
|
||||
result.append(f"""
|
||||
<input type="hidden" name="language" id="language" value="{lang_name}">
|
||||
|
||||
<p>
|
||||
<button name="render" value="1" formtarget="_blank">{_("Generate")}</button>
|
||||
<button name="render" value="2" formtarget="_self">{_("Download")}</button>
|
||||
|
@ -598,6 +600,8 @@ class BServer:
|
|||
else:
|
||||
box = box_cls()
|
||||
|
||||
box.translations = lang
|
||||
|
||||
if render == "0":
|
||||
defaults = {}
|
||||
for a in args:
|
||||
|
|
Loading…
Reference in New Issue