Upgrade-Safe Genesis Framework Child Theme Localization

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:

  1. 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.
  2. Scan your local copy of /example-genesis-child with Poedit and create /example-genesis-child.pot
  3. Use Poedit, Poeditor, GlotPress, or another tool to translate your strings.
  4. Create a languages directory in the child theme root.
  5. Export your gettext catalogs from Poedit as language_locale.po and language_locale.mo (e.g. es_MX.po) and place them in /languages.
  6. Create the /languages/genesis.
  7. 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
  8. 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

Leave a Reply

Your email address will not be published. Required fields are marked *