• Resolved derrida

    (@derrida)


    i have a test site locally with my theme and good thing cause when i upgraded to 6.7 all my theme translations are not working.
    in my theme setup function which uses the after_setup_theme action i always had this line:

    load_theme_textdomain('gutrs', get_template_directory() . '/languages');

    now it stopped working? any idea why?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Mayuri

    (@mayuripatel)

    To make translations work in WordPress 6.7, you need to update how you’re loading them. Here’s what you should do:

    1. Update load_theme_textdomain Function

    Since WordPress 6.7 now expects translations to be in wp-content/languages/themes/, you should update your load_theme_textdomain call to reflect this change. You can override the default path like this:

    function my_theme_setup() {
    load_theme_textdomain('gutrs', WP_LANG_DIR . '/themes');
    }
    add_action('after_setup_theme', 'my_theme_setup');

    This will tell WordPress to look for translations in the wp-content/languages/themes/ directory instead of the theme’s languages folder.

    2. Move Your Translation Files

    Move your translation files from your theme’s /languages/ folder to the following directory in your WordPress installation:

    wp-content/languages/themes/gutrs-{locale}.mo

    For example, if you’re using French translations, the file would be:

    wp-content/languages/themes/gutrs-fr_FR.mo

    3. This centralizes your translations and ensures they work with the new system in WordPress 6.7.3. Fallback for Development Environments (Optional)

    If you still want to keep using the theme’s languages folder for translations (for development purposes or testing), you can keep your current setup and also explicitly specify the path to the theme’s folder:

    function my_theme_setup() {
    load_theme_textdomain('gutrs', get_template_directory() . '/languages');
    load_theme_textdomain('gutrs', WP_LANG_DIR . '/themes'); // Fallback to global folder
    }
    add_action('after_setup_theme', 'my_theme_setup');

    This ensures that WordPress will check both the theme’s local languages folder and the central wp-content/languages/themes/ directory.

    Thread Starter derrida

    (@derrida)

    do i need to prefix the files created by poedit with the prefix gutrs- ? cause i have tried to move the files there and it did not worked

    Thread Starter derrida

    (@derrida)

    i tried to chenge the prefix…. then i get an error it loaded too soon? should i use the init hook instead of after_setup_theme?

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    see https://core.trac.www.ads-software.com/ticket/62337 for some possible workarounds or wait for 6.7.1

    Mayuri

    (@mayuripatel)

    Hello @derrida

    The init hook is a safer choice when you’re dealing with translations in WordPress, especially after version 6.7.

    Here’s a modified approach using the init hook, which ensures that WordPress has been fully initialized before attempting to load translations:

    function my_theme_setup() {
    load_theme_textdomain('gutrs', WP_LANG_DIR . '/themes');
    }
    add_action('init', 'my_theme_setup');

    If you want to support both local (theme’s own languages folder) and centralized translations (wp-content/languages/themes/), you could combine both methods in the init hook like this:

    function my_theme_setup() {
    // First, try loading translations from the theme's local languages folder
    load_theme_textdomain('gutrs', get_template_directory() . '/languages');

    // Then, fallback to the centralized languages folder
    load_theme_textdomain('gutrs', WP_LANG_DIR . '/themes');
    }
    add_action('init', 'my_theme_setup');
    • This reply was modified 1 week ago by Mayuri.
    Thread Starter derrida

    (@derrida)

    thanks so much. it does work, even though i still get the notice that Translation loading for the <code>gutrs</code> domain was triggered too early. but everything work and display the translation. hopefully this notice will be fixed somehow.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.