Make Theme Available for Translation (Sage9)


I checked the git for any closed issues and found Issue #1672 and Issue #1770, as @ben said we could still discuss this, I’m opening it here :slight_smile:

I believe #1770 makes more sense and does not necessarily mean we should provide a default .po/.mo file, as @ben said it is not really the point of a starter theme, however is the theme correctly uses gettext calls it should also load the textdomain.

This is quite simple to do, still it belongs on a starter theme as being almost required on all projects.

I suggest adding it to app/setup.php:110

    'dir.language'   => get_stylesheet_directory() . '/lang/',

And after that:

 * Make theme available for translation
load_theme_textdomain('sage', $paths['dir.language']);

And creating a lang folder, not really needed to add a .po file in my opinion.

1 Like

I tried your solution and it works fine on the front-end, but if you have for example setup your custom post type labels to be translatable with your text-domain, they won’t show in the backend. Moving the load_theme_textdomain call outside the after_setup_theme function will fix this!

Sorry I stand corrected, my register_post_type calls were not hooked into init action.
When they are, it does work inside the after_setup_theme call!