Re: [Zope3-Users] z3c.form, german umlauts on buttons - small patch, please review

2007-11-11 Thread Stephan Richter
On Tuesday 11 September 2007, Andreas Reuleaux wrote:
> This small patch fixes the problem for me, please review:

Thanks. I applied the patch in trunk.

Regards,
Stephan
-- 
Stephan Richter
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] z3c.form, german umlauts on buttons - small patch, please review

2007-09-11 Thread Andreas Reuleaux
This small patch fixes the problem for me, please review:



[EMAIL PROTECTED](~/tmp/z3c.form/src/z3c/form)$ svn diff
Index: util.py
===
--- util.py (Revision 79574)
+++ util.py (Arbeitskopie)
@@ -30,7 +30,7 @@
 def createId(name):
 if _identifier.match(name):
 return str(name).lower()
-return name.encode('hex')
+return name.encode('utf8').encode('hex')
 
 
 classTypes = type, types.ClassType
[EMAIL PROTECTED](~/tmp/z3c.form/src/z3c/form)$



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


Re: [Zope3-Users] z3c.form, german umlauts on buttons

2007-09-09 Thread Andreas Reuleaux
On Sun, Sep 09, 2007 at 11:20:34PM +0200, Roger Ineichen wrote:
> Hi Andreas
> 
> > Betreff: [Zope3-Users] z3c.form, german umlauts on buttons
> > 
> 
> [...]
> 
> >   My app is german only and if I was to introduce i18n I would still
> >   make german the primary language and English the second,
> >   i. e. I would still want
> > 
> >   @button.buttonAndHandler(_(u'Ändern'))
> 
> I never did use German in the code and can't say that this
> should work. But why do you use german as the default language?
> 
> I recommend to use english in the code and use german as a
> translated language.
> 
> I'm not really sure if we should support german Umlauts
> at the python leven and take care for encoding. I guess
> this is what translation should be used for. Or not?

Hi Roger,

OK, let me put it this way:

If I really have to use i18n for those umlauts on buttons (and that's
what I might have to do if nothing changes) then you might be right in
that it may be better to use English as the default language and
German as one of the languages looked up by i18n, i. e. to use:

   @button.buttonAndHandler(_(u'Change'))

and have i18n find "Ändern" as the German translation for "Change". At
least I guess this is what gettext docs would suggest. The other way
around might not even be possible due to some gettext restriction -
not sure about that.

However, this particular app of mine will never be an international
app, it will always be German only. It is just a simple app for a
customer of mine here in Berlin, that's it, I just don't plan to make
it a sophisticated multilanguage app. No need to negoatiate the
languages accepted by the browser etc. - And till now, as long as I was
using formlib, it was a simple app: as I pointed out, I could use
something like this in formlib:

  actions[u'actions.aendern'].label=u'Ändern'

It just feels awkward to make it more complex then was neccessary in
the past.

Besides, I can use umlauts in page templates without i18n - as utf-8
is the default there, just not on the buttons, this seems an assymetry
to me.

Also I specified the coding of my python file

  # -*- coding: utf-8 -*-

which in py3k will be the default anyway, and 

  buttonAndHandler()

in z3c.form expects an unicode param, i. e. u'...', not just a plain
string '...', doesn't it make sense to allow umlauts here - if ascii only
is accepted then a plain string would have done it just as well.

-Andreas


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


AW: [Zope3-Users] z3c.form, german umlauts on buttons

2007-09-09 Thread Roger Ineichen
Hi Andreas

> Betreff: [Zope3-Users] z3c.form, german umlauts on buttons
> 

[...]

>   My app is german only and if I was to introduce i18n I would still
>   make german the primary language and English the second,
>   i. e. I would still want
> 
>   @button.buttonAndHandler(_(u'Ändern'))

I never did use German in the code and can't say that this
should work. But why do you use german as the default language?

I recommend to use english in the code and use german as a
translated language.

I'm not really sure if we should support german Umlauts
at the python leven and take care for encoding. I guess
this is what translation should be used for. Or not?

Regards
Roger Ineichen
_
END OF MESSAGE
 

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


[Zope3-Users] z3c.form, german umlauts on buttons

2007-09-08 Thread Andreas Reuleaux


It appears to me that I can't have german umlauts (or any other
non-ascii chars for that matter) on buttons, for example ("Ändern"
 - with A umlaut - ist german for "Change"):

# -*- coding: utf-8 -*-

...

class MyDisplayForm(form.Form):

  ...

  @button.buttonAndHandler(u'Ändern')
  def change(self, action):
  self.request.response.redirect('edit')

tons of error msgs:

  ...
  File "/home/reuleaux/work/adrn/src/adrn/browser/views.py", line 489, in ?
class MyDisplayForm(form.Form):
  File "/home/reuleaux/work/adrn/src/adrn/browser/views.py", line 491, in 
MyDisplayForm
@button.buttonAndHandler(u'Ändern')
  File "/home/reuleaux/tmp/z3c.form/src/z3c/form/button.py", line 181, in 
