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

Automated testing for locale #57

Open
2 tasks
furkansimsekli opened this issue Jan 25, 2024 · 3 comments
Open
2 tasks

Automated testing for locale #57

furkansimsekli opened this issue Jan 25, 2024 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@furkansimsekli
Copy link
Member

furkansimsekli commented Jan 25, 2024

To be sure that every translation is available in every languages.

  • Create a keyword list (a script to extract translation keys from source code)
  • Check whether every department name has been translated
@furkansimsekli furkansimsekli added enhancement New feature or request good first issue Good for newcomers labels Jan 25, 2024
@div72
Copy link
Contributor

div72 commented Aug 31, 2024

What you essentially want is GNU gettext but you'll need a custom translation function that automatically deducts the language since you're not using a single language for the entire application.

Something like this (pseudocode):

_LANGUAGES = {l: gettext.translation("hu-announcement-bot", languages=[l]) for l in ["en", "tr", "fr"]}
def _(message: str):
    return _LANGUAGES[inspect.getcurrentframe().f_back.f_locals["language"]].gettext(message)

...

def subscribe(...):
    language = "en"
    print(_("Thanks for subscribing to %(department)s") % {"department": _(department)})

From there you can use xgettext like xgettext -o - test.py to extract the translation strings from the source.

@furkansimsekli
Copy link
Member Author

@div72
Using gettext means much more work at the beginning, the reason why I chose the way I handle translations now was because I wanted to keep things really really simple.

If gettext comes up with a perfect solution for #41, then I might think of using it honestly.

For this issue, writing a script to replicate what xgettext -o test.py should be rather easy (parse keys from decode() function calls (assuming every call is explicit)) and maintain a default language (either english or turkish) to fulfill at least one language and make it a guide for other translations.

@div72
Copy link
Contributor

div72 commented Sep 4, 2024

If gettext comes up with a perfect solution for #41, then I might think of using it honestly.

There's no perfect solution as that issue is kinda irrelevant. You can use % (%s/%(keyword)s style) or str.format({} {0} {keyword} style) with both the current or the gettext backend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants