Sphene Community Tools

Community

Copyright © 2007-2018 by Herbert Poul

You are not logged in.
Login
Register

Change Language:



AddThis Social Bookmark Button

A Django site.

Powered by Sphene Community Tools
Board » General » Where is i18n? Here is some.

Hi!

I noticed that SCT is not i18n-ized at all. This is really not cool :( I'd like to use SCT for non-english users so I really need i18n.

Because I don't need a wiki at the moment so I'have put some i18n into sphboard and accompanying apps: community and sphlinklist. The patch (containing polish translation files) is attached. I'll be happy if someone will check it and hopefully commit to trunk ;)

Important notes:
1. To make i18n working in Django it is required to use localemiddleware so please modify your settings.py to include it.

2. Another thing is that my patch only contains .po translation files so the files should be opened with poedit and saved (to generate binary .mo files).

I'm not completly happy with some translations in templates but there were situations where blocktrans was not able to include tags and I didn't want to make changes into the SCT code (to replace some tags with filters for example).
Attachments
thanks a lot for your efforts ..
i thought about adding i18n support .. but never had the time to do so .. i'll probably be able to try out your patch tomorrow or so ..

could you please explain me the problems you had with translating the templates ? maybe you could give me an example ? i haven't really worked yet with the i18n functions for templates
Hey, we have Signatures !!! Great, isn't it ? ;)
thanks a lot for your efforts ..
i thought about adding i18n support .. but never had the time to do so .. i'll probably be able to try out your patch tomorrow or so ..

could you please explain me the problems you had with translating the templates ? maybe you could give me an example ? i haven't really worked yet with the i18n functions for templates
Sure. Here is an example (from _displayLatestPost.html)
We have some code to be translated
By {% sphboard_displayUserName latestPost.author %}

The proper way to translate the above is to include both "By" and "username" (which is a tag result) in translation string. Then a translator will be able to write his translation like:
1. "translated 'By'" "username"
2. "username" "translated 'By'"
3. "something" "username" "something"
etc.

If you'll translate only "By" then it may not be enough (especially in harder cases than the above) to translate the sentence properly. It's always (IMHO) the best to put whole sentence into translation string.

To put a variable into a translation we can use {% blocktrans %} tag (see docs) but the problem is that blocktrans only accepts template variables and not whole tags. So the sentence from my example is not translatable :( I had to use:
{% trans "By" %} {% sphboard_displayUserName latestPost.author %}

which only translates "By"

To be able to translate the whole sentence we need to get rid of a tag in favour of something like:
{% blocktrans with latestPost.author|username_filter as username %}
 By {{ username }}
{% endblocktrans %}


regards
ok.. i think this is not a big problem.. it should be rather easy to convert most of them to template filters..

anyway .. i have applied your patch, and had to make a few changes to make it work with sphblog/sphlinklist ..

basically i've moved some initialization from __init__.py to views.py .. i'm still not sure what the best way would be to do something on startup in django .. anyway ..
the problem was that i got the following exception:

Traceback (most recent call last):
  File "./manage.py", line 11, in ?
    execute_manager(settings)
  File "/opt/local/lib/python2.4/site-packages/django/core/management/__init__.py", line 272, in execute_manager
    utility.execute()
  File "/opt/local/lib/python2.4/site-packages/django/core/management/__init__.py", line 219, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/local/lib/python2.4/site-packages/django/core/management/base.py", line 72, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/opt/local/lib/python2.4/site-packages/django/core/management/base.py", line 81, in execute
    translation.activate('en-us')
  File "/opt/local/lib/python2.4/site-packages/django/utils/translation/__init__.py", line 73, in activate
    return real_activate(language)
  File "/opt/local/lib/python2.4/site-packages/django/utils/translation/__init__.py", line 43, in delayed_loader
    return g['real_%s' % caller](*args, **kwargs)
  File "/opt/local/lib/python2.4/site-packages/django/utils/translation/trans_real.py", line 213, in activate
    _active[currentThread()] = translation(language)
  File "/opt/local/lib/python2.4/site-packages/django/utils/translation/trans_real.py", line 202, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "/opt/local/lib/python2.4/site-packages/django/utils/translation/trans_real.py", line 185, in _fetch
    app = getattr(__import__(appname[:p], {}, {}, [appname[p+1:]]), appname[p+1:])
  File "/Users/herbert/dev/python/communitydraft/community/../../communitytools/sphenecoll/sphene/sphlinklist/__init__.py", line 3, in ?
    from sphene.sphlinklist.categorytype import doinit
  File "/Users/herbert/dev/python/communitydraft/community/../../communitytools/sphenecoll/sphene/sphlinklist/categorytype.py", line 9, in ?
    from sphene.sphboard.views import PostForm
  File "/Users/herbert/dev/python/communitydraft/community/../../communitytools/sphenecoll/sphene/sphboard/views.py", line 153, in ?
    class PostForm(forms.Form):
  File "/Users/herbert/dev/python/communitydraft/community/../../communitytools/sphenecoll/sphene/sphboard/views.py", line 156, in PostForm
    help_text = describe_render_choices(), )
  File "/Users/herbert/dev/python/communitydraft/community/../../communitytools/sphenecoll/sphene/sphboard/renderers.py", line 158, in describe_render_choices
    return ugettext_lazy('You can use %(description)s in your posts') % {'description':desc}
  File "/opt/local/lib/python2.4/site-packages/django/utils/functional.py", line 98, in __mod__
    return unicode(self) % rhs
  File "/opt/local/lib/python2.4/site-packages/django/utils/functional.py", line 77, in __unicode_cast
    return self.__func(*self.__args, **self.__kw)
  File "/opt/local/lib/python2.4/site-packages/django/utils/translation/__init__.py", line 62, in ugettext
    return real_ugettext(message)
  File "/opt/local/lib/python2.4/site-packages/django/utils/translation/trans_real.py", line 292, in ugettext
    return do_translate(message, 'ugettext')
  File "/opt/local/lib/python2.4/site-packages/django/utils/translation/trans_real.py", line 282, in do_translate
    _default = translation(settings.LANGUAGE_CODE)
  File "/opt/local/lib/python2.4/site-packages/django/utils/translation/trans_real.py", line 202, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "/opt/local/lib/python2.4/site-packages/django/utils/translation/trans_real.py", line 185, in _fetch
    app = getattr(__import__(appname[:p], {}, {}, [appname[p+1:]]), appname[p+1:])
AttributeError: 'module' object has no attribute 'sphlinklist'


anyway .. after my modifications it ran smoothly .. i think i'll start translating the board & community to german :)

btw. since you obviously have more experience with i18n - how do you compile the message files ? is there a simple way to compile all of them from my project, or do i have to do this for each application separately ?


thanks,
herbert

(fyi - i have added you now to the AUTHORS file)
Hey, we have Signatures !!! Great, isn't it ? ;)
ok.. i think this is not a big problem.. it should be rather easy to convert most of them to template filters..

anyway .. i have applied your patch, and had to make a few changes to make it work with sphblog/sphlinklist ..

basically i've moved some initialization from __init__.py to views.py .. i'm still not sure what the best way would be to do something on startup in django .. anyway ..

the problem was that i got the following exception:

(...)
AttributeError: 'module' object has no attribute 'sphlinklist'


anyway .. after my modifications it ran smoothly .. i think i'll start translating the board & community to german :)
Strange. It worked well for me and works after your changes too :). I think that this is caused by different settings in my and your's settings.py.

