Here is the code:
from lino.apps.ledger.ledger_demo import startup from lino.apps.ledger.ledger_tables import Currency sess=startup(langs="en fr") qry=sess.query(Currency,"id name") # show in default language: qry.show() print # switch to FR and show again: sess.setBabelLangs("fr") qry.show() #sess.shutdown()
The Populator in sprl.demo inserts a few rows the Currencies table, specifying their description («name» field) in all known languages. The Populator is not visible in the code snippet, it is a part of demo.startup(). Take a look at the source code in module lino.apps.ledger.demo.
Some of these descriptions won't even be stored, because the populator runs in a certain Database which has a set of supported languages. This set can be specified at startup with the langs= parameter. The default for this field is "en", so usually only the English description is stored. But this time we specify two languages at startup.
Output:
Currencies ========== id |name ---+--------------------------------------------------------------------------- EUR|Euro BEF|Belgian Francs USD|US Dollar EEK|Estonian kroon Currencies ========== id |name ---+--------------------------------------------------------------------------- EUR|Euro BEF|Franc belge USD|Dollar US EEK|Couronne estonienne
TODO: more remarks...
Refering articles:
- tests/32.py (13.02.07) — tests/32.py currently fails because babel1.py now also issues a «QSqlDatabasePrivate::removeDatabase: connection 'Lino Ledger' is still in use, all queries will cease to work.» message. more
- More examples (03.05.05) — A new system to write testable documentation examples. query1.py and babel1.py. TODO: write TestCase that tests them (done on 20050504)