| Home | Trees | Indices | Help |
|
|---|
|
|
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 # stdlib
8 import logging
9 import sys
10
11
12 # 3rd party
13 import wx
14
15
16 # GNUmed
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
39 -class cDatabaseTranslationEAPnl(wxgDatabaseTranslationEAPnl.wxgDatabaseTranslationEAPnl, gmEditArea.cGenericEditAreaMixin):
40
42
43 try:
44 data = kwargs['translation']
45 del kwargs['translation']
46 except KeyError:
47 data = None
48
49 wxgDatabaseTranslationEAPnl.wxgDatabaseTranslationEAPnl.__init__(self, *args, **kwargs)
50 gmEditArea.cGenericEditAreaMixin.__init__(self)
51
52 # Code using this mixin should set mode and data
53 # after instantiating the class:
54 self.mode = 'new'
55 self.data = data
56 if data is not None:
57 self.mode = 'edit'
58
59 #self.__init_ui()
60 #----------------------------------------------------------------
61 # def __init_ui(self):
62 # # adjust phrasewheels etc
63 #----------------------------------------------------------------
64 # generic Edit Area mixin API
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 #----------------------------------------------------------------
82 self.data = gmPG2.update_translation_in_database (
83 language = self._TCTRL_language.GetValue().strip(),
84 original = self._TCTRL_original.GetValue().strip(),
85 translation = self._TCTRL_translation.GetValue().strip()
86 )
87 return True
88 #----------------------------------------------------------------
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 #----------------------------------------------------------------
100 self._TCTRL_original.SetValue(self.data['orig'])
101 self._TCTRL_original.SetEditable(False)
102 self._TCTRL_translation.SetValue(gmTools.coalesce(self.data['trans']))
103 self._TCTRL_language.SetValue(gmTools.coalesce(self.data['lang']))
104 self._TCTRL_translation.SetFocus()
105 #----------------------------------------------------------------
112 #----------------------------------------------------------------
113
114 #------------------------------------------------------------------------------
116 ea = cDatabaseTranslationEAPnl(parent = parent, id = -1)
117 ea.data = translation
118 ea.mode = gmTools.coalesce(translation, 'new', 'edit')
119 dlg = gmEditArea.cGenericEditAreaDlg2(parent = parent, id = -1, edit_area = ea, single_entry = single_entry)
120 dlg.SetTitle(gmTools.coalesce(translation, _('Adding new translation'), _('Editing translation')))
121 if dlg.ShowModal() == wx.ID_OK:
122 dlg.Destroy()
123 return True
124 dlg.Destroy()
125 return False
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 msg = (
221 u'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.send_mail (
227 auth = {'user': gmNetworkTools.default_mail_sender, 'password': u'gnumed-at-gmx-net'},
228 sender = u'GNUmed Client <gnumed@gmx.net>',
229 receiver = [u'gnumed-bugs@gnu.org'],
230 subject = u'<contribution>: database translation',
231 message = msg,
232 encoding = gmI18N.get_encoding(),
233 attachments = [[fname, u'text/plain', u'quoted-printable']]
234 ):
235 gmDispatcher.send(signal = 'statustext', msg = _('Unable to send mail. Cannot contribute translations to GNUmed community.') % report, beep = True)
236 return False
237
238 gmDispatcher.send(signal = 'statustext', msg = _('Thank you for your contribution to the GNUmed community!'), beep = True)
239 return True
240 #---------------------------------------------------------------------
241 if language is None:
242 caption = _('Showing translatable database strings for all languages.')
243 else:
244 caption = _('Showing translatable database strings for target language [%s].') % language
245 gmListWidgets.get_choices_from_list (
246 parent = parent,
247 caption = caption,
248 columns = [ _('String'), _('Language'), _('Translation') ],
249 single_selection = True,
250 can_return_empty = False,
251 refresh_callback = refresh,
252 edit_callback = edit,
253 new_callback = edit,
254 delete_callback = delete,
255 right_extra_button = (_('Contribute'), _('Contribute translations to GNUmed community by email.'), contribute_translations),
256 ignore_OK_button = True
257 )
258
259 #================================================================
260 if __name__ == '__main__':
261
262 gmI18N.activate_locale()
263 gmI18N.install_domain()
264
265 if (len(sys.argv) > 1):
266 if sys.argv[1] == 'test':
267 pass
268
269 #================================================================
270
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Sat Oct 5 03:57:20 2013 | http://epydoc.sourceforge.net |