Translations: Difference between revisions

From GNU MediaGoblin Wiki
Jump to navigation Jump to search
(Add one hint link for translators)
Line 18: Line 18:


=== In python code ===
=== In python code ===

Usually, like this:

<pre>
<pre>
from mediagoblin.util import pass_to_ugettext as _
from mediagoblin.util import pass_to_ugettext as _
Line 23: Line 26:
def some_func(something):
def some_func(something):
return _(u'This string would tooootally be translatable now.')
return _(u'This string would tooootally be translatable now.')
</pre>

Except, in form modules we don't actually want to translate things because for various reasons that doesn't work, so we do the translation call template-side. So write the module to use the fake ugettext passthrough (which doesn't do any translation but still wraps things in _() so that Babel will know to extract these strings):

<pre>
from mediagoblin.util import fake_ugettext_passthrough as _

class FunkyMonkeyForm(wtforms.Form):
funky = wtforms.TextAreaField(
_('Funkiness description'))
</pre>
</pre>



Revision as of 17:28, 10 August 2011

For translators

You can translate our tools at Transifex:

https://www.transifex.net/projects/p/mediagoblin/resource/mediagoblin/

Note: please don't translate the words "MediaGoblin" or "GNU" into your native language. Those words should be retained as-is for branding reasons. :)

For developers

Marking strings for translation

In Jinja2

See: http://jinja.pocoo.org/docs/templates/#i18n

Mostly like Django template i18n support, if you have any experience with that.

In python code

Usually, like this:

from mediagoblin.util import pass_to_ugettext as _

def some_func(something):
    return _(u'This string would tooootally be translatable now.')

Except, in form modules we don't actually want to translate things because for various reasons that doesn't work, so we do the translation call template-side. So write the module to use the fake ugettext passthrough (which doesn't do any translation but still wraps things in _() so that Babel will know to extract these strings):

from mediagoblin.util import fake_ugettext_passthrough as _

class FunkyMonkeyForm(wtforms.Form):
    funky = wtforms.TextAreaField(
            _('Funkiness description'))

Extracting translations

If you run buildout it should create a script called 'pybabel'. Use it to extract translations like so:

./bin/pybabel extract -F babel.ini -o mediagoblin/i18n/en/LC_MESSAGES/mediagoblin.po .

Compiling translations

./bin/pybabel compile -D mediagoblin -d mediagoblin/i18n/

Pulling translations from Transifex

Unfortunately until the next release of transifex-client which has been patched to have proper entry points, you have to run transifex-client from a virtualenv or from site-packages. But assuming that's done, pulling translations is easy:

tx pull -a

Pushing new translations to Transifex

tx push -s