Re: [Zope3-Users] newbie question on i18n

2006-04-26 Thread Frank Burkhardt
Hi,

On Wed, Apr 26, 2006 at 11:14:19AM +0200, Riccardo Tonon wrote:
> Hi everybody,
> 
> I'm developing a multilanguage site in Zope 3.
> 
> I've just prepared it to support the i18n based on the browser language.
> 
> I would like also to let the user decide which language to use. (e.g. using a 
> combo 
> box present on each page of the site)
> 
> Anybody has an example where I could learn from?

I'm developing a multilingual site, too. It works like this:
   * browser language preferences are usually used to determine favorite 
language
   * users can click on one of 3 small flags to override browser preferences
 with a different language
   * all data fields on content objects are stored as dictionaries like this:
 context.sampledata={'de':'Einige Daten','en':'Some Data'}
   * Data fields are inserted into pagetemplates using a special metal-namespace
 
http://namespaces.zope.org/browser";
xmlns:zope="http://namespaces.zope.org/zope";
xmlns:i18n="http://namespaces.zope.org/i18n";
i18n_domain="mpgsite"
>
























from zope.app.publisher.browser import BrowserView
from mpgsite.i18n.browser.tools import getPreferredLanguages
from zope.formlib import form
from zope.interface import Interface

class CookieLanguageSwitchView(BrowserView):
"""A view that sets a new preferred language by sending a cookie to the 
user.
Presence of this cookie overrides preferred-language settings 
in the browser.
This is useful for systems where the user is unable to control 
the browser
settings."""
def setlanguage(self, language, newurl):
response = self.request.response
response.setCookie('mpgsite.preferredlanguage', language, 
path='/')
response.redirect(newurl)

class GetLanguageView(BrowserView):
"""Returns the current language selection"""
def __call__(self):
languages=getPreferredLanguages(self.request)
return languages[0]

def getClass(self,language):
if language == self.__call__():
return 'MpgSelectedLanguage'
else:
return 'MpgUnSelectedLanguage'

class I18NEditView(form.EditForm):
schema=Interface
def __init__(self,context,request):
self.form_fields=form.Fields(self.schema)

@form.action("edit")
def handle_edit_action(self,action,data):
if form.applyChanges(self.context,self.form_fields,data):
self.status='Object updated'
else:
self.status='No changes'

def __call__(self):
self.update()
self.i18nwidgetcontroller=I18NWidgetController(self)
self._show_navmenu=False
for widget in self.widgets.__Widgets_widgets_list__:
widget.i18nwidgetcontroller=self.i18nwidgetcontroller
return self.index()
from zope.component import adapts
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.publisher.browser import BrowserLanguages
from zope.i18n.interfaces import IUserPreferredLanguages


class CookieBrowserLanguages(BrowserLanguages):
adapts(IBrowserRequest)

def getPreferredLanguages(self):
lang = self.request.cookies.get('mpgsite.preferredlanguage', 
None)
if lang is None:

languages=super(CookieBrowserLanguages,self).getPreferredLanguages()
return languages
return [lang]


___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] newbie question on i18n

2006-04-26 Thread Andreas Jung



--On 26. April 2006 11:14:19 +0200 Riccardo Tonon 
<[EMAIL PROTECTED]> wrote:



Hi everybody,

I'm developing a multilanguage site in Zope 3.

I've just prepared it to support the i18n based on the browser language.

I would like also to let the user decide which language to use. (e.g.
using a combo box present on each page of the site)




Look at PloneLanguageTool and/or LinguaPlone.

-aj

--
ZOPYX Ltd. & Co. KG - Charlottenstr. 37/1 - 72070 Tübingen - Germany
Web: www.zopyx.com - Email: [EMAIL PROTECTED] - Phone +49 - 7071 - 793376
E-Publishing, Python, Zope & Plone development, Consulting


pgpyImroX5xQy.pgp
Description: PGP signature
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] newbie question on i18n

2006-04-26 Thread Riccardo Tonon

Hi everybody,

I'm developing a multilanguage site in Zope 3.

I've just prepared it to support the i18n based on the browser language.

I would like also to let the user decide which language to use. (e.g. 
using a combo box present on each page of the site)


Anybody has an example where I could learn from?


Thank You,
Ricki

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users