Re: [SQLObject] Objects with localized properties
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: deelan <de...@in...> - 2003-05-07 17:34:45
|
Ian Bicking wrote: >>probably this solution make more sense: >> >>p1 = Product(10) >>p1.setLocale('it') >>p1.name <-- get italian name >>p1.setLocale('en') >>p1.name <-- get english name >> >>finally i would like to avoid doing this: >> >>p1 = Product(10) >>p1.nameEn <-- return english name >>p1.nameIt <-- return italian name >> >>since when a new locale is added i need to add a new variable. >>what are your thoughts? > > > What are you thinking for the database schema? I imagine there's two > columns in that case. to clarify as DB schema i was thinking to something like this: Product table ProductId ... ProductName table ProductId Name Lang where "lang" is out 2 char lang code, this would require a join between the two tables, by doing this i will avoid to mess up things when i need to add a name with a new localization. if i understood correctly via sqlobject i can auto join the two tables. i need to use one of those Join objects, is this correct? > > One possibilty might be to have a nameEn and nameIt, and do to: > > class Product(SQLObject): > ... > def _get_name(self): > if self.locale == 'en': return self.nameEn > elif self.locale == 'it': return self.nameIt > def _set_name(self, value): > if self.locale == 'en': self.nameEn = value > elif self.locale == 'it': self.nameIt = value > > But, assuming locale gets set by the interface somehow, this makes > Person unthreadsafe for multiple users with multiple languages (since > typically a single object would be shared among them). mmm, that's true. i didn't think to this possibility. > (...) Then you might get p1.name['en'] -- i.e., name returns a dictionary, that is > created from name_en, name_it, etc. Maybe that would be defined like: > > class Product(SQLObject): > name = DictOfCols({'it': 'name_it', 'en': 'name_en'}) > > But that's just speculative. Again, without changes you can implement > _get_name(self): return {'it': self.nameIt, 'en': self.nameEn}, at least > until I feel clearer implementing something specific. mmm, this is a nice solution but i'm having hard time to figuring out the entire thing. i'll think about it. thanks for the support. |