Kidでのlocaleの有効化
デフォルトではKidテンプレート内文字列のlocaleによる言語翻訳は有効にならない。下記の設定をすることで、有効にすることができる。
設定ファイル(*.cfg)
i18n.locale_dir = '/home/hogehoge/myproject/locales' (localesディレクトリのパス:dev.cfgでは不要) i18n.run_template_filter = True
テンプレート
それぞれのテンプレートに下記の内容を追加する。master.kidにでも追加しておけば楽。
【DOCTYPE宣言の直後】 <?python from turbogears.i18n import translate ?> 【html開始タグの直後】 <translate py:match="True" py:replace="translate(item)"/>
デフォルトのmaster.kidに対する修正はこんな感じ。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <?python import sitetemplate ?> <?python from turbogears.i18n import translate ?> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#" py:extends="sitetemplate"> <translate py:match="True" py:replace="translate(item)"/> <head py:match="item.tag=='{http://www.w3.org/1999/xhtml}head'" py:attrs="item.items()"> ...
あとは、tg-admin toolboxのAdmi18nで、翻訳するだけ。