I'm starting to write a small trac plugin, which seems to work so far so good. My problem is I can't get trac + genshi + i18n to translate the elements in my .html templates with my translations. :( The tools I use: Ubuntu Server, Trac 0.12, Babel 0.9.5, Genshi 0.6, mod_python 3.3.1, pysqlite 2.4.1, Python 2.6.5 (r265:79063, Apr 16 2010, 13:28:26) [GCC 4.4.3], setuptools 0.6, SQLite 3.6.22, jQuery: 1.4.2
I read http://trac.edgewall.org/wiki/CookBook/PluginL10N and did the following: 1. created setup.cfg (complete content): ----------------------------------------- [extract_messages] add_comments = TRANSLATOR: msgid_bugs_address = [email protected] output_file = testProject/locale/messages.pot keywords = _ N_ tag_ width = 72 [init_catalog] input_file = testProject/locale/messages.pot output_dir = testProject/locale domain = testProject [compile_catalog] directory = testProject/locale domain = testProject [update_catalog] input_file = testProject/locale/messages.pot output_dir = testProject/locale domain = testProject 2. adjusted setup.py (complete content): ----------------------------------------- from setuptools import find_packages, setup extra = {} extractors = [ ('**.py', 'python', None), ('**/templates/**.html', 'genshi', None), ] extra['message_extractors'] = { 'testProject': extractors, } setup( install_requires = ['Trac >= 0.12'], name='TracTestProject', version='0.1', packages=find_packages(exclude=['*.tests*']), entry_points=""" [trac.plugins] testProject= testProject """, package_data = { 'testProject': [ 'templates/*.html', 'htdocs/js/*.js', 'htdocs/css/*.css', 'locale/*/LC_MESSAGES/*.mo', ] }, **extra ) 3. created a 'locale' subfolder 4. added the following lines to my api.py file (just the additions): --------------------------------------------------------------------- at the top: ---------------------- import pkg_resources from trac.util.translation import domain_functions _, tag_, N_, add_domain = domain_functions('testProject', ('_', 'tag_', 'N_', 'add_domain'))[/code] at the beginning of my class ----------------------------------------- def __init__(self): locale_dir = pkg_resources.resource_filename('testProject', 'locale') add_domain(self.env.path, locale_dir) 5. adjusted the html-tag in all my .html templates: ------------------------------------------------------- (I suspect this is where I went wrong somehow) <html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://genshi.edgewall.org/" xmlns:i18n="http://genshi.edgewall.org/i18n/" xmlns:xi="http://www.w3.org/2001/XInclude" i18n:domain="testProject"> <xi:include href="layout.html" />[/code] So far so good,.. Calling "python ./setup.py extract_messages" gives me: running extract_messages extracting messages from testProject/__init__.py extracting messages from testProject/api.py extracting messages from testProject/db.py extracting messages from testProject/model.py extracting messages from testProject/web.py extracting messages from testProject/templates/testProject.html extracting messages from testProject/templates/docket_edit.html extracting messages from testProject/templates/docket_list.html extracting messages from testProject/templates/docket_view.html writing PO template file to testProject/locale/messages.pot and the created .pot file looks fine (as far as I can tell) (some elements seemed to be missing bug after using i.e. _('Add') instead of 'Add' these elements also appeared in the .pot file) Calling "python ./setup.py init_catalog -l de_DE" gives me: running init_catalog creating catalog 'testProject/locale/de_DE/LC_MESSAGES/testProject.po' based on 'testProject/locale/messages.pot' after editing the newly created testProject.po and calling "python ./ setup.py compile_catalog -f -l de_DE" I get: running compile_catalog compiling catalog 'testProject/locale/de_DE/LC_MESSAGES/ testProject.po' to 'testProject/locale/de_DE/LC_MESSAGES/ testProject.mo' For deployment I use the following script: ----------------------------------------------- #!/bin/bash TARGET="/var/trac/testProject/plugins/" clean() { rm -rf \ src/dist \ src/build \ src/TracTestProject.egg-info/dependency_links.txt \ src/TracTestProject.egg-info/entry_points.txt \ src/TracTestProject.egg-info/PKG-INFO \ src/TracTestProject.egg-info/requires.txt \ src/TracTestProject.egg-info/SOURCES.txt \ src/TracTestProject.egg-info/top_level.txt } clean cd src python ./setup.py extract_messages python ./setup.py update_catalog python ./setup.py compile_catalog -f python ./setup.py bdist_egg cd .. rm -f ${TARGET}/* cp src/dist/TracTestProject*.egg ${TARGET} clean after running the script a .egg was created and added to trac. Now I restarted apache2 (sudo service apache2 restart) and looking at the trac page with a browser I see: 1. my plugin is working 2. all the elemente in the .po file that link to auf python code were translated using the translations I definied 3. all the elements in the .html templates that were covered by the standard translations were translated (i.e. 'Add' -> 'Hinzufügen') 4. all other elements in the .html templates were not :( (nor were the translations I sepcified that overlap the standard translations used) [b]Problem/Conclusion:[/b] Something is not working as it should and I got no clue what I did wrong. I suspect it's related to the i18n:domain and genshi not finding the domain or my files. :/ Would be nice if someone more experienced with this could give a hand. :) Thanks! Cu Selur Ps.: I never used python or trac&co so I hope the above helps to understand my problem. If I need to provide further informations please say so. My overview over the whole thing isn't so good atm. so please be patient. :) -- You received this message because you are subscribed to the Google Groups "Trac Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/trac-users?hl=en.