To answer your problem with "doing something on startup in django" I can quote this (http://code.djangoproject.com/wiki/IrcFAQ):
I want to have some code run when the server/application starts. How do I do that?

Both mod_python and FastCGI are structured in such a way that there's no such thing as "application startup" or "server startup"; the best solution is to place your "startup" code somewhere that's guaranteed to be imported early on in the request/response cycle (the __init__.py file of your project, or of a specific application you're using, can be a good place, because Python will execute code found there the first time it has to import the module; just be aware that referencing the same module in different ways, say by doing from myproject.myapp import foo in one place, and from myapp import foo in another, will cause that code to be executed once for each different way you import it).


For example in django-multilingual project there is:
from multilingual.translation import Translation
in __init__.py and
# install the library
install_translation_library()
call in multilingual.translation package.

btw. since you obviously have more experience with i18n - how do you compile the message files ? is there a simple way to compile all of them from my project, or do i have to do this for each application separately ?

I dont'know. I have always compiled .po files per application using "poedit" editor. The .mo files should be placed in svn too.

thanks,
herbert

(fyi - i have added you now to the AUTHORS file)

Nice. Thanks :)
btw. since you obviously have more experience with i18n - how do you compile the message files ? is there a simple way to compile all of them from my project, or do i have to do this for each application separately ?
Hmm.. I have thought about this and maybe the proper solution for SCT is to generate only one message file for all apps. I never did it but it is possible: http://www.djangoproject.com/documentation/i18n/#message-files

Arrgh.. javascript! I forgot about js translations... That means that I've put gettext into _displayPostForm but I haven't added neither i18n url nor i18n js import:

url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict, name='js-i18n'),


and

<script type="text/javascript" src="{% url js-i18n %}"></script>


The above must be placed into urls.py and a top template. I've tried adding it to sphene.community but it raises:
Request Method:	GET
Request URL:	http://localhost:8000/community/jsi18n/
Exception Type:	TypeError
Exception Value:	javascript_catalog() got an unexpected keyword argument 'group'
Exception Location:	/home/ext/workingenvs/sphene/lib/python2.5/site-packages/django/core/handlers/base.py in get_response, line 82
Python Executable:	/usr/bin/python
Python Version:	2.5.1
Python Path:	[(...)]


Possibly you know what is 'group' and you'll be able to get this to work, but for now please remove gettext from _displayPostForm.html.

--- Last Edited by Jakub Wiśniowski at 2008-02-17 21:55:17 ---
Here is an update to previous i18n stuff. These are mainly 'profile form' related translations I missed earlier. The patch should work on current trunk.

I also attach polish .mo files for community, sphboard and linklist that IMHO should be added to repository.
Attachments
How about my patch?
How about my patch?
ooops.. i'm sorry ..
i've committed it now ... and.. i've compiled all the .mo files .. and committed them too .. i guess this makes most sense ..
i have written a small script in communitytools/dist/scripts/compile-all-sph-messages.py which compile all messages from all SCT application (currently .. community,sphboard,sphlinklist .. the others have no translations yet)

Hey, we have Signatures !!! Great, isn't it ? ;)
Arrgh.. javascript! I forgot about js translations... That means that I've put gettext into _displayPostForm but I haven't added neither i18n url nor i18n js
well .. i guess this is only required for either static .js files, or for dynamic messages. the 'Loading preview' messages are static in templates.. so i have simply changed that (in the sphboard) to:

show\ResponseInElement( 'previewarea', '{% trans "Loading Preview ..." %}',


i see no disadvantage in this .. and it doesn't require any additional urlconfs ..

in the long run .. i will probably see how i can configure the JS i18n handlers you've described in the community/urlconf.py ..

Hey, we have Signatures !!! Great, isn't it ? ;)

Please login to post a reply.



Powered by Sphene Community Tools