mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge branch 'master' of https://github.com/cbhaley/calibre
This commit is contained in:
commit
80ac7d893a
@ -43,19 +43,23 @@ from polyglot.builtins import iteritems, itervalues
|
|||||||
# Class and method to save an untranslated copy of translated strings
|
# Class and method to save an untranslated copy of translated strings
|
||||||
class TranslatedStringWithRaw(str):
|
class TranslatedStringWithRaw(str):
|
||||||
|
|
||||||
def __new__(cls, english, translated):
|
def __new__(cls, raw_english, raw_other, formatted_english, formatted_other):
|
||||||
instance = super().__new__(cls, translated)
|
instance = super().__new__(cls, formatted_other)
|
||||||
instance.raw_text = english
|
instance.raw_english = raw_english
|
||||||
|
instance.raw_other = raw_other
|
||||||
|
instance.formatted_english = formatted_english
|
||||||
|
instance.formatted_other = formatted_other
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
def format(self, *args, **kw):
|
def format(self, *args, **kw):
|
||||||
translated = super().format(*args, **kw)
|
formatted_english = self.raw_english.format(*args, **kw)
|
||||||
english = self.raw_text.format(*args, **kw)
|
formatted_other = self.raw_other.format(*args, **kw)
|
||||||
return TranslatedStringWithRaw(english, translated)
|
return TranslatedStringWithRaw(self.raw_english, self.raw_other,
|
||||||
|
formatted_english, formatted_other)
|
||||||
|
|
||||||
|
|
||||||
def _(txt):
|
def _(txt):
|
||||||
return TranslatedStringWithRaw(txt, xlated(txt))
|
return TranslatedStringWithRaw(txt, xlated(txt), txt, xlated(txt))
|
||||||
|
|
||||||
|
|
||||||
class StoredObjectType(Enum):
|
class StoredObjectType(Enum):
|
||||||
@ -369,11 +373,12 @@ class BuiltinAdd(BuiltinFormatterFunction):
|
|||||||
arg_count = -1
|
arg_count = -1
|
||||||
category = 'Arithmetic'
|
category = 'Arithmetic'
|
||||||
__doc__ = doc = _(
|
__doc__ = doc = _(
|
||||||
r'''
|
'''
|
||||||
``add(x [, y]*)`` -- returns the sum of its arguments. Throws an exception if an
|
``add(x [, y]*)`` -- returns the sum of its arguments. Throws an exception if an
|
||||||
argument is not a number. In most cases you can use the ``+`` operator instead
|
argument is not a number. In most cases you can use the ``+`` operator instead
|
||||||
of this function.
|
of this function.
|
||||||
''')
|
''')
|
||||||
|
# r'''No documentation provided''') # for debugging xlated text using French
|
||||||
|
|
||||||
def evaluate(self, formatter, kwargs, mi, locals, *args):
|
def evaluate(self, formatter, kwargs, mi, locals, *args):
|
||||||
res = 0
|
res = 0
|
||||||
@ -768,16 +773,16 @@ class BuiltinSwitch(BuiltinFormatterFunction):
|
|||||||
category = 'Iterating over values'
|
category = 'Iterating over values'
|
||||||
__doc__ = doc = _(
|
__doc__ = doc = _(
|
||||||
r'''
|
r'''
|
||||||
``switch([pattern, value,]+ else_value)`` -- for each ``pattern, value`` pair,
|
``switch(value, [patternN, valueN,]+ else_value)`` -- for each ``patternN, valueN`` pair,
|
||||||
checks if the field matches the regular expression ``pattern`` and if so returns
|
checks if the ``value`` matches the regular expression ``patternN`` and if so returns
|
||||||
the associated ``value``. If no ``pattern`` matches, then ``else_value`` is
|
the associated ``valueN``. If no ``patternN`` matches, then ``else_value`` is
|
||||||
returned. You can have as many ``pattern, value`` pairs as you wish. The first
|
returned. You can have as many ``patternN, valueN`` pairs as you wish. The first
|
||||||
match is returned.
|
match is returned.
|
||||||
''')
|
''')
|
||||||
|
|
||||||
def evaluate(self, formatter, kwargs, mi, locals, val, *args):
|
def evaluate(self, formatter, kwargs, mi, locals, val, *args):
|
||||||
if (len(args) % 2) != 1:
|
if (len(args) % 2) != 1:
|
||||||
raise ValueError(_('switch requires an odd number of arguments'))
|
raise ValueError(_('switch requires an even number of arguments'))
|
||||||
i = 0
|
i = 0
|
||||||
while i < len(args):
|
while i < len(args):
|
||||||
if i + 1 >= len(args):
|
if i + 1 >= len(args):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user