Internationalization and Location - jordy33/turbogears_tutorial GitHub Wiki
Making your code international
Whenever you write a message that has to displayed you must let TurboGears know that it has to be translated.
Even though TurboGears is able to automatically detect content inside tags and mark them for translation all the strings inside controllers must be explicitly marked as translated.
This can be achieved with the tg.i18n.ugettext() and tg.i18n.lazy_ugettext() calls which are usually imported with _ and l_ names:
from tg.i18n import ugettext as _
class RootController(BaseController):
@expose('myproj.templates.index')
def index(self):
return dict(msg=_('Hello World'))
html
colNames: ['id', "${_('Filter name')}", "${_('Expression')}","${_('Action')}","${_('Reset Expression')}","${_('Counter')}"],
$.alert("${_('Log has been trigger')}", { autoClose:true,type: 'success',});
Commands
To fresh start a translation, you could use the following command to handle your locales:
init_catalog
Extract all the translatable strings from your project’s files by using the following command:
(only one time)
Initialize Spanish Catalog . (Only the first time)
The country code could be es(Spanish), fr(France), zh_tw(Taiwan), jp(JAPAN), ru(Russian), or any other country code.
python setup.py init_catalog -l es
Extract
You can extract all messages from the project with the following command: (The extract will create a .POT file)
python setup.py extract_messages
Update Catalog (after extracting the messages with the above command).
You must update the catalog with the following command: (The update will take the .POT file and will update the .po file)
python setup.py update_catalog -l es
Compile Catalog
You can compile all messages from the project with the following command: (This will generate the .po file)
python setup.py compile_catalog
You must update .po and .mo files in the destination location You also must restart the program to get the translation