Changeset 2552
- Timestamp:
- 03/01/10 15:18:01 (5 months ago)
- Location:
- branches/0.9/pylucid_project
- Files:
-
- 1 added
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
branches/0.9/pylucid_project/pylucid_plugins/admin_menu/templates/admin_menu/includes/pylucid_admin_menu.html
r2496 r2552 153 153 {% trans "translate content" %} 154 154 </a> 155 <ul> 156 <li> 157 <a href="{% url PageAdmin-translate PYLUCID.pagemeta.id %}?prefill=1" 158 title="{% trans "auto translate page into a other language and prefill fields with google translation service" %}"> 159 {% trans "prefill with google" %} 160 </a> 161 </li> 162 </ul> 155 163 </li> 156 164 {% endif %} -
branches/0.9/pylucid_project/pylucid_plugins/page_admin/admin_views/translate_page.py
r2494 r2552 10 10 from django.utils.translation import ugettext_lazy as _ 11 11 12 from pylucid_project.utils.translate import translate 12 13 from pylucid_project.apps.pylucid.models import PageTree, PageMeta, PageContent, Language 13 14 from pylucid_project.apps.pylucid.decorators import check_permissions, render_to 14 15 from pylucid_project.apps.pylucid.markup.converter import apply_markup 15 16 16 17 17 from pylucid_project.pylucid_plugins.page_admin.forms import PageMetaForm, PageContentForm, \ … … 206 206 ) 207 207 208 209 if "prefill" in request.GET: 210 filled_fields = [] 211 if "content" not in dest_pagecontent_form.initial: 212 source_content = source_pagecontent_form.initial["content"] 213 try: 214 translated_content = translate( 215 source_content, src=source_language.code, to=dest_language.code 216 ) 217 except ValueError, err: 218 request.page_msg("Can't translate content with google: %s" % err) 219 else: 220 dest_pagecontent_form.initial["content"] = translated_content 221 filled_fields.append("content") 222 dest_pagecontent_form.fields['content'].widget.attrs['class'] = 'auto_translated' 223 224 for key, source_value in source_pagemeta_form.initial.iteritems(): 225 if not source_value \ 226 or not isinstance(source_value, basestring)\ 227 or key == "robots" \ 228 or dest_pagemeta_form.initial.get(key, None): 229 # Skip empty, non string, robots field and if dest. value exist 230 continue 231 232 try: 233 dest_value = translate( 234 source_value, src=source_language.code, to=dest_language.code 235 ) 236 except ValueError, err: 237 request.page_msg( 238 "Can't translate %(key)s with google: %(err)s" % {"key":key, "err":err} 239 ) 240 else: 241 dest_pagemeta_form.initial[key] = dest_value 242 filled_fields.append(key) 243 dest_pagemeta_form.fields[key].widget.attrs['class'] = 'auto_translated' 244 245 if filled_fields: 246 request.page_msg("These fields are translated via google: %s" % ", ".join(filled_fields)) 247 else: 248 request.page_msg("No fields translated via google.") 249 250 251 208 252 source_pagecontent_form.language = source_language 209 253 dest_pagecontent_form.language = dest_language -
branches/0.9/pylucid_project/pylucid_plugins/page_admin/templates/page_admin/translate_page.html
r2332 r2552 40 40 border: 1px solid #ddd; 41 41 } 42 .auto_translated { 43 /* mark fields witch are automatic translated */ 44 background-color: #efefef; 45 font-style: italic; 46 } 47 .auto_translated:focus { 48 background-color: #fff; 49 font-style: normal; 50 } 42 51 </style> 43 52 <script type="text/javascript"> … … 47 56 var rows = $("#id_source-content").attr("rows"); 48 57 $("#id_dest-content").attr("rows", rows); 58 59 $(".auto_translated").change(function() { 60 // 'reset' a changed 'automatic translate' field back to the normal style 61 $(this).css("background-color", "#ffffff"); 62 $(this).css("font-style", "normal"); 63 }); 49 64 }); 50 65 //-->