Commit 946105095d62b1101200a18e28e07167a78302c6
1 parent
9f47af27
Exists in
master
and in
68 other branches
ADD: support internationalization, reffer ticket fix #52
Showing
2 changed files
with
32 additions
and
22 deletions
Show diff stats
invesalius/i18n.py
@@ -17,12 +17,12 @@ | @@ -17,12 +17,12 @@ | ||
17 | # detalhes. | 17 | # detalhes. |
18 | #-------------------------------------------------------------------------- | 18 | #-------------------------------------------------------------------------- |
19 | 19 | ||
20 | +import ConfigParser | ||
20 | import locale | 21 | import locale |
21 | -import sys | ||
22 | import gettext | 22 | import gettext |
23 | import os | 23 | import os |
24 | -import ConfigParser | ||
25 | 24 | ||
25 | +import constants as const | ||
26 | 26 | ||
27 | def GetLocales(): | 27 | def GetLocales(): |
28 | """Return a dictionary which defines supported languages""" | 28 | """Return a dictionary which defines supported languages""" |
@@ -36,11 +36,10 @@ def GetLocaleOS(): | @@ -36,11 +36,10 @@ def GetLocaleOS(): | ||
36 | os_language = locale.getdefaultlocale()[0] | 36 | os_language = locale.getdefaultlocale()[0] |
37 | return os_language | 37 | return os_language |
38 | 38 | ||
39 | -def InstallLanguage(lang): | 39 | +def InstallLanguage(language): |
40 | 40 | ||
41 | - lang = gettext.translation('invesalius', lang_dir,\ | 41 | + lang = gettext.translation('invesalius', const.LANGUAGE_DIR,\ |
42 | languages=[language]) | 42 | languages=[language]) |
43 | lang.install() | 43 | lang.install() |
44 | - _ = lang.gettext | ||
45 | - return _ | ||
46 | - | 44 | + return lang.gettext |
45 | + | ||
47 | \ No newline at end of file | 46 | \ No newline at end of file |
invesalius/invesalius.py
@@ -31,6 +31,7 @@ from session import Session | @@ -31,6 +31,7 @@ from session import Session | ||
31 | # ---------------------------------------------------------------------- | 31 | # ---------------------------------------------------------------------- |
32 | 32 | ||
33 | path = os.path.join(os.path.expanduser('~'), ".invesalius", "presets") | 33 | path = os.path.join(os.path.expanduser('~'), ".invesalius", "presets") |
34 | + | ||
34 | try: | 35 | try: |
35 | os.makedirs(path) | 36 | os.makedirs(path) |
36 | except OSError: | 37 | except OSError: |
@@ -44,13 +45,32 @@ import wx.lib.pubsub as ps | @@ -44,13 +45,32 @@ import wx.lib.pubsub as ps | ||
44 | 45 | ||
45 | class SplashScreen(wx.SplashScreen): | 46 | class SplashScreen(wx.SplashScreen): |
46 | def __init__(self): | 47 | def __init__(self): |
48 | + | ||
49 | + session = Session() | ||
50 | + if not (session.ReadSession()): | ||
51 | + session.CreateItens() | ||
52 | + | ||
53 | + lang = session.GetLanguage() | ||
54 | + | ||
55 | + if not(lang): | ||
56 | + | ||
57 | + ldlg = lang_dlg.create(parent=None) | ||
58 | + ldlg.Show() | ||
59 | + | ||
60 | + if (ldlg.ShowModal() == wx.ID_OK): | ||
61 | + lang = ldlg.GetSelectedLanguage() | ||
62 | + session.SetLanguage(lang) | ||
63 | + _ = i18n.InstallLanguage(lang) | ||
64 | + else: | ||
65 | + _ = i18n.InstallLanguage(lang) | ||
66 | + | ||
67 | + | ||
47 | bmp = wx.Image("../icons/splash_en.png").ConvertToBitmap() | 68 | bmp = wx.Image("../icons/splash_en.png").ConvertToBitmap() |
48 | wx.SplashScreen.__init__(self, bitmap=bmp, | 69 | wx.SplashScreen.__init__(self, bitmap=bmp, |
49 | splashStyle=wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT, | 70 | splashStyle=wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT, |
50 | milliseconds=1500, id=-1, parent=None) | 71 | milliseconds=1500, id=-1, parent=None) |
51 | self.Bind(wx.EVT_CLOSE, self.OnClose) | 72 | self.Bind(wx.EVT_CLOSE, self.OnClose) |
52 | - | ||
53 | - | 73 | + |
54 | from gui.frame import Frame | 74 | from gui.frame import Frame |
55 | from control import Controller | 75 | from control import Controller |
56 | from project import Project | 76 | from project import Project |
@@ -77,8 +97,7 @@ class SplashScreen(wx.SplashScreen): | @@ -77,8 +97,7 @@ class SplashScreen(wx.SplashScreen): | ||
77 | session.CreateItens() | 97 | session.CreateItens() |
78 | 98 | ||
79 | lang = session.GetLanguage() | 99 | lang = session.GetLanguage() |
80 | - #TODO: temporary | ||
81 | - lang = "pt_BR" | 100 | + |
82 | if not(lang): | 101 | if not(lang): |
83 | 102 | ||
84 | ldlg = lang_dlg.create(parent=None) | 103 | ldlg = lang_dlg.create(parent=None) |
@@ -88,12 +107,10 @@ class SplashScreen(wx.SplashScreen): | @@ -88,12 +107,10 @@ class SplashScreen(wx.SplashScreen): | ||
88 | lang = ldlg.GetSelectedLanguage() | 107 | lang = ldlg.GetSelectedLanguage() |
89 | session.SetLanguage(lang) | 108 | session.SetLanguage(lang) |
90 | i18n.InstallLanguage(lang) | 109 | i18n.InstallLanguage(lang) |
110 | + self.ShowMain() | ||
91 | else: | 111 | else: |
92 | - #i18n.InstallLanguage(lang) | 112 | + i18n.InstallLanguage(lang) |
93 | self.ShowMain() | 113 | self.ShowMain() |
94 | - | ||
95 | - #print "not....." | ||
96 | - #self.ShowMain() | ||
97 | 114 | ||
98 | 115 | ||
99 | def ShowMain(self): | 116 | def ShowMain(self): |
@@ -101,11 +118,9 @@ class SplashScreen(wx.SplashScreen): | @@ -101,11 +118,9 @@ class SplashScreen(wx.SplashScreen): | ||
101 | 118 | ||
102 | if self.fc.IsRunning(): | 119 | if self.fc.IsRunning(): |
103 | self.Raise() | 120 | self.Raise() |
104 | - | 121 | + |
105 | class InVesalius(wx.App): | 122 | class InVesalius(wx.App): |
106 | def OnInit(self): | 123 | def OnInit(self): |
107 | - #self.main = Frame(None) | ||
108 | - #self.control = Controller(self.main) | ||
109 | self.SetAppName("InVesalius 3") | 124 | self.SetAppName("InVesalius 3") |
110 | splash = SplashScreen() | 125 | splash = SplashScreen() |
111 | self.control = splash.control | 126 | self.control = splash.control |
@@ -113,10 +128,6 @@ class InVesalius(wx.App): | @@ -113,10 +128,6 @@ class InVesalius(wx.App): | ||
113 | splash.Show() | 128 | splash.Show() |
114 | 129 | ||
115 | return True | 130 | return True |
116 | - | ||
117 | - #def ShowFrame(self): | ||
118 | - # self.main.Show() | ||
119 | - # self.SetTopWindow(self.main) | ||
120 | 131 | ||
121 | def parse_comand_line(): | 132 | def parse_comand_line(): |
122 | """ | 133 | """ |