[orm-devel] How to handle multi language?
Diedrich Vorberg
diedrich at tux4web.de
Fri Jun 17 12:52:48 CEST 2005
Hi Werner!
> My application supports multiple languages (en, de, fr), my current
> implementation works but I think there is "space for improvement"
> and I am looking for some hints/suggestions on how to do this.
> Thanks in advance for any ideas and/or hints.
I've got an idea I used for a web application, It's not ideal,
though. I used one column per table per language like this:
CREATE TABLE something
(
title_de TEXT,
description_de TEXT,
title_en TEXT,
description_en TEXT
);
I'm using Livinglogic's XIST XML handling library to create XHTML
output which represents the XHTML DOM tree using Python classes. I
inserted the relevant data into the dom tree with the HTML attribute
lang="" set to the correct language. Just previous to delivery I have
a little routine walk the DOM tree an delete all entries that do not
fit the user's language.
If you are writing a GUI application you might want to create the
model-Module (the one with all the dbclasses in) on startup depending
on the user's language settings. Than you could mangle the columns
dicts according to the locale. Like this (just a code-sketch)
from orm.dbclass import dbclass
from orm.columns import *
from orm.firebird.columns import *
class something(dbclass):
pass
something_columns = ( ("title", text, "title_%s"),
("description", text, "description_%s"), )
class someting_else(dbclass):
pass
something_columns = ( ("blah", text, "blah_%s"),
("blub", text, "blub_%s"), )
# figure out my locale, determine language abriviation, store it
in lang variable
for class_name in ("something", "something_else"):
dbclass = locals()[class_name]
column_tuples = locals()[class_name]
columns_dict = {}
for attribute_name, column_class, sql_column_name in
column_tuples:
columns_dict[attribute_name] = column_class
(column_name="sql_column_name" % lang)
dbclass.columns = columns_dict
# now you can normaly instantiate something and something_else
There is another idea I had: a dict_relationship that would let you
access different columns in a dbclass like a dict as in
dbobj.attribute[lang]
which maps to SQL column dbobj's attribute_"lang"-column.
Diedrich
--
Diedrich Vorberg <diedrich at tux4web.de> .---. / \
http://tux4web.de Tel: 02302 425269 / \ ((__-^^-,-^^-__))
\.O-O./ `-_---' `---_-'
"Unix is simple, but it takes a genius /`\_/`\ `--|o` 'o|--'
to understand the simplicity." // _ \\ \ ` /
- Dennis Ritchie | \ )|_ ): :(
/`\_`> <_/ \ :o_o:
Associate Member of the FSF #1245 \__/'---'\__/ "-"
More information about the orm-devel
mailing list