Wordpress Bundle
  • What is Wordpress Bundle?
  • Getting started
    • Installation
    • Wordpress
    • Router
    • Cron job
    • Templates
  • Reference
    • Argument resolver
    • Controller
      • AdminAction
      • BlogController
      • FrontAction
      • WordpressAction
    • Entity
      • Block
      • Blog
      • Comment
      • File
      • Image
      • Menu
      • MenuItem
      • Post
      • Term
      • User
    • Repository
      • CommentRepository
      • PostRepository
      • TermRepository
      • UserRepository
    • Service
      • PaginationService
      • BreacrumbService
  • Guides
    • Server requirements
    • Install plugins
    • Use Multisite
    • Gutenberg
    • WP Steroids plugin
      • Image options
      • Maintenance
      • Admin pages removal
      • WYSIWYG Editor
      • Feature Support
      • Multi-site configuration
      • Constants definition
      • ACF configuration
      • Menu
      • Custom Post type
      • Advanced permalink settings
      • Custom Taxonomy
      • Templates
      • Page states
      • External table viewer
      • Roles
      • Optimisations
      • Security
      • Search
    • Twig Cookbook
    • Inject variables in all templates
    • Internationalization
    • Extending Wordpress Bundle
    • Error pages
    • Site health
  • Integrations
    • Advanced Custom Fields
      • Install ACF PRO
  • Extras
    • Migrating from 1.x to 2.0
    • Roadmap
    • Changelog
    • Alternatives
Powered by GitBook
On this page
  • Translation functions
  • Generating localization files

Was this helpful?

  1. Guides

Internationalization

PreviousInject variables in all templatesNextExtending Wordpress Bundle

Last updated 3 years ago

Was this helpful?

Internationalization of a theme works pretty much the same way as it does for default WordPress themes. Follow the guide in the to setup i18n for your theme.

Twig has its own i18n extension that gives you {% trans %} tags to define translatable blocks, but there’s no need to use it.

Translation functions

Wordpress Bundle add all the translation functions used in WordPress:

  • __()

  • _x()

  • _n()

  • _nx()

  • _n_noop()

  • _nx_noop()

  • translate()

  • translate_nooped_plural()

The functions _e() and _ex() are also supported, but you probably won’t need them in Twig, because {{ }} already echoes the output.

<p class="entry-meta">{{ __('Posted on', 'my-text-domain') }} [...]</p>
<p class="entry-meta">{{ __('Posted on %s', 'my-text-domain')|format(post.date) }}</p>

Generating localization files

Generating l10n files with Poedit 2

Store .mo and .po into the /translations folder

To generate .pot, .po and .mo files, you need a tool that supports parsing Twig files to detect all your translations. While there are a lot of tools that can parse PHP files, the solution that works best for Twig files is .

fully supports Twig file parsing (Pro version only) with the following functions: __(), _x(), _n(), _nx().

WordPress Theme Handbook
Poedit
Poedit 2