473,606 Members | 2,200 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

i18n hell

I just spent hours trying to figure out why even after I set my SQL
table attributes to UTF-8 only garbage kept adding into the database.
Apparently you need to execute "SET NAMES 'utf8'" before inserting into
the tables.

Does anyone have experience working with other languages using Django
or Turbogears? I just need to be able to retrieve and enter text to
the database from my page without it being mangled. I know these
frameworks employ ORM so you don't need to write SQL and that worries
me because I tried this on Rails and it wouldn't work.

Thanks.

Apr 24 '06 #1
3 1618
fyleow wrote:
I just spent hours trying to figure out why even after I set my SQL
table attributes to UTF-8 only garbage kept adding into the database.
Apparently you need to execute "SET NAMES 'utf8'" before inserting into
the tables.

Does anyone have experience working with other languages using Django
or Turbogears? I just need to be able to retrieve and enter text to
the database from my page without it being mangled. I know these
frameworks employ ORM so you don't need to write SQL and that worries
me because I tried this on Rails and it wouldn't work.


Frequently asked question to people who are burning in i18n hell: are
you using unicode strings or byte strings? Unicode string means that
type(your_strin g) is unicode, it does not mean you keep utf-8 encoded
text in python byte strings.

AFAIK Ruby has only byte strings that have the same set of
issues/problems/traps as Python byte strings.

Apr 24 '06 #2
On 24 Apr 2006 00:38:42 -0700, Serge Orlov <Se*********@gm ail.com> wrote:
fyleow wrote:
I just spent hours trying to figure out why even after I set my SQL
table attributes to UTF-8 only garbage kept adding into the database.
Apparently you need to execute "SET NAMES 'utf8'" before inserting into
the tables.

Does anyone have experience working with other languages using Django
or Turbogears? I just need to be able to retrieve and enter text to
the database from my page without it being mangled. I know these
frameworks employ ORM so you don't need to write SQL and that worries
me because I tried this on Rails and it wouldn't work.


Frequently asked question to people who are burning in i18n hell: are
you using unicode strings or byte strings? Unicode string means that
type(your_strin g) is unicode, it does not mean you keep utf-8 encoded
text in python byte strings.


I used to live i18n hell, a while ago, until I understood this:
everytime you keep a reference to some kind of string object, ALWAYS
ALWAYS ALWAYS be AWARE of whether it is not encoded (a unicode object)
or an encoding string (a str object), and if so, which encoding it is
in. Then deal with the conversion between the two domains EXPLICITLY
(e.g. encode(), decode()). If you hold onto a str or unicode object
and you don't know which it is, you are inevitably bound to face
unicode hell at some point. You can use a prefix convention if that
makes it easier for you, but the point is that you CANNOT just "wing
it". Python makes it too easy to just "wing it" and that creates a
lot of surprises, especially since some methods hide the conversions,
e.g. str.join.

w.r.t. to DB storage, that depends on the specific database you're
using and the DBAPI module you're using, read up on it, write a few
tests on your corresponding DBAPI (simple tests, easy peasy), know
what kinds of strings you're sending in and reading back. I'm using
PostgreSQL often and my configuration always stores strings in UTF-8
in the database. I have a lightweight mapping module that
disambiguiates and does the encoding/decoding automatically in a
consistent way (that decision belongs in the client code for now,
unfortunately, but is centralized using my table declaration that
lists the desired conversions for each column). See
http://furius.ca/antiorm/ for something simple that works well.

cheers,


--
Martin
Furius Python Training -- http://furius.ca/training/
Apr 24 '06 #3
Martin Blais napisa³(a):
See
http://furius.ca/antiorm/ for something simple that works well.


I'd like to know what is this module/library good for *before* I start
downloading it. "Almost like ORM but not exactly" is rather vague term
and can denote anything. Is it dishwasher? Or microwave oven?

BTW, I don't have any problems without character encodings since I
started using unicode objects internally in my programs. Database is the
same kind of data source, as regular files, sockets or ttys -- you have
to know client encoding before you start receiving data. Then decode it
to unicode and you are fine.

--
Jarek Zgoda
http://jpa.berlios.de/
Apr 24 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2032
by: ProgDario | last post by:
HI, I downloaded and installed the I18N pear package, but the link on the doc referring to the DB is broken. Where can I find the I18N DB? Without it I can't make it work! Thanks in advance. :)ario
4
1950
by: Logan | last post by:
Is it possible to tell the wxPython widgets (e.g. file dialogs) to use another language (instead of English)? Thanks in advance for any hints! -- mailto: logan@phreaker(NoSpam).net
10
2975
by: Albretch | last post by:
.. Can you define the Character Set for particular tables instead of databases? . Which DBMSs would let you do that? . How do you store in a DBMS i18n'ed users' from input, coming over the web (basically from everywhere) store it and properly serve it back to users, . . .? . Can you point me to info on this? I would preferably use Java/JDBC drivers.
13
8643
by: Guido Wesdorp | last post by:
Hi! I've just released a JavaScript library to allow internationalizing JavaScript code and/or to do HTML translation from JavaScript. It's a first release, and it doesn't have all the features I'm interested in (e.g. it doesn't support domains, although I don't think that's much of a problem in most JavaScript applications, and it uses a non-standard message catalog format, instead of .po files translations are stored in XML) but it's...
0
1253
by: Laszlo Zsolt Nagy | last post by:
Hello, I wonder if there is a standard for making i18n in Python projects. I have several Python projects that are internationalized. I also have Python packages with i18n. But it is still not clean to me what is the recommended way to do it. Currently, I use a module called 'localization.py' with this code: from i18n_domain import DOMAIN import gettext
3
1625
by: Darren Davison | last post by:
Hi, I have a documentation tool based on Java and XSLT that I want to add i18n capability to. There are around 8 stylesheets that process a Source generated by the Java code and some of the static labels across the stylesheets are the same. Ideally I'd like to import a set of variables into each template, and preferably based on an XSLT parameter (the locale) but this obviously doesn't work:
8
1670
by: Alan J. Flavell | last post by:
OK, I guess I'm about ready to expose this page for public discussion: http://ppewww.ph.gla.ac.uk/~flavell/charset/i18n-weft.html Please concentrate on the content. I'm well aware that my old stylesheet is in need of modernisation, but this isn't the moment to get sidetracked by that. If anyone is previewing IE7 (which I am not), they might care to comment on whether anything has been done to address the problem in IE(<=6) where...
0
1093
by: i18n-bounces | last post by:
Your mail to 'I18n' with the subject Mail Delivery (failure i18n@mova.org) Is being held until the list moderator can review it for approval. The reason it is being held: Post by non-member to a members-only list
8
3196
by: CptDondo | last post by:
I have a small, embedded app that uses a webserver to serve up pages showing status, etc. Right now all the pages are hard-coded in English. We need to provide multi-lingual support. All of the pages are PHP generated. Ideally, I'd like for the PHP backend to serve up the language based a) the user's locale, and if that is not set, its own locale.
0
8430
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8094
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6770
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5966
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5465
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3930
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3977
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2448
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1553
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.