Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test_constants_translations_are_up_to_date, fix broken translations #746

Merged
merged 8 commits into from
Jul 2, 2023
Merged
10 changes: 0 additions & 10 deletions djoser/locale/ja/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,6 @@ msgstr "入力されたemailを使用しているユーザーは見つかりま
msgid "Unable to create account."
msgstr "アカウントを作成できませんでした。"

#: djoser/constants.py:15
msgid ""
"User model does not contain specified email field. Please see http://djoser."
"readthedocs.io/en/latest/settings.html#USER_EMAIL_FIELD_NAME for more "
"details."
msgstr ""
"指定されたemailフィールドを持つユーザーモデルが存在しません。 "
"http://djoser.readthedocs.io/en/latest/settings.html#USER_EMAIL_FIELD_NAME "
"上記から詳細を確認してください。"

#: djoser/templates/email/activation.html:4
#, python-format
msgid "Account activation on %(site_name)s"
Expand Down
11 changes: 1 addition & 10 deletions djoser/locale/pl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ msgstr ""
"%100<12 || n%100>14) ? 1 : n!=1 && (n%10>=0 && n%10<=1) || (n%10>=5 && n"
"%10<=9) || (n%100>=12 && n%100<=14) ? 2 : 3);\n"
#: djoser/constants.py:4
msgid "Unable to login with provided credentials."
msgid "Unable to log in with provided credentials."
msgstr "Nie udało się zalogować przy pomocy tych danych."

#: djoser/constants.py:5
Expand Down Expand Up @@ -57,15 +57,6 @@ msgstr "Użytkownik z tym adresem email nie istnieje."
msgid "Unable to create account."
msgstr "Nie udało się stworzyć konta."

#: djoser/constants.py:15
msgid ""
"User model does not contain specified email field. Please see http://djoser."
"readthedocs.io/en/latest/settings.html#USER_EMAIL_FIELD_NAME for more "
"details."
msgstr "Model użytkownika nie zawiera wskazanego pola email. Zobacz "
"http://djoser.readthedocs.io/en/latest/settings.html#USER_EMAIL_FIELD_NAME "
"by zobaczyć więcej szczegółów"

#: djoser/templates/email/activation.html:4
#, python-format
msgid "Account activation on %(site_name)s"
Expand Down
12 changes: 1 addition & 11 deletions djoser/locale/pt_BR/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n > 1);\n"

#: djoser/constants.py:4
msgid "Unable to login with provided credentials."
msgid "Unable to log in with provided credentials."
msgstr "Não foi possível fazer login com os dados inseridos."

#: djoser/constants.py:5
Expand Down Expand Up @@ -55,16 +55,6 @@ msgstr "Não existe um usuário com o email fornecido."
msgid "Unable to create account."
msgstr "Não foi possível criar a conta."

#: djoser/constants.py:15
msgid ""
"User model does not contain specified email field. Please see http://djoser."
"readthedocs.io/en/latest/settings.html#USER_EMAIL_FIELD_NAME for more "
"details."
msgstr ""
"O usuário fornecido não possui campo de email definido. Por favor, confira "
"http://djoser.readthedocs.io/en/latest/settings.html#USER_EMAIL_FIELD_NAME "
"para mais detalhes."

#: djoser/templates/email/activation.html:4
#, python-format
msgid "Account activation on %(site_name)s"
Expand Down
11 changes: 1 addition & 10 deletions djoser/locale/ru_RU/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ msgstr ""
"X-Poedit-SearchPath-0: .\n"

#: djoser/constants.py:4
msgid "Unable to login with provided credentials."
msgid "Unable to log in with provided credentials."
msgstr "Невозможно войти с предоставленными учетными данными."

#: djoser/constants.py:5
Expand Down Expand Up @@ -60,15 +60,6 @@ msgstr "Пользователь с данным адресом электрон
msgid "Unable to create account."
msgstr "Невозможно создать учетную запись."

#: djoser/constants.py:15
msgid ""
"User model does not contain specified email field. Please see http://djoser."
"readthedocs.io/en/latest/settings.html#USER_EMAIL_FIELD_NAME for more details."
msgstr ""
"Модель пользователя не содержит указанное поле для электронной почты. Пожалуйста, "
"посмотрите http://djoser.readthedocs.io/en/latest/settings."
"html#USER_EMAIL_FIELD_NAME для получения дополнительной информации."

#: djoser/templates/email/activation.html:4
#, python-format
msgid "Account activation on %(site_name)s"
Expand Down
7 changes: 4 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ coverage = "^7.2.2"
pytest-cov = "^4.0.0"
pytest-django = "^4.5.2"
tox = "^4.4.8"
babel = "^2.12.1"

[tool.poetry.group.code-quality.dependencies]
black = "^23.1.0"
Expand Down
36 changes: 36 additions & 0 deletions testproject/testapp/tests/test_translations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from io import StringIO

from babel.messages.pofile import read_po
from django.utils.encoding import force_str
import pathlib

from djoser.constants import Messages


def test_constants_translations_are_up_to_date():
messages = {force_str(v) for k, v in vars(Messages).items() if k.isupper()}
ERROR_TEMPALTE = (
"Error message '{message}' was found in "
"locale {locale} but can't be found in the messages class"
)

root = pathlib.Path(__file__).parent.parent.parent.parent
locale_dir = root / "djoser" / "locale"
for specific_locale in locale_dir.iterdir():
po_file = specific_locale / "LC_MESSAGES" / "django.po"
po_contents = po_file.read_text()
with StringIO() as buf:
buf.write(po_contents)
buf.seek(0)
parsed_po = read_po(buf)
for message in parsed_po:
if not message.id:
continue
if "djoser/constants.py" not in [loc[0] for loc in message.locations]:
continue
if message.id not in messages:
raise ValueError(
ERROR_TEMPALTE.format(
message=message.id, locale=specific_locale.name
)
)