Skip to content

Commit

Permalink
Fix translations of enums
Browse files Browse the repository at this point in the history
These _ calls were evaluated at import time, which was before
aeidon.i18n.bind called as part of gaupol main. Thus they were simply
not translated. I don't remember anymore what was originally intended
here. Fixed now using lazy translations marked as __.

Closes #210
  • Loading branch information
otsaloma committed May 27, 2023
1 parent a06b847 commit 166e1ca
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 27 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
PENDING: Gaupol 1.13
====================

* Fix translations missing for enums (#210)

2023-01-21: Gaupol 1.12
=======================

Expand Down
8 changes: 8 additions & 0 deletions aeidon/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
in its set. New items can always be added to an enumeration.
"""

from aeidon.i18n import _
from aeidon.i18n import __

__all__ = ("EnumerationItem", "Enumeration",)


Expand All @@ -47,6 +50,11 @@ def __bool__(self):
"""For consistency, always return ``True``."""
return True

def __getattribute__(self, name):
"""Return attribute, evaluating any lazy translations."""
value = super().__getattribute__(name)
return _(value) if isinstance(value, __) else value

def __str__(self):
"""Return name as the string representation."""
return self.name
Expand Down
24 changes: 12 additions & 12 deletions aeidon/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import shutil
import sys

from aeidon.i18n import _
from aeidon.i18n import __

__all__ = [
"align_methods",
Expand All @@ -37,10 +37,10 @@


class AlignMethodNumber(aeidon.EnumerationItem):
label = _("Subtitle number")
label = __("Subtitle number")

class AlignMethodPosition(aeidon.EnumerationItem):
label = _("Subtitle position")
label = __("Subtitle position")

align_methods = aeidon.Enumeration()
align_methods.NUMBER = AlignMethodNumber()
Expand All @@ -56,35 +56,35 @@ class DocumentTranslation(aeidon.EnumerationItem): pass


class Framerate23976(aeidon.EnumerationItem):
label = _("23.976 fps")
label = __("23.976 fps")
value = 24 / 1.001

class Framerate24000(aeidon.EnumerationItem):
label = _("24.000 fps")
label = __("24.000 fps")
value = 24.0

class Framerate25000(aeidon.EnumerationItem):
label = _("25.000 fps")
label = __("25.000 fps")
value = 25.0

class Framerate29970(aeidon.EnumerationItem):
label = _("29.970 fps")
label = __("29.970 fps")
value = 30 / 1.001

class Framerate30000(aeidon.EnumerationItem):
label = _("30.000 fps")
label = __("30.000 fps")
value = 30.0

class Framerate50000(aeidon.EnumerationItem):
label = _("50.000 fps")
label = __("50.000 fps")
value = 50.0

class Framerate59940(aeidon.EnumerationItem):
label = _("59.940 fps")
label = __("59.940 fps")
value = 60 / 1.001

class Framerate60000(aeidon.EnumerationItem):
label = _("60.000 fps")
label = __("60.000 fps")
value = 60.0

framerates = aeidon.Enumeration()
Expand All @@ -109,7 +109,7 @@ class ModeSeconds(aeidon.EnumerationItem): pass


class NewlinesMac(aeidon.EnumerationItem):
label = _("Mac (classic)")
label = __("Mac (classic)")
value = "\r"

class NewlinesUnix(aeidon.EnumerationItem):
Expand Down
4 changes: 4 additions & 0 deletions aeidon/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
_translation = gettext.NullTranslations()


# Wrapper class for marking lazy translations
class __(str): pass


def bind(localedir=aeidon.LOCALE_DIR):
"""Bind translation domains and initialize gettext."""
with aeidon.util.silent(Exception):
Expand Down
30 changes: 15 additions & 15 deletions gaupol/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import aeidon

from aeidon.i18n import _
from aeidon.i18n import __
from gi.repository import Gtk

__all__ = [
Expand All @@ -34,40 +34,40 @@
class FieldNumber(aeidon.EnumerationItem):
is_position = False
is_text = False
label = _("No.")
tooltip = _("Subtitle number")
label = __("No.")
tooltip = __("Subtitle number")

class FieldStart(aeidon.EnumerationItem):
is_position = True
is_text = False
label = _("Start")
tooltip = _("Start position")
label = __("Start")
tooltip = __("Start position")

class FieldEnd(aeidon.EnumerationItem):
is_position = True
is_text = False
label = _("End")
tooltip = _("End position")
label = __("End")
tooltip = __("End position")

class FieldDuration(aeidon.EnumerationItem):
is_position = True
is_text = False
# TRANSLATORS: 'Dur.' is short for duration. It is used in the header
# of a column that contains numbers five digits wide.
label = _("Dur.")
tooltip = _("Duration")
label = __("Dur.")
tooltip = __("Duration")

class FieldMainText(aeidon.EnumerationItem):
is_position = False
is_text = True
label = _("Text")
tooltip = _("Text")
label = __("Text")
tooltip = __("Text")

class FieldTranslationText(aeidon.EnumerationItem):
is_position = False
is_text = True
label = _("Translation")
tooltip = _("Translation")
label = __("Translation")
tooltip = __("Translation")

fields = aeidon.Enumeration()
fields.NUMBER = FieldNumber()
Expand All @@ -79,10 +79,10 @@ class FieldTranslationText(aeidon.EnumerationItem):


class LengthUnitChar(aeidon.EnumerationItem):
label = _("characters")
label = __("characters")

class LengthUnitEm(aeidon.EnumerationItem):
label = _("ems")
label = __("ems")

length_units = aeidon.Enumeration()
length_units.CHAR = LengthUnitChar()
Expand Down
1 change: 1 addition & 0 deletions tools/extract-translations
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ xgettext \
--from-code=UTF-8 \
--language=Python \
--keyword=_:1 \
--keyword=__:1 \
--keyword=d_:2 \
--keyword=n_:1,2 \
--add-comments=TRANSLATORS: \
Expand Down

0 comments on commit 166e1ca

Please sign in to comment.