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

Single file languages list #64

Merged
merged 4 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/user-guide/translation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ Adding a new language
---------------------
If you want to support a new language:

- add it in ``./scripts/update_translation_files`` in the language list,
- add it in ``scan/libmailgoose/language.py`` in the ``Language`` enum,
- add it in ``scan/libmailgoose/languages.txt``,
- run ``./scripts/update_translation_files`` and fill ``.po`` files for the UI messages for your language in ``./app/translations``
(**you may skip that part if you want only the library error messages to be translated**),
- add the error message translations for your language in ``scan/libmailgoose/translate.py``.
Expand Down
8 changes: 3 additions & 5 deletions scan/libmailgoose/language.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from enum import Enum
from pathlib import Path


class Language(Enum):
en_US = "en_US"
lt_LT = "lt_LT"
pl_PL = "pl_PL"
with open(Path(__file__).parent / "languages.txt") as f:
Language = Enum("Language", {line.strip(): line.strip() for line in f}) # type: ignore
3 changes: 3 additions & 0 deletions scan/libmailgoose/languages.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pl_PL
en_US
lt_LT
6 changes: 3 additions & 3 deletions scan/libmailgoose/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


TRANSLATIONS = {
Language.lt_LT: [
Language.lt_LT: [ # type: ignore
(
"SPF '~all' or '-all' directive not found. We recommend adding it, as it describes "
"what should happen with messages that fail SPF verification. For example, "
Expand Down Expand Up @@ -435,7 +435,7 @@
"DKIM parašo patvirtinimo metu įvyko nežinoma klaida.",
),
],
Language.pl_PL: [
Language.pl_PL: [ # type: ignore
(
"SPF '~all' or '-all' directive not found. We recommend adding it, as it describes "
"what should happen with messages that fail SPF verification. For example, "
Expand Down Expand Up @@ -985,7 +985,7 @@ def translate(
language: Language,
nonexistent_translation_handler: Optional[Callable[[str], str]] = None,
) -> str:
if language == Language.en_US:
if language == Language.en_US: # type: ignore
return message

return _translate_using_dictionary(
Expand Down
2 changes: 2 additions & 0 deletions scan/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
license="BSD",
url="https://github.com/CERT-Polska/mailgoose",
packages=["libmailgoose"],
package_data={"": ["languages.txt"]},
include_package_data=True,
scripts=[],
classifiers=[
"Programming Language :: Python :: 3",
Expand Down
4 changes: 2 additions & 2 deletions scripts/update_translation_files
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash

LOCALES="pl_PL en_US lt_LT"

cd $(dirname $0)/..

LOCALES=`cat scan/libmailgoose/languages.txt`

if [ ! -d .venv.translations ]
then
python3 -m venv .venv.translations
Expand Down
Loading