• Resolved learnee

    (@learnee)


    Here is a quick solution to the problem with the location of language files with translation in WordPress 6.7 – which I myself have successfully used:
    A ready-made bash script that automatically moves the language files on the whole server from the plugin folder, to the system folders.

    As a result, you don’t need to do anything else on the sites themselves (even if there are a lot of them)? ??
    Place in the root of the server (or user directory) and run.

    All processes are logged.

    P.S. Or just move your files manually: from ‘/wp-content/languages/loco/plugins/’ to ‘/wp-content/languages/plugins/’, and from ‘/wp-content/languages/loco/themes/’ to ‘/wp-content/languages/themes/’

    #!/bin/bash

    # Set the log file to the current directory
    LOG="$(pwd)/logfile.log"

    # Function for logging
    log_message() {
    echo "$(date +'%Y-%m-%d %H:%M:%S') - $1" >> "$LOG"
    }

    # Recursive directory traversal
    find . -type d -path "*/wp-content/languages/loco/plugins" | while read -r dir; do
    # Move files from /wp-content/languages/loco/plugins/ to /wp-content/languages/plugins/
    target_dir="$(echo "$dir" | sed 's|wp-content/languages/loco/plugins|wp-content/languages/plugins|')"
    mkdir -p "$target_dir"
    mv "$dir"/* "$target_dir"
    log_message "Moved files from $dir to $target_dir"
    done

    find . -type d -path "*/wp-content/languages/loco/themes" | while read -r dir; do
    # Move files from /wp-content/languages/loco/themes/ to /wp-content/languages/themes/
    target_dir="$(echo "$dir" | sed 's|wp-content/languages/loco/themes|wp-content/languages/themes|')"
    mkdir -p "$target_dir"
    mv "$dir"/* "$target_dir"
    log_message "Moved files from $dir to $target_dir"
    done

    echo "Script completed."
Viewing 15 replies - 1 through 15 (of 24 total)
  • Plugin Author Tim W

    (@timwhitlock)

    Sorry, but this isn’t a solution. Files in this location are not safe from updates.

    The recommended approach has always been to keep the system file installed AND create custom files from them. This actually hasn’t broken after WordPress 6.7.

    The latest development version fixes this and allows the custom file to be loaded without the system file, but NOT if there’s some other problem such as a theme or plugin requesting translations too early.

    Thread Starter learnee

    (@learnee)

    In my particular case – the language I need is not supported by the author of the plugin and theme. Therefore, for a quick solution – this was the way out for me.

    Ideally, of course, you need to store language files not in the system directory.

    he latest version of the plugin 2.6.12-dev – I tried, but it did not help.

    Plugin Author Tim W

    (@timwhitlock)

    The latest version of the plugin 2.6.12-dev – I tried, but it did not help.

    We need to find out why. I have an inbox full of people telling me the same thing, but the fix works for me in isolated tests. Other plugins and themes will be affected by this, so we need to attribute the fault to where it lies.

    Can you please post an example string from a publicly available plugin or theme that fails to load from the custom file location?

    Thread Starter learnee

    (@learnee)

    Yes. There is a problem and it is easy to reproduce.

    My steps:

    • installed a clean WordPress 6.7 RU (PHP 7.4)
    • deleted all default plugins
    • installed Loco Translate plugins 2.6.11
    • deleted all default themes
    • installed a free X Blog theme 1.3.27
    • added a new language (ru) to the theme and translated the “More button”

    If you save the language file to the loco plugin folder, it doesn’t see the translation.

    If to the system folder, it does

    • This reply was modified 3 months, 2 weeks ago by learnee.
    • This reply was modified 3 months, 2 weeks ago by learnee.
    • This reply was modified 3 months, 2 weeks ago by learnee.
    Thread Starter learnee

    (@learnee)

    Installing Loco Translate plugins 2.6.12-dev does not help

    • This reply was modified 3 months, 2 weeks ago by learnee.

    Thank you very much @learnee, it perfectly works.

    While I know this is just a temporary solution (I’ve just left a copy of the files in the original folder) it helps while an official solution can be found. ??

    Plugin Author Tim W

    (@timwhitlock)

    Yes. There is a problem and it is easy to reproduce.

    I’m able to reproduce this. Thanks.

    The custom file is being loaded, but for reasons I don’t yet understand the absence of the original (system) file is unsetting it. I’ll continue working on this tomorrow.

    Thread Starter learnee

    (@learnee)

    Here’s what the neural network got wise: https://chatgpt.com/share/67370e51-7a4c-8000-a312-57bc0d483198

    In WordPress 6.6 and 6.7, significant changes were introduced that could affect how language files are loaded. In particular:

    • Updates to the theme.json file processing.
    • API changes for templates and localization mechanisms.

    These updates may have made WordPress strictly adhere to the standard /wp-content/languages/plugins/ path for plugins and themes, excluding custom directories like /wp-content/languages/loco/plugins/. This could be due to a simplification of file-loading mechanisms or security enhancements to prevent the accidental use of unsupported directories.

    A possible solution could be this (haven’t tried it yet): Add the following code to your theme’s functions.php file:

    add_filter('loco_load_textdomain_override', function ($locale, $domain, $path) {
    $custom_path = WP_CONTENT_DIR . '/languages/loco/plugins/';
    if (file_exists($custom_path . $domain . '-' . $locale . '.mo')) {
    load_textdomain($domain, $custom_path . $domain . '-' . $locale . '.mo');
    return true;
    }
    return false;
    }, 10, 3);
    • This reply was modified 3 months, 2 weeks ago by learnee.
    Plugin Author Tim W

    (@timwhitlock)

    No disrespect to you or ChatGPT, but this issue is more complex than a simple override. It involves numerous filters, and merging of multiple files in the correct order. I’ve grappled with these issues for years, and the matter will be fixed. Hopefully today.

    Thread Starter learnee

    (@learnee)

    I will be waiting for your decision with interest. And if I can help test it, I will be glad. Good luck.

    Thread Starter learnee

    (@learnee)

    A working solution at the theme settings level via a functions.php file without moving language files from /wp-content/languages/loco/:

    add_action('after_setup_theme', function () {
    $domain = 'x-blog'; // Specify the text domain. My option is indicated for the X Blog themes
    $locale = determine_locale(); // Determine the current locale

    // Main path for plugin language files
    $plugin_custom_path = WP_CONTENT_DIR . '/languages/loco/plugins/';
    $theme_custom_path = WP_CONTENT_DIR . '/languages/loco/themes/';

    // Load files from the custom plugin directory
    $mo_plugin_file = $plugin_custom_path . $domain . '-' . $locale . '.mo';
    $po_plugin_file = $plugin_custom_path . $domain . '-' . $locale . '.po';

    if (file_exists($mo_plugin_file)) {
    load_textdomain($domain, $mo_plugin_file);
    } elseif (file_exists($po_plugin_file)) {
    load_textdomain($domain, $po_plugin_file);
    }

    // Load files from the custom theme directory
    $mo_theme_file = $theme_custom_path . $domain . '-' . $locale . '.mo';
    $po_theme_file = $theme_custom_path . $domain . '-' . $locale . '.po';

    if (file_exists($mo_theme_file)) {
    load_textdomain($domain, $mo_theme_file);
    } elseif (file_exists($po_theme_file)) {
    load_textdomain($domain, $po_theme_file);
    }
    });
    Plugin Author Tim W

    (@timwhitlock)

    @learnee I’ve updated the dev version with another fix. Please try it.

    Using your test case of X Blog Free, and the text “Continue Reading”, I’ve verified this update works for me when having ONLY a custom translation file installed.

    Thread Starter learnee

    (@learnee)

    Yes. The problem was solved in the theme. But not in the plugin.

    https://localise.biz/wordpress/plugin/developers

    P.S. And the version number of the plugin has not changed (it’s not important)

    • This reply was modified 3 months, 2 weeks ago by learnee.
    Plugin Author Tim W

    (@timwhitlock)

    The problem was solved in the theme. But not in the plugin.

    the plugin may be suffering an unrelated issue then. Please post details as you did for the theme. Thanks.

    And the version number of the plugin has not changed

    It won’t change until it goes live. This is the trunk for continuous development. If WordPress could install release candidates etc.. I would number them, but it can’t. The SVN revision will tell you if it’s updated.

    Thread Starter learnee

    (@learnee)

    Just installed your plugin.

    Tried moving the language file to system, author and individual inside the plugin – works. Deactivating the plugin disables translation – which is logical and confirms functionality.


    The theme is being translated. Unfortunately, plugins are not translated

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