Re: [sqlalchemy] Re: internationalization of content
Hi, Having seen Nil's elexir approach I had another go at this problem. I wanted a solution which is usable from non Python tools accessing the database, so I came up with: e.g. for countries: - Country/countries - class and table with the default language values and everything else for countries - Country_L/countries_l - class and table with the localized column information - countries_lp - a stored procedure which does the localization/default value stuff (uses some Firebird SQL specific code, which could probably be changed to be more generic) - Country_LV/countries_lv - class and database view, the select of the view is using the stored procedure Using it looks like this: # set localization to DE_de session.execute(select rdb$set_context('USER_SESSION', 'LANG_CODE', 'DE_de')from rdb$database).fetchone() session.commit() print ' base table ' result = session.query(db.Country) for item in result: print item.name print ' localize for DE_de ' result = session.query(db.Country_LV) for item in result: print item.name # set localization to FR_fr session.execute(select rdb$set_context('USER_SESSION', 'LANG_CODE', 'FR_fr')from rdb$database).fetchone() session.commit() print ' localize for FR_fr - which is getting default value for e.g. France and Germany ' result = session.query(db.Country_LV) for item in result: print item.name which results in: base table France Switzerland Germany localize for DE_de Frankreich Schweiz Deutschland localize for FR_fr - which is getting default value for e.g. France and Germany France Suisse Germany The SA model for this looks like this: class Country(Base, CreateUpdateMixin): __tablename__ = u'countries' id = sa.Column(sa.BigInteger(), sa.Sequence('countries_id'), primary_key=True, nullable=False) name = sa.Column(sa.String(length=30, convert_unicode=False)) iso2 = sa.Column(sa.String(length=2, convert_unicode=False)) iso3 = sa.Column(sa.String(length=3, convert_unicode=False)) telcode = sa.Column(sa.SmallInteger()) __localize_columns__ = ['name', ] class Country_L(Base): __table__ = sautils.make_localize_table(Country(), 'countries_l', metadata) class Country_LV(Base): __table__ = sautils.make_localize_view(Country(), 'countries_lv', metadata) I am sure that this could be done even nicer/better and that it could be done in a way that would be compatible with meta.drop_all(engine) and meta.create_all(engine), currently I need to create the _LV view and the stored procedure outside of sa. The make_localize_* functions are inspired from code I have seen in wiki/UsageRecipes. If there is interest to further enhance this and get it to SQLAlchemy standard of code I would very much like to help but I am not good enough a coder to actually do the work or I would definitely need a lot of hand holding and coaching. Werner -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: internationalization of content
Hi, I must admit that I discovered the test I wrote to assert my approach works for polymorphic content is wrongly True. I'm working at making it reallty work but it is not that easy. Still for non polymorphic content it is quite ok of course, it is completely elixir oriented, but I'm sure it could be ported to pure sqla -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: internationalization of content
Hello again, I published an updated version of acts_as_localized on http://code.google.com/p/elixirlocalized/ It is an Elixir's Entity builder that will manage several translations for DB contents If anyone cares to review or use it. NiL -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Re: internationalization of content
Hi Nil, On 14/09/2010 21:58, NiL wrote: Hi Werner, many thanks for your rich reply. I'm going to try an elixir implementation for now. If you want follow the thread of the same title in the elixir mailing list. Thanks for letting me know. One of the things which disturb me about SA or Elixir approach is that other means to access the database will now have access to the translations, e.g. Report Writer accessing the db directly, tools like Excel using the db via ODBC etc etc. I am surprised that db's at this point in time don't have some support for something like this. Werner -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: internationalization of content
Hi chris, thanks for your reply. I guess it is not an application framework oriented question. It seems to me rather a question of database design/access. I have a pointer to modify the elixir versioning extension to provide this functionnality. It would be framework oriented, if we were talking about the translations of templates, which is not the case. best NiL -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: internationalization of content
Hi Werner, many thanks for your rich reply. I'm going to try an elixir implementation for now. If you want follow the thread of the same title in the elixir mailing list. I'll stay tuned to any sqla development best NiL -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.