buttonAndHandler
f_locals['buttons'] += Buttons(button)
  File "/home/reuleaux/tmp/z3c.form/src/z3c/form/button.py", line 83, in 
__init__
arg.__name__ = util.createId(arg.title)
  File "/home/reuleaux/tmp/z3c.form/src/z3c/form/util.py", line 33, in 
createId
return name.encode('hex')
  File "encodings/hex_codec.py", line 24, in hex_encode
zope.configuration.xmlconfig.ZopeXMLConfigurationError: File 
"/home/reuleaux/work/adrn/parts/adrbuch/site.zcml", line 4.0-4.42
ZopeXMLConfigurationError: File 
"/home/reuleaux/work/adrn/src/adrn/app.zcml", line 86.2-86.28
ZopeXMLConfigurationError: File 
"/home/reuleaux/work/adrn/src/adrn/configure.zcml", line 27.2-27.32
ZopeXMLConfigurationError: File 
"/home/reuleaux/work/adrn/src/adrn/browser/configure.zcml", line 40.2-40.27
ZopeXMLConfigurationError: File 
"/home/reuleaux/work/adrn/src/adrn/browser/av/configure.zcml", line 14.2
UnicodeEncodeError: 'ascii' codec can't encode character u'\xc4' in 
position 0: ordinal not in range(128)

I get similar errors at runtime (when rendering the form) if I try to
change the title of an existing button:

class AdrEditForm(form.EditForm):

...

buttons=form.EditForm.buttons
# save changes
buttons['apply'].title=u'Änderungen speichern'

this gives me:

Traceback (most recent call last):
  File 
"/home/reuleaux/z3eggs/tmp-nK7Ng/zope.publisher-3.5.0a1.dev_r78838-py2.4.egg/zope/publisher/publish.py",
 line 133, in publish
  File 
"/home/reuleaux/z3eggs/tmp1LrliP/zope.app.publication-3.4.0a1_2-py2.4.egg/zope/app/publication/zopepublication.py",
 line 167, in callObject
  File 
"/home/reuleaux/z3eggs/tmp-nK7Ng/zope.publisher-3.5.0a1.dev_r78838-py2.4.egg/zope/publisher/publish.py",
 line 108, in mapply
   - __traceback_info__: 
  File 
"/home/reuleaux/z3eggs/tmp-nK7Ng/zope.publisher-3.5.0a1.dev_r78838-py2.4.egg/zope/publisher/publish.py",
 line 114, in debug_call
  File "/home/reuleaux/work/adrn/src/adrn/browser/views.py", line 636, in 
__call__
self.update(**kw)
  File "/home/reuleaux/work/adrn/src/adrn/browser/views.py", line 692, in 
update
self.form.update()
  File "/home/reuleaux/work/adrn/src/adrn/browser/views.py", line 334, in 
update
super(AdrEditForm, self).update()
  File "/home/reuleaux/tmp/z3c.form/src/z3c/form/form.py", line 183, in 
update
self.updateActions()
  File "/home/reuleaux/tmp/z3c.form/src/z3c/form/form.py", line 179, in 
updateActions
self.actions.update()
  File "/home/reuleaux/tmp/z3c.form/src/z3c/form/button.py", line 229, in 
update
buttonAction = zope.component.getMultiAdapter(
  File 
"/home/reuleaux/z3eggs/tmpxWsYeR/zope.component-3.4.0a1-py2.4.egg/zope/component/_api.py",
 line 101, in getMultiAdapter
  File 
"/home/reuleaux/z3eggs/tmpxWsYeR/zope.component-3.4.0a1-py2.4.egg/zope/component/_api.py",
 line 114, in queryMultiAdapter
  File 
"/home/reuleaux/z3eggs/tmpxWsYeR/zope.component-3.4.0a1-py2.4.egg/zope/component/registry.py",
 line 206, in queryMultiAdapter
  File 
"/home/reuleaux/z3eggs/tmpiBfeIG/zope.interface-3.4.0-py2.4-linux-i686.egg/zope/interface/adapter.py",
 line 482, in queryMultiAdapter
  File "/home/reuleaux/tmp/z3c.form/src/z3c/form/button.py", line 191, in 
__init__
action.Action.__init__(self, request, field.title)
  File "/home/reuleaux/tmp/z3c.form/src/z3c/form/action.py", line 60, in 
__init__
name = util.createId(title)
  File "/home/reuleaux/tmp/z3c.form/src/z3c/form/util.py", line 33, in 
createId
return name.encode('hex')
  File "encodings/hex_codec.py", line 24, in hex_encode
  UnicodeEncodeError: 'ascii' codec can't encode character u'\xc4' in 
position 0: ordinal not in range(128)

Two points to note:

* I don't want to introduce i18n just for the buttons

  @button.buttonAndHandler(_(u'Change'))

  My app is german only and if I was to introduce i18n I would still
  make german the primary language and English the second,
  i. e. I would still want

  @button.buttonAndHandler(_(u'Ändern'))

* This caused me no problems in formlib, there I could do e. g.