Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, Zope already has gettext-compatible i18n packages available for you, in the form of <a href="http://pypi.python.org/pypi/zope.i18n" rel="nofollow"><code>zope.i18n</code></a>. This is already part of Zope itself, no need to install it separately.</p> <p>Secondly, don't muck about with <code>__builtin__</code>; simply <em>import</em> the message factory into a module and name it <code>_</code>.</p> <p>In your Zope Product <code>__init__.py</code> you add a message factory for this:</p> <pre><code>from zope.i18nmessageid import MessageFactory from AccessControl import ModuleSecurityInfo YourDomainMessageFactory = MessageFactory('your.domain') ModuleSecurityInfo('your.packagename').declarePublic('YourDomainMessageFactory') </code></pre> <p>Now you have a message id factory that can be imported into any of your project python files, <em>including</em> restricted files:</p> <pre><code>from your.packagename import YourDomainMessageFactory as _ message = _('Your message to be translated') </code></pre> <p>Note how we still use <code>_</code> as the local name in the code.</p> <p>You register your message catalogs with a short amount of ZCML:</p> <pre class="lang-xml prettyprint-override"><code>&lt;configure xmlns:i18n="http://namespaces.zope.org/i18n"&gt; &lt;i18n:registerTranslations directory="locales" /&gt; &lt;/configure&gt; </code></pre> <p>where <code>locales</code> is a subdirectory of the directory the <code>configure.zcml</code> file lives. <code>zope.i18n</code> expects to find <code>&lt;REGION&gt;/LC_MESSAGES/yourdomain.mo</code> and optionally, <code>&lt;REGION&gt;/LC_MESSAGES/yourdomain.po</code> files in the registered directory; <code>.po</code> files are automatically compiled into <code>.mo</code> files for you as needed.</p> <p>ZPT page templates use <code>zope.i18n</code> message catalogs by default, see <a href="http://wiki.zope.org/zope3/ZPTInternationalizationSupport" rel="nofollow">ZPT i18n support</a>.</p> <p>If you need to translate something manually, use the <code>zope.i18n.translate</code> function:</p> <pre><code>from zope.i18n import translate message = _('Your message to be translated') print translate(message, target_language='de') </code></pre> <p>Most of the <a href="http://plone.org/documentation/manual/developer-manual/internationalization-i18n-and-localization-l10n" rel="nofollow">Plone i18n manual</a> applies to generic Zope applications.</p> <p>If you absolutely <em>have</em> to be able to poke things into <code>__builtins__</code>, then by all means directly manipulate <code>RestrictedPython.Guards.safe_builtins</code>; it's a dictionary:</p> <pre><code>from RestrictedPython.Guards import safe_builtins safe_builtins['_'] = t.gettext </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload