Permalink
Browse files

babel view, google translation service, initial site setup and 1.0b1 …

…tagging
  • Loading branch information...
1 parent 2df017a commit 363d5afe2309fc3a5c61f1d81ad3d5d1a8f8ce9e @bloodbare bloodbare committed Apr 3, 2012
View
@@ -49,6 +49,15 @@ See plone.multilingual README:
http://github.com/plone/plone.multilingual
+License
+=======
+
+GNU General Public License, version 2
+
+
+Sponsoring
+==========
+
Roadmap
=======
View
@@ -0,0 +1,23 @@
+Credits
+=======
+
+Plone.app.multilingual has been developed based on LinguaPlone by:
+
+Design and development --
+ Iskra_ (Ramon Navarro Bosch, Victor Fernandez de Alba)
+
+.. _Iskra: http://www.iskra.cat
+
+Additional funding/sponsorship:
+ Hitotsubashi University in Tokyo, Centre for New European studies
+ (Jonathan Lewis)
+
+Also many thanks to
+
+Jan-Carel Brand:
+ For language independent field implementation on AT
+
+Anne Walter:
+ For pushing for a initial working version
+
+Thomas Massmann, Martijn Pieters, Martin Aspelli, David Glick
View
@@ -1,6 +1,16 @@
Changelog
=========
+1.0b1 - 2012-4-3
+----------------
+
+- Added Google Translation Service ajax service [ramon]
+- Added babel view on AT [sneridagh]
+- Added babel view on dexterity [ramon]
+- Added the option to not filter language on folder_contents view [ramon]
+- Added to translation menu to edit a translated language [ramon]
+- Initial setup of a site moving content to language folders [ramon]
+
0.1a2 - 2011-12-4
-----------------
View
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
import os
-version = '0.2b4-dev'
+version = '1.0b1'
setup(name='plone.app.multilingual',
version=version,
@@ -19,14 +19,17 @@
folderlisting_macro view_macros/folderlisting | folderlisting | base_macros/folderlisting;
errors python:request.get('errors', {})">
- <div class="field">
- <label>Title</label>
- <h2 tal:content="context/Title" />
+ <div id="view_language" tal:content="context/language">
</div>
- <div class="field">
- <label>Description</label>
- <h2 tal:content="context/Description" />
+ <div class="field" id="title">
+ <label i18n:translate="Title">Title</label>
+ <h2 class="value localstatic-field" tal:content="context/Title" />
+ </div>
+
+ <div class="field" id="description">
+ <label i18n:translate="Description">Description</label>
+ <h2 class="value localstatic-field" tal:content="context/Description" />
</div>
<tal:fields tal:define="field_macro field_macro | context/widgets/field/macros/view"
@@ -38,7 +41,9 @@
visState python:field.widget.isVisible(here, mode);
visCondition python:field.widget.testCondition(None, portal, context);"
condition="python:visState == 'visible' and visCondition">
+ <div class="value">
<metal:use_field use-macro="field_macro" />
+ </div>
</tal:if_visible>
</div>
</tal:fields>
@@ -10,6 +10,10 @@
from plone.app.i18n.locales.browser.selector import LanguageSelector
from AccessControl.SecurityManagement import getSecurityManager
+from zope.component import getUtility
+from plone.registry.interfaces import IRegistry
+from plone.app.multilingual.interfaces import IMultiLanguageExtraOptionsSchema
+
class BabelView(BrowserView):
__call__ = ViewPageTemplateFile('babel_view.pt')
@@ -47,6 +51,11 @@ def getPortal(self):
def objToTranslate(self):
return self.context
+ def gtenabled(self):
+ registry = getUtility(IRegistry)
+ settings = registry.forInterface(IMultiLanguageExtraOptionsSchema)
+ return settings.google_translation_key != ''
+
def languages(self):
context = aq_inner(self.context)
@@ -63,7 +72,6 @@ def languages(self):
# We want to see the babel_view
append_path = ('', 'babel_view',)
_checkPermission = getSecurityManager().checkPermission
-
non_viewable = set()
for data in results:
code = str(data['code'])
@@ -77,33 +85,9 @@ def languages(self):
# shortcut if the user cannot see the item
non_viewable.add((data['code']))
continue
-
- state = getMultiAdapter((trans, self.request),
- name='plone_context_state')
- try:
- data['url'] = state.canonical_object_url() + appendtourl
- except AttributeError:
- data['url'] = context.absolute_url() + appendtourl
+ data['url'] = trans.absolute_url() + appendtourl
else:
- has_view_permission = bool(_checkPermission('View', context))
- # Ideally, we should also check the View permission of default
- # items of folderish objects.
- # However, this would be expensive at it would mean that the
- # default item should be loaded as well.
- #
- # IOW, it is a conscious decision to not take in account the
- # use case where a user has View permission a folder but not on
- # its default item.
- if not has_view_permission:
- non_viewable.add((data['code']))
- continue
-
- state = getMultiAdapter((context, self.request),
- name='plone_context_state')
- try:
- data['url'] = state.canonical_object_url() + appendtourl
- except AttributeError:
- data['url'] = context.absolute_url() + appendtourl
+ non_viewable.add((data['code']))
# filter out non-viewable items
results = [r for r in results if r['code'] not in non_viewable]
@@ -89,12 +89,20 @@
<!-- GTranslate Service -->
<browser:page
- for="*"
+ for="plone.dexterity.interfaces.IDexterityContent"
+ name="gtranslation_service"
+ class=".translate.gtranslation_service_dexterity"
+ permission="cmf.ModifyPortalContent"
+ />
+
+ <browser:page
+ for="Products.Archetypes.atapi.BaseObject"
name="gtranslation_service"
- class=".translate.gtranslation_service"
+ class=".translate.gtranslation_service_at"
permission="cmf.ModifyPortalContent"
/>
+
<!-- Edit form -->
<browser:page
@@ -10,6 +10,7 @@
<script src="++resource++plone.app.multilingual.javascript/loadContentToTranslateFrom.js">
</script>
<input type="hidden" id="url_translate" value="" tal:attributes="value context/absolute_url"/>
+ <input type="hidden" id="gtanslate_service" value="" tal:attributes="value pamview/gtenabled"/>
<div class='cell width-8 position-0'>
<div id="trans-selector"
tal:define="languages view/languages;">
@@ -30,7 +31,9 @@
<div id="header-translation">
<h1 i18n:translate="translation_to">TRANSLATION TO <span tal:replace="context/language"></span></h1>
</div>
- <tal:block content="structure view/babel_content">Contingut</tal:block>
+ <div id="form-target">
+ <tal:block content="structure view/babel_content">Contingut</tal:block>
+ </div>
</div>
</div>
@@ -3,7 +3,6 @@
from Products.CMFCore.utils import getToolByName
from Acquisition import aq_inner
from AccessControl.SecurityManagement import getSecurityManager
-from zope.component import getMultiAdapter
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
@@ -12,11 +11,20 @@
from plone.multilingualbehavior.interfaces import ILanguageIndependentField
+from zope.component import getUtility
+from plone.registry.interfaces import IRegistry
+from plone.app.multilingual.interfaces import IMultiLanguageExtraOptionsSchema
+
class MultilingualEditForm(DefaultEditForm):
babel = ViewPageTemplateFile("dexterity_edit.pt")
+ def gtenabled(self):
+ registry = getUtility(IRegistry)
+ settings = registry.forInterface(IMultiLanguageExtraOptionsSchema)
+ return settings.google_translation_key != ''
+
def languages(self):
context = aq_inner(self.context)
@@ -47,33 +55,9 @@ def languages(self):
# shortcut if the user cannot see the item
non_viewable.add((data['code']))
continue
-
- state = getMultiAdapter((trans, self.request),
- name='plone_context_state')
- try:
- data['url'] = state.canonical_object_url() + appendtourl
- except AttributeError:
- data['url'] = context.absolute_url() + appendtourl
+ data['url'] = trans.absolute_url() + appendtourl
else:
- has_view_permission = bool(_checkPermission('View', context))
- # Ideally, we should also check the View permission of default
- # items of folderish objects.
- # However, this would be expensive at it would mean that the
- # default item should be loaded as well.
- #
- # IOW, it is a conscious decision to not take in account the
- # use case where a user has View permission a folder but not on
- # its default item.
- if not has_view_permission:
- non_viewable.add((data['code']))
- continue
-
- state = getMultiAdapter((context, self.request),
- name='plone_context_state')
- try:
- data['url'] = state.canonical_object_url() + appendtourl
- except AttributeError:
- data['url'] = context.absolute_url() + appendtourl
+ non_viewable.add((data['code']))
# filter out non-viewable items
results = [r for r in results if r['code'] not in non_viewable]
@@ -2,11 +2,15 @@
function reload_height() {
orig = $('#frame-content .field');
- desti = $('#form .field');
+ desti = $('#form-target .field');
order = 1;
$.each(orig, function(index, value) {
- $(value).height($(desti[index]).height());
- if (($(value).find('.richtext-field').length>0) || ($(value).find('.textline-field').length>0) || ($(value).find('.localstatic-field').length>0)) {
+ if ($(value).height()>$(desti[index]).height()) {
+ $(desti[index]).height($(value).height());
+ } else {
+ $(value).height($(desti[index]).height());
+ }
+ if (($(value).find('.richtext-field').length>0) || ($(value).find('.textline-field').length>0) || ($(value).find('.localstatic-field').length>0) || ($(value).find('.ArchetypesField-TextField').length>0)) {
$(value).prepend("<div class='translator-widget' id='item_translation_"+order+"'></div>");
$(value).children('.translator-widget').click(function() {
var langSource = $('#frame-content #view_language')[0].innerHTML;
@@ -80,7 +84,7 @@ jq(document).ready(function() {
}
babel_selectec = this;
$(this).toggleClass("selected");
- index = $('#form .field').index($(this));
+ index = $('#form-target .field').index($(this));
orig_babel_select = $('#frame-content .field')[index];
$(orig_babel_select).toggleClass("selected");
$(orig_babel_select).children('.translator-widget').show()
@@ -60,4 +60,8 @@
background: url('++resource++plone.app.multilingual.images/gtranslate.png');
min-height: 50px;
min-width: 50px;
+}
+
+.currentLanguage {
+ font-weight: bold;
}
@@ -16,12 +16,11 @@
from plone.multilingual.interfaces import LANGUAGE_INDEPENDENT
from plone.app.multilingual import _
from Products.Five import BrowserView
-from plone.multilingual.interfaces import ITranslationManager
-
+from plone.multilingual.interfaces import ITranslationManager, ILanguage
import urllib
-class gtranslation_service(BrowserView):
+class gtranslation_service_dexterity(BrowserView):
def __call__(self):
if (self.request.method != 'POST' and
@@ -32,7 +31,7 @@ def __call__(self):
manager = ITranslationManager(self.context)
registry = getUtility(IRegistry)
settings = registry.forInterface(IMultiLanguageExtraOptionsSchema)
- lang_target = self.context.language
+ lang_target = ILanguage(self.context).get_language()
lang_source = self.request.form['lang_source']
orig_object = manager.get_translation(lang_source)
if hasattr(orig_object, self.request.form['field']):
@@ -41,6 +40,8 @@ def __call__(self):
question = question.raw
else:
return _("Invalid field")
+ if len(question)>1600:
+ return _("Too long field")
data = {'key': settings.google_translation_key,
'target': lang_target,
'source': lang_source,
@@ -52,6 +53,36 @@ def __call__(self):
return retorn.read()
+class gtranslation_service_at(BrowserView):
+
+ def __call__(self):
+ if (self.request.method != 'POST' and
+ not ('field' in self.request.form.keys() and
+ 'lang_source' in self.request.form.keys())):
+ return _("Need a field")
+ else:
+ manager = ITranslationManager(self.context)
+ registry = getUtility(IRegistry)
+ settings = registry.forInterface(IMultiLanguageExtraOptionsSchema)
+ lang_target = ILanguage(self.context).get_language()
+ lang_source = self.request.form['lang_source']
+ orig_object = manager.get_translation(lang_source)
+ try:
+ question = orig_object.getField(self.request.form['field']).get(orig_object)
+ except AttributeError:
+ return _("Invalid field")
+ if len(question)>1600:
+ return _("Too long field")
+ data = {'key': settings.google_translation_key,
+ 'target': lang_target,
+ 'source': lang_source,
+ 'q': question}
+ params = urllib.urlencode(data)
+
+ url = 'https://www.googleapis.com/language/translate/v2'
+ retorn = urllib.urlopen(url + '?' + params)
+ return retorn.read()
+
class TranslationForm(form.SchemaForm):
""" Translation Form """
@@ -48,4 +48,13 @@
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
/>
+ <genericsetup:importStep
+ name="pam_reindex"
+ title="Multilingual Reindex catalog"
+ description=""
+ handler=".setuphandlers.importReindexLanguageIndex">
+ <depends name="content"/>
+ <depends name="toolset"/>
+ </genericsetup:importStep>
+
</configure>
Oops, something went wrong.

0 comments on commit 363d5af

Please sign in to comment.