Skip to content

Commit

Permalink
configure_locale_and_language(): switches from class-based to GNU get…
Browse files Browse the repository at this point in the history
…text API

Fixes #1293 by using gettext.[bind]textdomain(), which will allow

    from gettext import gettext as _

to use the globally-configured locale without running afoul of mypy.

This reverts commit 4dd4d13.
  • Loading branch information
cfm committed Sep 2, 2021
1 parent b725048 commit 35d8a16
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 5 deletions.
7 changes: 2 additions & 5 deletions securedrop_client/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,8 @@ def configure_locale_and_language() -> str:
language_code = current_locale[:2]
except ValueError: # pragma: no cover
language_code = "en" # pragma: no cover
# DEBUG/TRANSLATE: override the language code here (e.g. to Chinese).
# language_code = 'zh'
gettext.translation(
"messages", localedir=localedir, languages=[language_code], fallback=True
).install("ngettext")
gettext.bindtextdomain("messages", localedir=localedir)
gettext.textdomain("messages")
return language_code


Expand Down
1 change: 1 addition & 0 deletions securedrop_client/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import logging
from gettext import gettext as _
from typing import Dict, List, Optional # noqa: F401

from PyQt5.QtCore import Qt
Expand Down
2 changes: 2 additions & 0 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import html
import logging
import sys
from gettext import gettext as _
from gettext import ngettext
from typing import Dict, List, Optional, Union # noqa: F401
from uuid import uuid4

Expand Down
1 change: 1 addition & 0 deletions securedrop_client/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import logging
import os
import uuid
from gettext import gettext as _
from typing import Any, Dict, List, Tuple, Type, Union # noqa: F401

import arrow
Expand Down
1 change: 1 addition & 0 deletions tests/gui/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import math
import random
from datetime import datetime
from gettext import gettext as _
from unittest.mock import Mock, PropertyMock, patch

import arrow
Expand Down
1 change: 1 addition & 0 deletions tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import datetime
import logging
import os
from gettext import gettext as _
from typing import Type
from unittest.mock import Mock, call

Expand Down

0 comments on commit 35d8a16

Please sign in to comment.