How to localize both Genesis Framework and a custom child theme, without the risk of framework upgrades removing the gettext catalogs.
This example covers localizing a theme in Spanish (Mexico), but the process is the same for other languages and locales.
Prerequisites:
- Genesis Framework installed at
/wp-content/themes/genesis
- A custom child theme installed at
/wp-content/themes/example-genesis-child
- Poedit installed
Steps:
- Wrap translatable strings in
__()
or_e()
, using a theme-specific text domain (e.g.example-genesis-child
). See i18n for WordPress Developers for an overview. - Scan your local copy of
/example-genesis-child
with Poedit and create/example-genesis-child.pot
- Use Poedit, Poeditor, GlotPress, or another tool to translate your strings.
- Create a
languages
directory in the child theme root. - Export your gettext catalogs from Poedit as language_locale.po and language_locale.mo (e.g.
es_MX.po
) and place them in/languages
. - Create the
/languages/genesis
. - Export the corresponding Genesis Framework gettext catalogs as language_locale.po and language_locale.mo (e.g.
es_MX.po
) and place them in/languages/genesis
- Add the following to the beginning of
/example-genesis-child/functions.php
:<?php // Use copy of Genesis Framework language files for upgrade stability define( 'GENESIS_LANGUAGES_DIR', get_stylesheet_directory() . '/languages/genesis' ); // Must be added before Genesis Framework /lib/init.php is included add_action( 'after_setup_theme', 'example_genesis_child_setup' ); function example_genesis_child_setup() { load_child_theme_textdomain( 'example-genesis-child', get_stylesheet_directory() . '/languages' ); }
You should have four new files in the child theme directory:
/wp-content/themes/example-genesis-child/languages/es_MX.po
/wp-content/themes/example-genesis-child/languages/es_MX.mo
/wp-content/themes/example-genesis-child/languages/genesis/es_MX.po
/wp-content/themes/example-genesis-child/languages/genesis/es_MX.mo