Skip to content

Commit 2d142b3

Browse files
committed
Simplify translation fucntion
1 parent 363a96a commit 2d142b3

40 files changed

Lines changed: 394 additions & 623 deletions

archinstall/__init__.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import sys
66
import time
77
import traceback
8-
from typing import TYPE_CHECKING
98

109
from archinstall.lib.args import arch_config_handler
1110
from archinstall.lib.disk.utils import disk_layouts
@@ -14,14 +13,9 @@
1413
from .lib.output import FormattedOutput, debug, error, info, log, warn
1514
from .lib.pacman import Pacman
1615
from .lib.plugins import load_plugin, plugins
17-
from .lib.translationhandler import DeferredTranslation, Language, translation_handler
16+
from .lib.translationhandler import Language, tr, translation_handler
1817
from .tui.curses_menu import Tui
1918

20-
if TYPE_CHECKING:
21-
from collections.abc import Callable
22-
23-
_: Callable[[str], DeferredTranslation]
24-
2519

2620
# @archinstall.plugin decorator hook to programmatically add
2721
# plugins in runtime. Useful in profiles_bck and other things.
@@ -76,7 +70,7 @@ def main() -> int:
7670
return 0
7771

7872
if os.getuid() != 0:
79-
print(_("Archinstall requires root privileges to run. See --help for more."))
73+
print(tr("Archinstall requires root privileges to run. See --help for more."))
8074
return 1
8175

8276
_log_sys_info()
@@ -125,7 +119,6 @@ def run_as_a_module() -> None:
125119

126120

127121
__all__ = [
128-
"DeferredTranslation",
129122
"FormattedOutput",
130123
"Language",
131124
"Pacman",

archinstall/default_profiles/desktops/hyprland.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
from typing import TYPE_CHECKING, override
1+
from typing import override
22

33
from archinstall.default_profiles.desktops import SeatAccess
44
from archinstall.default_profiles.profile import GreeterType, ProfileType
55
from archinstall.default_profiles.xorg import XorgProfile
6+
from archinstall.lib.translationhandler import tr
67
from archinstall.tui.curses_menu import SelectMenu
78
from archinstall.tui.menu_item import MenuItem, MenuItemGroup
89
from archinstall.tui.result import ResultType
910
from archinstall.tui.types import Alignment, FrameProperties
1011

11-
if TYPE_CHECKING:
12-
from collections.abc import Callable
13-
14-
from archinstall.lib.translationhandler import DeferredTranslation
15-
16-
_: Callable[[str], DeferredTranslation]
17-
1812

1913
class HyprlandProfile(XorgProfile):
2014
def __init__(self) -> None:
@@ -54,8 +48,8 @@ def services(self) -> list[str]:
5448

5549
def _ask_seat_access(self) -> None:
5650
# need to activate seat service and add to seat group
57-
header = str(_("Hyprland needs access to your seat (collection of hardware devices i.e. keyboard, mouse, etc)"))
58-
header += "\n" + str(_("Choose an option to give Hyprland access to your hardware")) + "\n"
51+
header = tr("Hyprland needs access to your seat (collection of hardware devices i.e. keyboard, mouse, etc)")
52+
header += "\n" + tr("Choose an option to give Hyprland access to your hardware") + "\n"
5953

6054
items = [MenuItem(s.value, value=s) for s in SeatAccess]
6155
group = MenuItemGroup(items, sort_items=True)
@@ -67,7 +61,7 @@ def _ask_seat_access(self) -> None:
6761
group,
6862
header=header,
6963
allow_skip=False,
70-
frame=FrameProperties.min(str(_("Seat access"))),
64+
frame=FrameProperties.min(tr("Seat access")),
7165
alignment=Alignment.CENTER,
7266
).run()
7367

archinstall/default_profiles/desktops/labwc.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
from typing import TYPE_CHECKING, override
1+
from typing import override
22

33
from archinstall.default_profiles.desktops import SeatAccess
44
from archinstall.default_profiles.profile import GreeterType, ProfileType
55
from archinstall.default_profiles.xorg import XorgProfile
6+
from archinstall.lib.translationhandler import tr
67
from archinstall.tui.curses_menu import SelectMenu
78
from archinstall.tui.menu_item import MenuItem, MenuItemGroup
89
from archinstall.tui.result import ResultType
910
from archinstall.tui.types import Alignment, FrameProperties
1011

11-
if TYPE_CHECKING:
12-
from collections.abc import Callable
13-
14-
from archinstall.lib.translationhandler import DeferredTranslation
15-
16-
_: Callable[[str], DeferredTranslation]
17-
1812

