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

Fixes locale problems #401

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

kdschlosser
Copy link
Member

There are multiple locale issues between wxPython and the locale module in Python. This is an attempt to correct 3 of those issues. The first one is with wxPython and GetSystemLocale not returning the correct locale. The second is with wxPythons use of LCID's to identify a locale. While I have not correct the use of the LCID's I have correct it's use of LCID's when using wx.Locale.GetInfo().

The 3rd problem is in Pythons locale module. The locale module does not create a proper locale string for setting the locale. If you pass "en_US" to locale.setlocale it will fail. with the changes I have made it will no longer fail. It also returns the correct locale string for windows. When using python 2.7 on windows it seems that you must use english language name_english country name.code page. So now if you pass en_US to locale.setlocale it is going to query windows and get the english names for the language and country and append a modified version of the code page that has been supplied if one was supplied.

There are multiple locale issues between wxPython and the locale module in Python. This is an attempt to correct 3 of those issues. The first one is with wxPython and GetSystemLocale not returning the correct locale. The second is with wxPythons use of LCID's to identify a locale. While I have not correct the use of the LCID's I have correct it's use of LCID's when using wx.Locale.GetInfo().

The 3rd problem is in Pythons locale module. The locale module does not create a proper locale string for setting the locale. If you pass "en_US" to locale.setlocale it will fail. with the changes I have made it will no longer fail. It also returns the correct locale string for windows. When using python 2.7 on windows it seems that you must use english language name_english country name.code page. So now if you pass en_US to locale.setlocale it is going to query windows and get the english names for the language and country and append a modified version of the code page that has been supplied if one was supplied.
@kdschlosser kdschlosser added this to the v0.5 milestone May 2, 2020
if index == wx.LOCALE_TIME_FMT:
return '%H:%M:%S'
if index == wx.LOCALE_DATE_TIME_FMT:
return '%m/%d/%y %H:%M:%S'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid too many return statements within this function.

if index == wx.LOCALE_LONG_DATE_FMT:
return '%A, %B %d, %Y'
if index == wx.LOCALE_TIME_FMT:
return '%H:%M:%S'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid too many return statements within this function.

@@ -0,0 +1,348 @@
# -*- coding: utf-8 -*-
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File WXLocale.py has 265 lines of code (exceeds 250 allowed). Consider refactoring.

return LANGID(lcid.value)


def GetInfo(index, cat=wx.LOCALE_CAT_DEFAULT):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function GetInfo has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.

LOCALE_STIMEFORMAT = 0x00001003


def GetLocaleInfo(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function GetLocaleInfo has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.

return output


def GetLocaleInfoEx(lp_locale_name, lc_type):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function GetLocaleInfoEx has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

@@ -0,0 +1,552 @@

import locale as _locale
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File __init__.py has 286 lines of code (exceeds 250 allowed). Consider refactoring.

LCTYPE = DWORD


def GetLocaleInfoEx(lp_locale_name, lc_type):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function GetLocaleInfoEx has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

return output


def getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function getdefaultlocale has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.

return locale[0], code_page


def setlocale(category, locale=None):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function setlocale has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

return value


def FormatDate(value):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FormatDate has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

return value


def GetLCType(index, cat):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function GetLCType has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

return lc_type


def GetLocaleInfo(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function GetLocaleInfo has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.

return LCID(lang_id)


def GetInfoDefaults(index):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function GetInfoDefaults has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

LCTYPE = DWORD


def GetLocaleInfoEx(lp_locale_name, lc_type):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function GetLocaleInfoEx has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

_original_resetlocale = _locale.resetlocale


def getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function getdefaultlocale has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.

return False


def setlocale(category, locale=None):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function setlocale has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.

I updated the Options dialog so it will display all languages and locales that have translations coded into EG. I also expanded the number of flags to a total of 249.

The language selection now displays the language and country name in the native script if available, otherwise it is displayed in english.
self.__locale_type = 3
return ''

@property
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 4 locations. Consider refactoring.

self.__locale_type = 3
return ''

@property
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 4 locations. Consider refactoring.

self.__locale_type = 3
return ''

@property
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 4 locations. Consider refactoring.

else:
raise ValueError('Unknown Locale String')

@property
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 4 locations. Consider refactoring.

return False


def EnumLocales():
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function EnumLocales has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.

self.code_page = code_page
self.__locale_type = 0

def __str__(self):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function __str__ has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.

)


def GetLocaleInfoEx(lp_locale_name, lc_type):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function GetLocaleInfoEx has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

@@ -0,0 +1,659 @@
# -*- coding: utf-8 -*-
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File Locale.py has 363 lines of code (exceeds 250 allowed). Consider refactoring.

return False


def setlocale(category, locale=None):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function setlocale has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.

_original_resetlocale = _locale.resetlocale


def getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function getdefaultlocale has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.

@codeclimate
Copy link

codeclimate bot commented May 11, 2020

Code Climate has analyzed commit 847c3b2 and detected 15 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 11
Duplication 4

View more on Code Climate.

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

Successfully merging this pull request may close these issues.

None yet

2 participants