[Sage 10] how to localize / translate theme?

Hey all,

I want to translate my theme. But I’m not getting it to work and as far as I see there is not yet documentation of sage 10, so I’m asking for some pointers. When I run get_locale() I get the same result as the translated files.

Question:
How do I localize my theme?

Current approach

  • run yarn translate
  • this installs a pot file in /resources/lang/sage.pot
  • I create a new language translation with poedit for my desired language and translate the strings.
  • I don’t know if I should anything extra in poedit
  • I add load_theme_textdomain() to /app/setup.php (example below)
add_action('after_setup_theme', function () {
    load_theme_textdomain('my-domain',  get_stylesheet_directory() . '/lang');
});

current result
I don’t see any of the translated strings in the rendered page

What would be the right approach?

  1. Are the translation domains for the source strings correct? For the strings in the sage theme, the translation domain is `sage.
  2. Does get_stylesheet_directory() . '/lang' result in the proper path to your lang/ folder?
  3. The mo files should have as filename the translation domain (e.g. de_DE_formal.mo or fr_FR.mo).

Thanks @strarsis. The answer lays in your comment.
In package.json I’ve changed the path of the commend script translate like:

    "translate": "npm run translate:pot && npm run translate:js",
    "translate:pot": "wp i18n make-pot . ./lang/my-domain.pot --ignore-domain --include=\"app,resources\"",

So, thats from ./resources/languages/sage.pot to ./lang/my-domain.pot.
(I’ve changed the text domain sage to custom one. I’ve checked this with a clean install as well. )
yarn translate does not work out of the box though.

Thanks once again

This topic was automatically closed after 42 days. New replies are no longer allowed.