1913
class LabwcProfile(XorgProfile):
2014
def __init__(self) -> None:
@@ -51,8 +45,8 @@ def services(self) -> list[str]:
5145

5246
def _ask_seat_access(self) -> None:
5347
# need to activate seat service and add to seat group
54-
header = str(_("labwc needs access to your seat (collection of hardware devices i.e. keyboard, mouse, etc)"))
55-
header += "\n" + str(_("Choose an option to give labwc access to your hardware")) + "\n"
48+
header = tr("labwc needs access to your seat (collection of hardware devices i.e. keyboard, mouse, etc)")
49+
header += "\n" + tr("Choose an option to give labwc access to your hardware") + "\n"
5650

5751
items = [MenuItem(s.value, value=s) for s in SeatAccess]
5852
group = MenuItemGroup(items, sort_items=True)
@@ -64,7 +58,7 @@ def _ask_seat_access(self) -> None:
6458
group,
6559
header=header,
6660
allow_skip=False,
67-
frame=FrameProperties.min(str(_("Seat access"))),
61+
frame=FrameProperties.min(tr("Seat access")),
6862
alignment=Alignment.CENTER,
6963
).run()
7064

archinstall/default_profiles/desktops/niri.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
from typing import TYPE_CHECKING, override
1+
from typing import override
22

33
from archinstall.default_profiles.desktops import SeatAccess
44
from archinstall.default_profiles.profile import GreeterType, ProfileType
55
from archinstall.default_profiles.xorg import XorgProfile
6+
from archinstall.lib.translationhandler import tr
67
from archinstall.tui.curses_menu import SelectMenu
78
from archinstall.tui.menu_item import MenuItem, MenuItemGroup
89
from archinstall.tui.result import ResultType
910
from archinstall.tui.types import Alignment, FrameProperties
1011

11-
if TYPE_CHECKING:
12-
from collections.abc import Callable
13-
14-
from archinstall.lib.translationhandler import DeferredTranslation
15-
16-
_: Callable[[str], DeferredTranslation]
17-
1812

1913
class NiriProfile(XorgProfile):
2014
def __init__(self) -> None:
@@ -59,8 +53,8 @@ def services(self) -> list[str]:
5953

6054
def _ask_seat_access(self) -> None:
6155
# need to activate seat service and add to seat group
62-
header = str(_("niri needs access to your seat (collection of hardware devices i.e. keyboard, mouse, etc)"))
63-
header += "\n" + str(_("Choose an option to give niri access to your hardware")) + "\n"
56+
header = tr("niri needs access to your seat (collection of hardware devices i.e. keyboard, mouse, etc)")
57+
header += "\n" + tr("Choose an option to give niri access to your hardware") + "\n"
6458

6559
items = [MenuItem(s.value, value=s) for s in SeatAccess]
6660
group = MenuItemGroup(items, sort_items=True)
@@ -72,7 +66,7 @@ def _ask_seat_access(self) -> None:
7266
group,
7367
header=header,
7468
allow_skip=False,
75-
frame=FrameProperties.min(str(_("Seat access"))),
69+
frame=FrameProperties.min(tr("Seat access")),
7670
alignment=Alignment.CENTER,
7771
).run()
7872

archinstall/default_profiles/desktops/sway.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
from typing import TYPE_CHECKING, override
1+
from typing import override
22

33
from archinstall.default_profiles.desktops import SeatAccess
44
from archinstall.default_profiles.profile import GreeterType, ProfileType
55
from archinstall.default_profiles.xorg import XorgProfile
6+
from archinstall.lib.translationhandler import tr
67
from archinstall.tui.curses_menu import SelectMenu
78
from archinstall.tui.menu_item import MenuItem, MenuItemGroup
89
from archinstall.tui.result import ResultType
910
from archinstall.tui.types import Alignment, FrameProperties
1011

11-
if TYPE_CHECKING:
12-
from collections.abc import Callable
13-
14-
from archinstall.lib.translationhandler import DeferredTranslation
15-
16-
_: Callable[[str], DeferredTranslation]
17-
1812

1913
class SwayProfile(XorgProfile):
2014
def __init__(self) -> None:
@@ -61,8 +55,8 @@ def services(self) -> list[str]:
6155

6256
def _ask_seat_access(self) -> None:
6357
# need to activate seat service and add to seat group
64-
header = str(_("Sway needs access to your seat (collection of hardware devices i.e. keyboard, mouse, etc)"))
65-
header += "\n" + str(_("Choose an option to give Sway access to your hardware")) + "\n"
58+
header = tr("Sway needs access to your seat (collection of hardware devices i.e. keyboard, mouse, etc)")
59+
header += "\n" + tr("Choose an option to give Sway access to your hardware") + "\n"
6660

