Commit e0376d66e6fcadb0540ac1828fbbeed28347e238
1 parent
1a61d02a
Exists in
master
and in
6 other branches
ENH: Beginning of the internationalization, reffer ticket 52
Showing
5 changed files
with
211 additions
and
4 deletions
Show diff stats
.gitattributes
@@ -127,6 +127,7 @@ invesalius/gui/dicom_preview_panel.py -text | @@ -127,6 +127,7 @@ invesalius/gui/dicom_preview_panel.py -text | ||
127 | invesalius/gui/frame.py -text | 127 | invesalius/gui/frame.py -text |
128 | invesalius/gui/import_data_wizard.py -text | 128 | invesalius/gui/import_data_wizard.py -text |
129 | invesalius/gui/import_panel.py -text | 129 | invesalius/gui/import_panel.py -text |
130 | +invesalius/gui/language_dialog.py -text | ||
130 | invesalius/gui/task_exporter.py -text | 131 | invesalius/gui/task_exporter.py -text |
131 | invesalius/gui/task_generic.py -text | 132 | invesalius/gui/task_generic.py -text |
132 | invesalius/gui/task_importer.py -text | 133 | invesalius/gui/task_importer.py -text |
@@ -139,6 +140,7 @@ invesalius/gui/widgets/foldpanelbar.py -text | @@ -139,6 +140,7 @@ invesalius/gui/widgets/foldpanelbar.py -text | ||
139 | invesalius/gui/widgets/gradient.py -text | 140 | invesalius/gui/widgets/gradient.py -text |
140 | invesalius/gui/widgets/listctrl.py -text | 141 | invesalius/gui/widgets/listctrl.py -text |
141 | invesalius/gui/widgets/slice_menu.py -text | 142 | invesalius/gui/widgets/slice_menu.py -text |
143 | +invesalius/i18n.py -text | ||
142 | invesalius/invesalius.py -text | 144 | invesalius/invesalius.py -text |
143 | invesalius/presets.py -text | 145 | invesalius/presets.py -text |
144 | invesalius/project.py -text | 146 | invesalius/project.py -text |
@@ -0,0 +1,130 @@ | @@ -0,0 +1,130 @@ | ||
1 | +#-------------------------------------------------------------------------- | ||
2 | +# Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas | ||
3 | +# Copyright: (C) 2001 Centro de Pesquisas Renato Archer | ||
4 | +# Homepage: http://www.softwarepublico.gov.br | ||
5 | +# Contact: invesalius@cti.gov.br | ||
6 | +# License: GNU - GPL 2 (LICENSE.txt/LICENCA.txt) | ||
7 | +#-------------------------------------------------------------------------- | ||
8 | +# Este programa e software livre; voce pode redistribui-lo e/ou | ||
9 | +# modifica-lo sob os termos da Licenca Publica Geral GNU, conforme | ||
10 | +# publicada pela Free Software Foundation; de acordo com a versao 2 | ||
11 | +# da Licenca. | ||
12 | +# | ||
13 | +# Este programa eh distribuido na expectativa de ser util, mas SEM | ||
14 | +# QUALQUER GARANTIA; sem mesmo a garantia implicita de | ||
15 | +# COMERCIALIZACAO ou de ADEQUACAO A QUALQUER PROPOSITO EM | ||
16 | +# PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais | ||
17 | +# detalhes. | ||
18 | +#-------------------------------------------------------------------------- | ||
19 | + | ||
20 | +import os | ||
21 | +import wx | ||
22 | +import wx.combo | ||
23 | + | ||
24 | +import i18n | ||
25 | +import constants as const | ||
26 | + | ||
27 | +def create(parent): | ||
28 | + return LanguageDialog(parent) | ||
29 | + | ||
30 | +class LanguageDialog(wx.Dialog): | ||
31 | + """Class define the language to be used in the InVesalius, | ||
32 | + exist chcLanguage that list language EN and PT. The language | ||
33 | + selected is writing in the config.ini""" | ||
34 | + | ||
35 | + def __init__(self, parent, startApp = None): | ||
36 | + | ||
37 | + #self.__TranslateMessage__() | ||
38 | + | ||
39 | + self.pre = pre = wx.PreDialog() | ||
40 | + pre.SetExtraStyle(wx.DIALOG_MODAL) | ||
41 | + | ||
42 | + pre.Create(parent, -1, 'Language selection', size = wx.Size(250, 150), | ||
43 | + pos = wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE) | ||
44 | + self.PostCreate(pre) | ||
45 | + | ||
46 | + icon_path = os.path.join(const.ICON_DIR, "invesalius.ico") | ||
47 | + pre.SetIcon(wx.Icon(icon_path, wx.BITMAP_TYPE_ICO)) | ||
48 | + | ||
49 | + self.pnl = wx.Panel(id=-1, name='pnl', | ||
50 | + parent=pre, pos=wx.Point(0, 0), size=wx.Size(250, 160), | ||
51 | + style=wx.TAB_TRAVERSAL) | ||
52 | + | ||
53 | + self.txtMsg = wx.StaticText(id=1, | ||
54 | + label=('Choose user interface language'), | ||
55 | + name='txtMsg', parent=self.pnl, pos=wx.Point(15, | ||
56 | + 10), size=wx.Size(200, 13), style=0) | ||
57 | + | ||
58 | + self.bxSizer = wx.BoxSizer(orient=wx.VERTICAL) | ||
59 | + self.bxSizer.AddWindow(self.pnl, 1, wx.GROW|wx.ALIGN_CENTRE) | ||
60 | + | ||
61 | + btnsizer = wx.StdDialogButtonSizer() | ||
62 | + | ||
63 | + if wx.Platform != "__WXMSW__": | ||
64 | + btn = wx.ContextHelpButton(self) | ||
65 | + btnsizer.AddButton(btn) | ||
66 | + | ||
67 | + btnsizer.SetOrientation(wx.CENTER) | ||
68 | + | ||
69 | + btn = wx.Button(self, wx.ID_OK) | ||
70 | + btn.SetDefault() | ||
71 | + btnsizer.AddButton(btn) | ||
72 | + | ||
73 | + btn = wx.Button(self, wx.ID_CANCEL) | ||
74 | + btnsizer.AddButton(btn) | ||
75 | + btnsizer.Realize() | ||
76 | + | ||
77 | + self.bxSizer.AddSizer(btnsizer, 1, wx.GROW|wx.ALIGN_CENTRE) | ||
78 | + | ||
79 | + self.__init_combobox_bitmap__() | ||
80 | + | ||
81 | + self.SetSizer(self.bxSizer) | ||
82 | + | ||
83 | + | ||
84 | + def __init_combobox_bitmap__(self): | ||
85 | + """Initialize combobox bitmap""" | ||
86 | + | ||
87 | + self.locales = i18n.GetLocales().values() | ||
88 | + | ||
89 | + self.locales_key = i18n.GetLocales().keys() | ||
90 | + self.os_locale = i18n.GetLocaleOS() | ||
91 | + | ||
92 | + | ||
93 | + self.bitmapCmb = bitmapCmb = wx.combo.BitmapComboBox(self.pnl, pos=(32,34), | ||
94 | + size=(180,22), style=wx.CB_READONLY) | ||
95 | + | ||
96 | + bmp_brazilian_flag = wx.Bitmap(os.path.join(const.ICON_DIR, "pt_BR.bmp"), wx.BITMAP_TYPE_BMP) | ||
97 | + bmp_english_flag = wx.Bitmap(os.path.join(const.ICON_DIR, "en_GB.bmp"), wx.BITMAP_TYPE_BMP) | ||
98 | + bmp_spanish_flag = wx.Bitmap(os.path.join(const.ICON_DIR, "es.bmp"), wx.BITMAP_TYPE_BMP) | ||
99 | + | ||
100 | + bitmapCmb.Append(self.locales[0], bmp_brazilian_flag,"pt_BR") | ||
101 | + bitmapCmb.Append(self.locales[1], bmp_english_flag,"en_GB") | ||
102 | + bitmapCmb.Append(self.locales[2], bmp_spanish_flag,"es") | ||
103 | + | ||
104 | + | ||
105 | + if (self.os_locale[0:2] == 'pt'): | ||
106 | + bitmapCmb.SetSelection(0) | ||
107 | + elif (self.os_locale[0:2] == 'es'): | ||
108 | + bitmapCmb.SetSelection(2) | ||
109 | + else: | ||
110 | + bitmapCmb.SetSelection(1) | ||
111 | + | ||
112 | + def GetSelectedLanguage(self): | ||
113 | + """Return String with Selected Language""" | ||
114 | + return self.locales_key[self.bitmapCmb.GetSelection()] | ||
115 | + | ||
116 | + def __TranslateMessage__(self): | ||
117 | + """Translate Messages of the Window""" | ||
118 | + os_language = ivI18n.GetLocaleOS() | ||
119 | + | ||
120 | + if(os_language[0:2] == 'pt'): | ||
121 | + _ = ivI18n.ParseLang('pt_BR') | ||
122 | + elif(os_language[0:2] == 'es'): | ||
123 | + _ = ivI18n.ParseLang('es') | ||
124 | + else: | ||
125 | + _ = ivI18n.ParseLang('en_GB') | ||
126 | + | ||
127 | + def Cancel(self, event): | ||
128 | + """Close Frm_Language""" | ||
129 | + self.Close() | ||
130 | + event.Skip() |
@@ -0,0 +1,46 @@ | @@ -0,0 +1,46 @@ | ||
1 | +#-------------------------------------------------------------------------- | ||
2 | +# Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas | ||
3 | +# Copyright: (C) 2001 Centro de Pesquisas Renato Archer | ||
4 | +# Homepage: http://www.softwarepublico.gov.br | ||
5 | +# Contact: invesalius@cti.gov.br | ||
6 | +# License: GNU - GPL 2 (LICENSE.txt/LICENCA.txt) | ||
7 | +#-------------------------------------------------------------------------- | ||
8 | +# Este programa e software livre; voce pode redistribui-lo e/ou | ||
9 | +# modifica-lo sob os termos da Licenca Publica Geral GNU, conforme | ||
10 | +# publicada pela Free Software Foundation; de acordo com a versao 2 | ||
11 | +# da Licenca. | ||
12 | +# | ||
13 | +# Este programa eh distribuido na expectativa de ser util, mas SEM | ||
14 | +# QUALQUER GARANTIA; sem mesmo a garantia implicita de | ||
15 | +# COMERCIALIZACAO ou de ADEQUACAO A QUALQUER PROPOSITO EM | ||
16 | +# PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais | ||
17 | +# detalhes. | ||
18 | +#-------------------------------------------------------------------------- | ||
19 | + | ||
20 | +import locale | ||
21 | +import sys | ||
22 | +import gettext | ||
23 | +import os | ||
24 | +import ConfigParser | ||
25 | + | ||
26 | + | ||
27 | +def GetLocales(): | ||
28 | + """Return a dictionary which defines supported languages""" | ||
29 | + locale_descriptions = {'es':'Espa\xf1ol',\ | ||
30 | + 'en_GB':'English',\ | ||
31 | + 'pt_BR':'Portugu\xeas (Brasil)'} | ||
32 | + return locale_descriptions | ||
33 | + | ||
34 | +def GetLocaleOS(): | ||
35 | + """Return language of the operating system.""" | ||
36 | + os_language = locale.getdefaultlocale()[0] | ||
37 | + return os_language | ||
38 | + | ||
39 | +def InstallLanguage(lang): | ||
40 | + | ||
41 | + lang = gettext.translation('invesalius', lang_dir,\ | ||
42 | + languages=[language]) | ||
43 | + lang.install() | ||
44 | + _ = lang.gettext | ||
45 | + return _ | ||
46 | + |
invesalius/invesalius.py
@@ -21,6 +21,9 @@ import multiprocessing | @@ -21,6 +21,9 @@ import multiprocessing | ||
21 | from optparse import OptionParser | 21 | from optparse import OptionParser |
22 | import os | 22 | import os |
23 | import sys | 23 | import sys |
24 | + | ||
25 | +import gui.language_dialog as lang_dlg | ||
26 | +import i18n | ||
24 | from session import Session | 27 | from session import Session |
25 | 28 | ||
26 | 29 | ||
@@ -68,7 +71,29 @@ class SplashScreen(wx.SplashScreen): | @@ -68,7 +71,29 @@ class SplashScreen(wx.SplashScreen): | ||
68 | # main frame now | 71 | # main frame now |
69 | if self.fc.IsRunning(): | 72 | if self.fc.IsRunning(): |
70 | self.fc.Stop() | 73 | self.fc.Stop() |
71 | - self.ShowMain() | 74 | + |
75 | + session = Session() | ||
76 | + if not (session.ReadSession()): | ||
77 | + session.CreateItens() | ||
78 | + | ||
79 | + lang = session.GetLanguage() | ||
80 | + #TODO: temporary | ||
81 | + lang = "pt_BR" | ||
82 | + if not(lang): | ||
83 | + | ||
84 | + ldlg = lang_dlg.create(parent=None) | ||
85 | + ldlg.Show() | ||
86 | + | ||
87 | + if (ldlg.ShowModal() == wx.ID_OK): | ||
88 | + lang = ldlg.GetSelectedLanguage() | ||
89 | + session.SetLanguage(lang) | ||
90 | + i18n.InstallLanguage(lang) | ||
91 | + else: | ||
92 | + #i18n.InstallLanguage(lang) | ||
93 | + self.ShowMain() | ||
94 | + | ||
95 | + #print "not....." | ||
96 | + #self.ShowMain() | ||
72 | 97 | ||
73 | 98 | ||
74 | def ShowMain(self): | 99 | def ShowMain(self): |
@@ -107,8 +132,6 @@ def parse_comand_line(): | @@ -107,8 +132,6 @@ def parse_comand_line(): | ||
107 | options, args = parser.parse_args() | 132 | options, args = parser.parse_args() |
108 | 133 | ||
109 | session = Session() | 134 | session = Session() |
110 | - if not (session.ReadSession()): | ||
111 | - session.CreateItens() | ||
112 | 135 | ||
113 | if options.debug: | 136 | if options.debug: |
114 | # The user passed the debug option? | 137 | # The user passed the debug option? |
invesalius/session.py
@@ -126,7 +126,13 @@ class Session(object): | @@ -126,7 +126,13 @@ class Session(object): | ||
126 | dict = plistlib.readPlist(main_plist) | 126 | dict = plistlib.readPlist(main_plist) |
127 | for key in dict: | 127 | for key in dict: |
128 | setattr(self, key, dict[key]) | 128 | setattr(self, key, dict[key]) |
129 | - | 129 | + |
130 | + def GetLanguage(self): | ||
131 | + return self.language | ||
132 | + | ||
133 | + def SetLanguage(self, language): | ||
134 | + self.language = language | ||
135 | + | ||
130 | def ReadSession(self): | 136 | def ReadSession(self): |
131 | 137 | ||
132 | config = ConfigParser.ConfigParser() | 138 | config = ConfigParser.ConfigParser() |