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
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 29 additions & 24 deletions eg/Classes/OptionsDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

# Local imports
import eg
from eg.WinApi import Locale


INDENT_WIDTH = 18

Expand Down Expand Up @@ -80,14 +82,14 @@ def Configure(self, parent=None):
title=text.Title,
)

languageNames = eg.Translation.languageNames
languageList = ["en_EN"]
for item in os.listdir(eg.languagesDir):
name, ext = os.path.splitext(item)
if ext == ".py" and name in languageNames:
languageList.append(name)
languageList.sort()
languageNameList = [languageNames[x] for x in languageList]
locales = sorted(
(
locale for locale in Locale.EnumLocales()
if locale.iso_language == 'en' or locale.eg_has_language
),
key=lambda lng: lng.language_name
)

notebook = wx.Notebook(self, -1)
page1 = eg.Panel(notebook)
notebook.AddPage(page1, text.Tab1)
Expand Down Expand Up @@ -182,20 +184,17 @@ def OnDatestampKillFocus(_):
datestampCtrl.Bind(wx.EVT_KILL_FOCUS, OnDatestampKillFocus)

languageChoice = BitmapComboBox(page1, style=wx.CB_READONLY)
for name, code in zip(languageNameList, languageList):
filename = os.path.join(eg.imagesDir, "flags", "%s.png" % code)
if os.path.exists(filename):
image = wx.Image(filename)
image.Resize((16, 16), (0, 3))
bmp = image.ConvertToBitmap()
languageChoice.Append(name, bmp)
else:
languageChoice.Append(name)

if config.language not in languageList:
config.language='en_EN'

languageChoice.SetSelection(languageList.index(config.language))

for locale in locales:
languageChoice.Append(locale.label, locale.flag)

for locale in locales:
if locale.iso_code == config.language:
languageChoice.SetSelection(locale.label)
else:
languageChoice.SetStringSelection('English - United States')
config.language = 'en_US'

languageChoice.SetMinSize((150, -1))

buttonRow = eg.ButtonRow(self, (wx.ID_OK, wx.ID_CANCEL))
Expand Down Expand Up @@ -228,7 +227,7 @@ def OnDatestampKillFocus(_):

langGroupSizer = page1.VStaticBoxSizer(
text.LanguageGroup,
(languageChoice, 0, wx.LEFT | wx.RIGHT, INDENT_WIDTH),
(languageChoice, 0, wx.LEFT | wx.RIGHT | wx.EXPAND, INDENT_WIDTH),
)

page1Sizer = eg.VBoxSizer(
Expand Down Expand Up @@ -262,7 +261,13 @@ def OnDatestampKillFocus(_):
config.propResize = propResizeCtrl.GetValue()
config.useFixedFont = useFixedFontCtrl.GetValue()
config.datestamp = datestampCtrl.GetValue()
config.language = languageList[languageChoice.GetSelection()]

lang = languageChoice.GetStringSelection()
for locale in locales:
if locale.label == lang:
config.language = locale.iso_code
break

config.Save()
self.SetResult()

Expand Down
6 changes: 4 additions & 2 deletions eg/Init.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ def Traverse(root, moduleRoot):
Traverse(join(eg.mainDir, "eg"), "eg")
Traverse(eg.corePluginDir, "eg.CorePluginModule")


def Init():
import WinApi.pywin32_patches # NOQA
import WinApi.wx_patches # NOQA
import WinApi.locale_patches # NOQA
import WinApi.pywin32_patches # NOQA
import WinApi.wx_patches # NOQA
import WinApi.GenPaths # NOQA


Expand Down