6761
items = [MenuItem(s.value, value=s) for s in SeatAccess]
6862
group = MenuItemGroup(items, sort_items=True)
@@ -74,7 +68,7 @@ def _ask_seat_access(self) -> None:
7468
group,
7569
header=header,
7670
allow_skip=False,
77-
frame=FrameProperties.min(str(_("Seat access"))),
71+
frame=FrameProperties.min(tr("Seat access")),
7872
alignment=Alignment.CENTER,
7973
).run()
8074

archinstall/default_profiles/profile.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@
44
from enum import Enum, auto
55
from typing import TYPE_CHECKING
66

7-
if TYPE_CHECKING:
8-
from collections.abc import Callable
9-
10-
from archinstall.lib.translationhandler import DeferredTranslation
7+
from archinstall.lib.translationhandler import tr
118

9+
if TYPE_CHECKING:
1210
from ..lib.installer import Installer
1311

14-
_: Callable[[str], DeferredTranslation]
15-
1612

1713
class ProfileType(Enum):
1814
# top level default_profiles
@@ -200,7 +196,7 @@ def packages_text(self, include_sub_packages: bool = False) -> str:
200196
if sub_profile.packages:
201197
packages.update(sub_profile.packages)
202198

203-
text = str(_("Installed packages")) + ":\n"
199+
text = tr("Installed packages") + ":\n"
204200

205201
for pkg in sorted(packages):
206202
text += f"\t- {pkg}\n"

archinstall/default_profiles/xorg.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
from typing import TYPE_CHECKING, override
1+
from typing import override
22

33
from archinstall.default_profiles.profile import Profile, ProfileType
4-
5-
if TYPE_CHECKING:
6-
from collections.abc import Callable
7-
8-
from archinstall.lib.translationhandler import DeferredTranslation
9-
10-
_: Callable[[str], DeferredTranslation]
4+
from archinstall.lib.translationhandler import tr
115

126

137
class XorgProfile(Profile):
@@ -26,7 +20,7 @@ def __init__(
2620

2721
@override
2822
def preview_text(self) -> str:
29-
text = str(_("Environment type: {}")).format(self.profile_type.value)
23+
text = tr("Environment type: {}").format(self.profile_type.value)
3024
if packages := self.packages_text():
3125
text += f"\n{packages}"
3226

archinstall/lib/args.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from dataclasses import dataclass, field
88
from importlib.metadata import version
99
from pathlib import Path
10-
from typing import TYPE_CHECKING, Any
10+
from typing import Any
1111
from urllib.request import Request, urlopen
1212

1313
from pydantic.dataclasses import dataclass as p_dataclass
@@ -25,17 +25,10 @@
2525
from archinstall.lib.output import debug, error, warn
2626
from archinstall.lib.plugins import load_plugin
2727
from archinstall.lib.storage import storage
28-
from archinstall.lib.translationhandler import Language, translation_handler
28+
from archinstall.lib.translationhandler import Language, tr, translation_handler
2929
from archinstall.lib.utils.util import get_password
3030
from archinstall.tui.curses_menu import Tui
3131

32-
if TYPE_CHECKING:
33-
from collections.abc import Callable
34-
35-
from archinstall.lib.translationhandler import DeferredTranslation
36-
37-
_: Callable[[str], DeferredTranslation]
38-
3932

4033
@p_dataclass
4134
class Arguments:
@@ -430,7 +423,7 @@ def _process_creds_data(self, creds_data: str) -> dict[str, Any] | None:
430423
return json.loads(creds_data)
431424
except ValueError as err:
432425
if "Invalid password" in str(err):
433-
error(str(_("Incorrect credentials file decryption password")))
426+
error(tr("Incorrect credentials file decryption password"))
434427
exit(1)
435428
else:
436429
debug(f"Error decrypting credentials file: {err}")
@@ -440,10 +433,10 @@ def _process_creds_data(self, creds_data: str) -> dict[str, Any] | None:
440433

441434
with Tui():
442435
while True:
443-
header = str(_("Incorrect password")) if incorrect_password else None
436+
header = tr("Incorrect password") if incorrect_password else None
444437

445438
decryption_pwd = get_password(
446-
text=str(_("Credentials file decryption password")),
439+
text=tr("Credentials file decryption password"),
447440
header=header,
448441
allow_skip=False,
449442
skip_confirmation=True,

0 commit comments

Comments
 (0)