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
base: master
Are you sure you want to change the base?
Fixes locale problems #401
Conversation
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.
eg/WinApi/wx_patches/WXLocale.py
Outdated
if index == wx.LOCALE_TIME_FMT: | ||
return '%H:%M:%S' | ||
if index == wx.LOCALE_DATE_TIME_FMT: | ||
return '%m/%d/%y %H:%M:%S' |
There was a problem hiding this comment.
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.
eg/WinApi/wx_patches/WXLocale.py
Outdated
if index == wx.LOCALE_LONG_DATE_FMT: | ||
return '%A, %B %d, %Y' | ||
if index == wx.LOCALE_TIME_FMT: | ||
return '%H:%M:%S' |
There was a problem hiding this comment.
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 -*- |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
eg/WinApi/locale_patches/__init__.py
Outdated
LCTYPE = DWORD | ||
|
||
|
||
def GetLocaleInfoEx(lp_locale_name, lc_type): |
There was a problem hiding this comment.
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.
eg/WinApi/locale_patches/__init__.py
Outdated
return output | ||
|
||
|
||
def getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')): |
There was a problem hiding this comment.
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.
eg/WinApi/locale_patches/__init__.py
Outdated
return locale[0], code_page | ||
|
||
|
||
def setlocale(category, locale=None): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
eg/WinApi/locale_patches/win_api.py
Outdated
LCTYPE = DWORD | ||
|
||
|
||
def GetLocaleInfoEx(lp_locale_name, lc_type): |
There was a problem hiding this comment.
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')): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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(): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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 -*- |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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')): |
There was a problem hiding this comment.
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.
Code Climate has analyzed commit 847c3b2 and detected 15 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
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.