Internationalization and Unicode

66 views
Skip to first unread message

Pierre

unread,
Nov 27, 2015, 9:48:02 AM11/27/15
to web2py-users
Hi all,

I am writing an app supposed to handle different languages/alphabets
Do I have to pay special attention to unicode issues (the subject is quite confusing)
or is this managed by the web2py api and the build-in translation tool ?



Richard Vézina

unread,
Nov 27, 2015, 10:15:38 AM11/27/15
to web2py-users

Depending if you hardcode or not your special language character or not. If you only input unicode into field by the mean of your app you should not have to pay attention, web2py will handle the differents languages. But if you defined you alphabets in differents languages as constant type variable in your code base you may need decode/encode from unicode.

I am not an expert in encoding and how works web2py at this level, but by default web2py use python 2.7 byte or str type... If it get a none ASCII character it get store in str in utf-8 hexadecimal representation for characters that can't be support by ASCII...

So the best way to avoid any issue with encoding in web2py is to always use plain ascii in your code base... 

If you can't, you have different option, for alphabet you can generate them with chr and ord
or you can use unicode:
var = u'unicode string'.decode(yourencoding).encode('utf-8')

Hope it helps and I didn't make error in my explanation.

Cheer

Richard

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pierre

unread,
Nov 28, 2015, 9:15:56 AM11/28/15
to web2py-users

what for to hardcode ?
python / web2py does everything transparently
>>> a=['un','deux','été','maçon']
>>> a
['un', 'deux', '\xc3\xa9t\xc3\xa9', 'ma\xc3\xa7on']
>>> 'été' in a
True
>>> print a[3]
maçon

Isn't it that python does the encode / decode transparently : from 'été' to '\xc3\xa9t\xc3\xa9' and back to 'été' for screen output
I can also do a database lookup based on the term 'été' so I don't understand what else should be encoded or decoded ?
It's true though I have little knowledge of Unicode

anyway thanks for the clarifications

Richard Vézina

unread,
Nov 30, 2015, 9:44:26 AM11/30/15
to web2py-users
Français : http://sametmax.com/lencoding-en-python-une-bonne-fois-pour-toute/

:)

I am not sure that what you say is correct... Did you try to look at these hardcoded code into the browser? Also, if you need to use the magic T(), it makes no sens to have different language code into the application... But your needs may be different.

Richard

--
Reply all
Reply to author
Forward
0 new messages