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

Do not base interface language on LC_TIME #230

Closed
aostruszka opened this issue Jan 15, 2018 · 15 comments
Closed

Do not base interface language on LC_TIME #230

aostruszka opened this issue Jan 15, 2018 · 15 comments

Comments

@aostruszka
Copy link
Contributor

sys_locale = locale.getlocale(locale.LC_TIME)[0]

I've got maybe non-standard locale settings since I'm from Poland but I prefer to have interface in English. So I have LANG/LANGUAGE set to en_US.utf8/en_US but I set "LC_CTYPE=pl_PL.utf8 LC_COLLATE=pl_PL.utf8" in my dot files. In default settings generated by the system (/etc/default/locale) I see also LC_TIME set to pl_PL.utf8 so I can change that but actually I prefer having 24h clock instead of AM/PM.

So I'd like to ask for possibility to:

  1. Base the interface language used on LANG/LC_MESSAGES instead of LC_TIME
  2. Advanced option would be to split locale: having one for time and one for interface/messages (maybe this option is not even needed since correctly installed locale should be respecting LC_TIME override)

Best regards
Andrzej

PS. If you agree that such modification make sense (to me it does - since MESSAGES seems to be more specific to tell what kind of language I want to see in the interface) then it looks to me like the following patch achieves both points:

--- Utility-orig.py	2018-01-15 11:56:09.990407876 +0100
+++ Utility.py	2018-01-15 12:02:31.688636092 +0100
@@ -91,13 +91,13 @@
         GLib.idle_add(target_function)
 
 
-def system_locale():
+def system_locale(category=locale.LC_MESSAGES):
     """
     Return the system locale. If not available, return en_US.UTF-8.
     """
     try:
         locale.setlocale(locale.LC_ALL, '')
-        sys_locale = locale.getlocale(locale.LC_TIME)[0]
+        sys_locale = locale.getlocale(category)[0]
         if not sys_locale:
             sys_locale = 'en_US.UTF-8'
         return sys_locale
@@ -110,7 +110,7 @@
     """
     Format time based on the system time.
     """
-    sys_locale = system_locale()
+    sys_locale = system_locale(locale.LC_TIME)
     return babel.dates.format_time(time, format='short', locale=sys_locale)
@slgobinath
Copy link
Owner

Hi,
The same issue is reported in #225. Did you check your suggested patch? If it is working as expected, could you please send a PR?

Thanks

@aostruszka
Copy link
Contributor Author

It is working for me (I've asked others in #225 to test) - if it is working for others then I can create PR, but I do not know your app well so there might be other points to be fixed. For me I get what I want - interface in English and time in 24h format.

@slgobinath
Copy link
Owner

After their confirmation, please send a PR.
If there are any other issues, I will take care of them.

Thanks

@hartwork
Copy link
Contributor

hartwork commented Jan 15, 2018

The patch looks like the right direction to me.

@leedoyle
Copy link

leedoyle commented Jan 15, 2018

I solved the problem by specifying both the locale and time locale. I want safeeyes to use a locale that is not my system locale, so the aostruszka's patch doesn't meet my requirements. However, if I wasn't able to set the locale I need, I would be glad to use @aostruszka 's patch.

@leedoyle
Copy link

I find that this should be configurable at the very least by editing a .config file, not the program's source code.

@slgobinath
Copy link
Owner

Okay, I will follow from this and fix the issue with a configurable alternative.
I am little busy this week. I will fix this issue in the coming weekend.

@hartwork
Copy link
Contributor

I want safeeyes to use a locale that is not my system locale, so the aostruszka's patch doesn't meet my requirements.

@leedoyle for a workaround you could start safeeyes like LC_TIME=en_US.utf8 safeeyes on the shell or adjust a copy of safeeyes.desktop put to ~/.local/share/applications/, I believe. Tested former so far.

@leedoyle
Copy link

leedoyle commented Jan 15, 2018

@hartwork well, here's how I did it (quick and dirty)

def system_locale():
    """
    Return the system locale. If not available, return en_US.UTF-8.
    """
    try:
        locale.setlocale(locale.LC_ALL, '')
#        sys_locale = locale.getlocale(locale.LC_TIME)[0]
        if not sys_locale:
            sys_locale = 'de_DE.UTF-8'
        return sys_locale
    except BaseException:
        # Some systems does not return proper locale
        return 'de_DE.UTF-8'


def format_time(time):
    """
    Format time based on the system time.
    """
    sys_locale = 'ru_RU.UTF8'
#    sys_locale = system_locale(locale.LC_TIME)
    return babel.dates.format_time(time, format='short', locale=sys_locale)


@aostruszka
Copy link
Contributor Author

@leedoyle
You are hardcoding the result you want. Try instead revert the Utility.py to original state, copy and paste the patch I've included into some file (say safe_eyes.patch) then in the directory with Utility.py execute: patch < safe_eyes.patch. This will allow to configure settings via environment variables.

You can test what results you'll get by playing with python shell. Just start it with different values for LANG/LC_TIME (e.g. LANG=ru_RU.utf8 LC_TIME=de_DE.utf8 python for Russian interface with German time formatting) and issue:

import locale
locale.setlocale(locale.LC_ALL, '')

and observe the values of LC_MESSAGES and LC_TIME.

For example I have LANG=en_US.utf8 (which is the system setting). This governs all categories unless overridden by more specific settings - and in my case I set LC_CTYPE, LC_COLLATE and LC_TIME to pl_PL.utf8. In that case LC_MESSAGES gets value from LANG (it could be overridden with explicit LC_MESSAGES= assignment) and LC_TIME from explicit setting and I have interface in English but time in 24h (instead of AM/PM).

So if you have system locale X then you should have LANG=X. If you want safeeyes to be in:

  • Y with time in Z -> LC_MESSAGES=Y LC_TIME=Z
  • Y with time in X -> LC_MESSAGES=Y
  • X with time in Y -> LC_TIME=Y
  • and so on...

So for me this works as I expect. LANG/LC_* settings configure locale for my whole session and safeeyes (with the patch) adapt to it. However if you want safeeyes to have different settings from the rest of your session then you would need to ask @slgobinath to implement it :).

Best regards
Andrzej

@slgobinath
Copy link
Owner

Hi all,
Sorry for my delay due to my busy schedule.
According to my testings, @aostruszka's patch resolves the issue.
If you run Safe Eyes (master branch) using the following command, Safe Eyes should use Russian for interface and German for time format.

LANG=ru_RU.utf8 LC_TIME=de_DE.utf8 python3 -m safeeyes

I find it more generic and the standard way to go.
Do we still need a configuration to adjust them? WDYT?

@hartwork
Copy link
Contributor

Do we still need a configuration to adjust them? WDYT?

With the fix in, I won't need another way to configure locales, personally.

@slgobinath
Copy link
Owner

Thanks for all your support. I have released Safe Eyes 2.0.3 including this fix.

@slgobinath
Copy link
Owner

@hartwork Please note that I have immediately released 2.0.4 to fix another bug I have noticed after releasing 2.0.3.

@hartwork
Copy link
Contributor

@slgobinath thanks, bumped to 2.0.4 now in Gentoo.

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

No branches or pull requests

4 participants