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

[Request] Split translations for some strings #97

Closed
LukaszH77 opened this issue Mar 10, 2024 · 15 comments
Closed

[Request] Split translations for some strings #97

LukaszH77 opened this issue Mar 10, 2024 · 15 comments

Comments

@LukaszH77
Copy link
Contributor

There are several strings used multiple times in different contexts. This works in English, but for languages that use noun declension (i.e. Polish) not so much.

Example:
"High" is used in mousam.py on line 276 (and also 286, but that's missing from mousam.pot), and in weatherData.py on lines 120, 133 and 142. In Polish translation, that should be "Max.", "Wysoki", "Wysoka" and "Wysokie".

The same with "Moderate", "Low" and "Extreme".

@amit9838
Copy link
Owner

I have made more strings translatable (like line no 286),
But about splitting the string by context - i think it is not possible here if the string is same.
If you you have idea, let me know 🙂

@LukaszH77
Copy link
Contributor Author

I tried to separate translations for each string in a forked repo, but you were right, it is not possible. I will have to come up with translations for those strings that fit all occurrences.

@LukaszH77
Copy link
Contributor Author

I've asked my friend who has experience making translatable apps. He said there is a way to do it: strings like "hight_humidity" and "high_pressure" in the code with translation in en.po to "High" in both places, and "Wysoka" and "Wysokie" in pl.po.

@amit9838
Copy link
Owner

amit9838 commented Mar 11, 2024

Can you explain more clearly?

@LukaszH77
Copy link
Contributor Author

I'll try :)

Right now, the English version is hard-coded in the .py files, that's why there can be only one translation that covers all occurrences of these words.

According to my friend, the way to work around that is to use separate strings for them. So in weatherData.py there would be something like

def classify_humidity_level(uv_index):
    if uv_index < 50:
        return _("Low_Humidity")
    elif uv_index <= 80:
        return _("Moderate_Humidity")
    else:
        return _("High_Humidity")

def classify_presssure_level(pressure):
    if pressure < 940:
        return _("Low_Pressure")
    elif pressure <= 1010:
        return _("Normal_Pressure")
    else:
        return _("High_Pressure")

And then in the en.po:

msgid "Low_Pressure"
msgstr "Low"

msgid "Low_Humidity"
msgstr "Low"

and in pl.po

msgid "Low_Pressure"
msgstr "Niskie"

msgid "Low_Humidity"
msgstr "Niska"

@amit9838
Copy link
Owner

O I got you, so how are we going to deal with the non translated version? Like eng?

@LukaszH77
Copy link
Contributor Author

I started reading gettext docs to try to answer your question without bothering my friend and found something that may be useful: defining string context in a po file using msgctx.

I have to read a bit more and try it out to see if it can help here, and then I will let you know.

@LukaszH77
Copy link
Contributor Author

I've read more, and it should be simple, but I just can't get it to work in my Mousam fork.

Using my non-existing Python skills I managed to create a working example though :)

import gettext
gettext.bindtextdomain('gt', 'po')
gettext.textdomain('gt')

print("High as in high UV index:",gettext.pgettext("uvindex","High"))
print("High as in high humidity:",gettext.pgettext("humidity","High"))
print("High as in high polution:",gettext.pgettext("polution","High"))

I got gt.pot file using xgettext --keyword=pgettext:1c,2 --output=po/gt.pot -n -f po/POTFILES with context for each string:

#: GettextTest.py:5
msgctxt "uvindex"
msgid "High"
msgstr ""

#: GettextTest.py:6
msgctxt "humidity"
msgid "High"
msgstr ""

#: GettextTest.py:7
msgctxt "polution"
msgid "High"
msgstr ""

After translating pl.po and creating .mo file with msgfmt po/pl.po -o po/pl/LC_MESSAGES/gt.mo everything works as it should:

$ python3 GettextTest.py
High as in high UV index: Wysoki
High as in high humidity: Wysoka
High as in high polution: Wysokie
$ LANG=en python3 GettextTest.py
High as in high UV index: High
High as in high humidity: High
High as in high polution: High

But this is where my freshly aquired Python knowledge ends.

@amit9838
Copy link
Owner

That's nice , thnaks for all your efforts, i'll add these context wherever required.

@LukaszH77
Copy link
Contributor Author

After more messing around with the code I was able to get this to work:

obraz

Turns out I was missing gettext settings in mousam.in.

gettext.bindtextdomain('mousam', localedir)
gettext.textdomain('mousam')

If you want, I can make a PR with these changes later this week to save you some work.

@amit9838
Copy link
Owner

Sure , absolutely you can raise the pr.
I had a question here, looks like AM, PM is not visible anywhere in your version.
If possible can you help me that why it is not visible for you (visible for me), if there is any specific issue, ill fix that

@LukaszH77
Copy link
Contributor Author

LukaszH77 commented Mar 15, 2024

We don't use AM and PM in Polish and 24h time format is more natural for us than 12h.

@amit9838
Copy link
Owner

Ok, got it, but i wanted to know, what if I use 12h format in Polish, it should show AM , PM right?

@LukaszH77
Copy link
Contributor Author

Nope, because AM and PM means nothing to us. If anything that would be "przed południem" and "po południu", but it isn't really used to format time.

@amit9838
Copy link
Owner

Oh, got it, I'll add support for 24h in comming days. Thanks for the clarification 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants