1 """GNUmed I18n/L10n related widgets.
2 """
3
4 __version__ = '$Revision: 1.4 $'
5 __author__ = 'karsten.hilbert@gmx.net'
6 __license__ = 'GPL (details at http://www.gnu.org)'
7
8
9 import logging, sys
10
11
12
13 import wx
14
15
16
17 if __name__ == '__main__':
18 sys.path.insert(0, '../../')
19
20 from Gnumed.pycommon import gmTools
21 from Gnumed.pycommon import gmPG2
22 from Gnumed.pycommon import gmI18N
23 from Gnumed.pycommon import gmDispatcher
24
25
26 from Gnumed.wxpython import gmListWidgets
27 from Gnumed.wxpython import gmEditArea
28 from Gnumed.wxpython import gmPhraseWheel
29 from Gnumed.wxpython import gmGuiHelpers
30 from Gnumed.wxpython import gmAuthWidgets
31
32
33 _log = logging.getLogger('gm.ui')
34 _log.info(__version__)
35
36
37 from Gnumed.wxGladeWidgets import wxgDatabaseTranslationEAPnl
38
40
58
59
60
61
62
63
64
65
67
68 fields = [self._TCTRL_original, self._TCTRL_translation, self._TCTRL_language]
69
70 has_errors = False
71 for field in fields:
72 if field.GetValue().strip() == u'':
73 has_errors = True
74 field.SetBackgroundColour(gmPhraseWheel.color_prw_invalid)
75 field.SetFocus()
76 else:
77 field.SetBackgroundColour(gmPhraseWheel.color_prw_valid)
78
79 return (has_errors is False)
80
88
90 return self._save_as_new()
91
93 self._TCTRL_original.SetValue(u'')
94 self._TCTRL_original.SetEditable(True)
95 self._TCTRL_translation.SetValue(u'')
96 self._TCTRL_language.SetValue(u'')
97 self._TCTRL_original.SetFocus()
98
105
107 self._TCTRL_original.SetValue(self.data['orig'])
108 self._TCTRL_original.SetEditable(False)
109 self._TCTRL_translation.SetValue(u'')
110 self._TCTRL_language.SetValue(u'')
111 self._TCTRL_translation.SetFocus()
112
113
114
126
127
129
130 if parent is None:
131 parent = wx.GetApp().GetTopWindow()
132
133 if language is None:
134 langs = gmPG2.get_translation_languages()
135 for lang in [gmI18N.system_locale_level['language'], gmI18N.system_locale_level['country']]:
136 if lang not in langs:
137 langs.append(lang)
138
139 curr_lang = gmPG2.get_current_user_language()
140 try:
141 selections = [langs.index(curr_lang)]
142 except ValueError:
143 selections = None
144
145 language = gmListWidgets.get_choices_from_list (
146 parent = parent,
147 caption = _('Selecting language for translation'),
148 msg = _('Please select the language the translations for which you want to work on.'),
149 single_selection = True,
150 can_return_empty = False,
151 columns = [_('Language')],
152 choices = langs,
153 selections = selections
154 )
155
156 def refresh(lctrl):
157 txs = gmPG2.get_database_translations(language = language, order_by = u'orig, lang')
158 items = [ [
159 tx['orig'],
160 gmTools.coalesce(tx['lang'], u''),
161 gmTools.coalesce(tx['trans'], u'')
162 ] for tx in txs ]
163 lctrl.set_string_items(items)
164 lctrl.set_data(txs)
165
166 def edit(translation=None):
167 return edit_translation(parent = parent, translation = translation, single_entry = True)
168
169 def delete(translation=None):
170 msg = _(
171 'Are you sure you want to delete the translation of:\n'
172 '\n'
173 '%s\n'
174 '\n'
175 'into [%s] as:\n'
176 '\n'
177 '%s\n'
178 '\n'
179 '? (Note that you must know the database administrator password !)\n'
180 ) % (
181 gmTools.wrap (
182 text = translation['orig'],
183 width = 60,
184 initial_indent = u' ',
185 subsequent_indent = u' '
186 ),
187 translation['lang'],
188 gmTools.wrap (
189 text = translation['trans'],
190 width = 60,
191 initial_indent = u' ',
192 subsequent_indent = u' '
193 )
194 )
195 delete_it = gmGuiHelpers.gm_show_question (
196 aTitle = _('Deleting translation from database'),
197 aMessage = msg
198 )
199 if not delete_it:
200 return False
201
202 conn = gmAuthWidgets.get_dbowner_connection(procedure = _('deleting a translation'))
203 if conn is None:
204 return False
205
206 return gmPG2.delete_translation_from_database(link_obj = conn, language = translation['lang'], original = translation['orig'])
207
208 def contribute_translations(item=None):
209
210 do_it = gmGuiHelpers.gm_show_question (
211 aTitle = _('Contributing translations'),
212 aMessage = _('Do you want to contribute your translations to the GNUmed project ?')
213 )
214 if not do_it:
215 return False
216
217 fname = gmTools.get_unique_filename(prefix = 'gm-db-translations-', suffix = '.sql')
218 gmPG2.export_translations_from_database(filename = fname)
219
220 if not gmTools.send_mail (
221 auth = {'user': gmTools.default_mail_sender, 'password': u'gnumed-at-gmx-net'},
222 sender = u'GNUmed Client <gnumed@gmx.net>',
223 receiver = [u'gnumed-bugs@gnu.org'],
224 subject = u'<contribution>: database translation',
225 message = u'These are database string translations contributed by a GNUmed user.\n\n\tThe GNUmed Client',
226 encoding = gmI18N.get_encoding(),
227 attachments = [[fname, u'text/plain', u'quoted-printable']]
228 ):
229 gmDispatcher.send(signal = 'statustext', msg = _('Unable to send mail. Cannot contribute translations to GNUmed community.') % report, beep = True)
230 return False
231
232 gmDispatcher.send(signal = 'statustext', msg = _('Thank you for your contribution to the GNUmed community!'), beep = True)
233 return True
234
235 if language is None:
236 caption = _('Showing translatable database strings for all languages.')
237 else:
238 caption = _('Showing translatable database strings for target language [%s].') % language
239 gmListWidgets.get_choices_from_list (
240 parent = parent,
241 caption = caption,
242 columns = [ _('String'), _('Language'), _('Translation') ],
243 single_selection = True,
244 can_return_empty = False,
245 refresh_callback = refresh,
246 edit_callback = edit,
247 new_callback = edit,
248 delete_callback = delete,
249 right_extra_button = (_('Contribute'), _('Contribute translations to GNUmed community by email.'), contribute_translations),
250 ignore_OK_button = True
251 )
252
253
254 if __name__ == '__main__':
255
256 from Gnumed.pycommon import gmI18N
257 gmI18N.activate_locale()
258 gmI18N.install_domain()
259
260 if (len(sys.argv) > 1):
261 if sys.argv[1] == 'test':
262 pass
263
264
265