Fix i18n relative path + reformat using pre-commit (#1740)

* fix: i18n relative path + reformat using `pre-commit`

* chore: changes

---------

Co-authored-by: Katant <katantdev@mail.ru>
This commit is contained in:
Artem Kushnerov 2026-01-02 08:01:02 +10:00 committed by GitHub
parent b27ca9a45d
commit 7201e82238
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 9 additions and 10 deletions

1
.github/FUNDING.yml vendored
View file

@ -1,2 +1 @@
open_collective: aiogram open_collective: aiogram

1
CHANGES/1740.bugfix.rst Normal file
View file

@ -0,0 +1 @@
Fix I18n initialization with relative path

View file

@ -21,7 +21,7 @@ class I18n(ContextInstanceMixin["I18n"]):
default_locale: str = "en", default_locale: str = "en",
domain: str = "messages", domain: str = "messages",
) -> None: ) -> None:
self.path = Path(path) self.path = Path(path).resolve()
self.default_locale = default_locale self.default_locale = default_locale
self.domain = domain self.domain = domain
self.ctx_locale = ContextVar("aiogram_ctx_locale", default=default_locale) self.ctx_locale = ContextVar("aiogram_ctx_locale", default=default_locale)
@ -66,9 +66,9 @@ class I18n(ContextInstanceMixin["I18n"]):
translations: dict[str, gettext.GNUTranslations] = {} translations: dict[str, gettext.GNUTranslations] = {}
for name in self.path.iterdir(): for name in self.path.iterdir():
if not (self.path / name).is_dir(): if not name.is_dir():
continue continue
mo_path = self.path / name / "LC_MESSAGES" / (self.domain + ".mo") mo_path = name / "LC_MESSAGES" / (self.domain + ".mo")
if mo_path.exists(): if mo_path.exists():
with mo_path.open("rb") as fp: with mo_path.open("rb") as fp:

View file

@ -32,4 +32,3 @@ msgid ""
msgstr "" msgstr ""
"Джерело: " "Джерело: "
"https://github.com/telegramdesktop/tdesktop/blob/991fe491c5ae62705d77aa8fdd44a79caf639c45/Telegram/SourceFiles/data/data_forum_topic.cpp#L51-L56" "https://github.com/telegramdesktop/tdesktop/blob/991fe491c5ae62705d77aa8fdd44a79caf639c45/Telegram/SourceFiles/data/data_forum_topic.cpp#L51-L56"

View file

@ -103,4 +103,3 @@ msgstr ""
#: ../../api/methods/set_chat_permissions.rst:50 #: ../../api/methods/set_chat_permissions.rst:50
msgid ":meth:`aiogram.types.chat.Chat.set_permissions`" msgid ":meth:`aiogram.types.chat.Chat.set_permissions`"
msgstr "" msgstr ""

View file

@ -195,4 +195,3 @@ msgstr ""
"Альтернативним способом є об’єднання за допомогою спеціальних функцій " "Альтернативним способом є об’єднання за допомогою спеціальних функцій "
"(:func:`and_f`, :func:`or_f`, :func:`invert_f` з модуля " "(:func:`and_f`, :func:`or_f`, :func:`invert_f` з модуля "
":code:`aiogram.filters`):" ":code:`aiogram.filters`):"

View file

@ -106,4 +106,3 @@ msgid ""
msgstr "" msgstr ""
"Передача події обробнику подій(handler) та зупинка при першому ж збігу. " "Передача події обробнику подій(handler) та зупинка при першому ж збігу. "
"Обробник(handler) буде викликало, коли всі його фільтри пройдено." "Обробник(handler) буде викликало, коли всі його фільтри пройдено."

View file

@ -202,4 +202,3 @@ msgstr ""
#: aiogram.utils.callback_answer.CallbackAnswer.cache_time:1 of #: aiogram.utils.callback_answer.CallbackAnswer.cache_time:1 of
msgid "Response cache time" msgid "Response cache time"
msgstr "" msgstr ""

View file

@ -288,4 +288,3 @@ msgstr ""
#: aiogram.utils.media_group.MediaGroupBuilder.build:5 of #: aiogram.utils.media_group.MediaGroupBuilder.build:5 of
msgid "List of media objects." msgid "List of media objects."
msgstr "" msgstr ""

View file

@ -1,3 +1,4 @@
from pathlib import Path
from typing import Any, Dict from typing import Any, Dict
import pytest import pytest
@ -27,6 +28,10 @@ class TestI18nCore:
def test_init(self, i18n: I18n): def test_init(self, i18n: I18n):
assert set(i18n.available_locales) == {"en", "uk"} assert set(i18n.available_locales) == {"en", "uk"}
def test_init_relative(self):
i18n_relative = I18n(path="tests/data/locales")
assert set(i18n_relative.available_locales) == {"en", "uk"}
def test_reload(self, i18n: I18n): def test_reload(self, i18n: I18n):
i18n.reload() i18n.reload()
assert set(i18n.available_locales) == {"en", "uk"} assert set(i18n.available_locales) == {"en", "uk"}