1 """GNUmed I18n/L10n related widgets.
2 """
3
4 __author__ = 'karsten.hilbert@gmx.net'
5 __license__ = 'GPL v2 or later (details at http://www.gnu.org)'
6
7
8 import logging
9 import 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 gmNetworkTools
22 from Gnumed.pycommon import gmPG2
23 from Gnumed.pycommon import gmI18N
24 from Gnumed.pycommon import gmDispatcher
25
26
27 from Gnumed.wxpython import gmListWidgets
28 from Gnumed.wxpython import gmEditArea
29 from Gnumed.wxpython import gmPhraseWheel
30 from Gnumed.wxpython import gmGuiHelpers
31 from Gnumed.wxpython import gmAuthWidgets
32
33
34 _log = logging.getLogger('gm.ui')
35
36
37 from Gnumed.wxGladeWidgets import wxgDatabaseTranslationEAPnl
38
40
58
59
60
61
62
63
64
65
80
88
90 return self._save_as_new()
91
93 self._TCTRL_original.SetValue('')
94 self._TCTRL_original.SetEditable(True)
95 self._TCTRL_translation.SetValue('')
96 self._TCTRL_language.SetValue('')
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('')
110 self._TCTRL_language.SetValue('')
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 = 'orig, lang')
158 items = [ [
159 tx['orig'],
160 gmTools.coalesce(tx['lang'], ''),
161 gmTools.coalesce(tx['trans'], '')
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 = ' ',
185 subsequent_indent = ' '
186 ),
187 translation['lang'],
188 gmTools.wrap (
189 text = translation['trans'],
190 width = 60,
191 initial_indent = ' ',
192 subsequent_indent = ' '
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 msg = (
221 'These are database string translations contributed by a GNUmed user.\n'
222 '\n'
223 '\tThe GNUmed "%s" Client'
224 ) % gmI18N.system_locale
225
226 if not gmNetworkTools.compose_and_send_email (
227 auth = {'user': gmNetworkTools.default_mail_sender, 'password': 'gnumed-at-gmx-net'},
228 sender = 'GNUmed Client <gnumed@gmx.net>',
229 receiver = ['gnumed-bugs@gnu.org'],
230 subject = '<contribution>: database translation',
231 message = msg,
232 attachments = [[fname, 'text/plain', 'quoted-printable']]
233 ):
234 gmDispatcher.send(signal = 'statustext', msg = _('Unable to send mail. Cannot contribute translations to GNUmed community.') % report, beep = True)
235 return False
236
237 gmDispatcher.send(signal = 'statustext', msg = _('Thank you for your contribution to the GNUmed community!'), beep = True)
238 return True
239
240 if language is None:
241 caption = _('Showing translatable database strings for all languages.')
242 else:
243 caption = _('Showing translatable database strings for target language [%s].') % language
244 gmListWidgets.get_choices_from_list (
245 parent = parent,
246 caption = caption,
247 columns = [ _('String'), _('Language'), _('Translation') ],
248 single_selection = True,
249 can_return_empty = False,
250 refresh_callback = refresh,
251 edit_callback = edit,
252 new_callback = edit,
253 delete_callback = delete,
254 right_extra_button = (_('Contribute'), _('Contribute translations to GNUmed community by email.'), contribute_translations),
255 ignore_OK_button = True
256 )
257
258
259 if __name__ == '__main__':
260
261 gmI18N.activate_locale()
262 gmI18N.install_domain()
263
264 if (len(sys.argv) > 1):
265 if sys.argv[1] == 'test':
266 pass
267
268
269