Forum Replies Created

Viewing 13 replies - 1 through 13 (of 13 total)
  • Thread Starter learnee

    (@learnee)

    Tim W, thank you very much for your patience and work.
    For me personally, the solution for now – is to add the find_textdomains_from_files function to my scripts.
    I hope the WordPress developers will also want to look into the situation

    Thread Starter learnee

    (@learnee)

    Good day. Unfortunately, I continue to see a problem on the my test site.

    The plugin sees the language translation file for my plugin (Eagle Booking). But it does not see the theme translation (X Blog).

    I updated to version 2.6.14 – it does not help.

    The test site is pure WordPress. Only two plugins are installed: Loco Translate, Eagle Booking. Only one theme is installed: X Blog

    Is this a problem only for me?

    Thread Starter learnee

    (@learnee)

    A working ‘crutch’ that restores the plugin to work.
    Add this code to the end of the /wp-content/plugins/loco-translate/loco.php file
    By changing if(true) to if(false) (at the beginning of the code) – it is easy to enable/disable the script

    if(true) add_action('init', function()
    {
    // Paths for language files
    $plugin_custom_path = WP_CONTENT_DIR . '/languages/loco/plugins/';
    $theme_custom_path = WP_CONTENT_DIR . '/languages/loco/themes/';

    // Array for storing found domains
    $textdomains = [];

    // Function for searching and adding domains based on .mo files
    function find_textdomains_from_files($directory, $locale, &$textdomains)
    {
    // Open the directory and look for all .mo files
    $mo_files = glob($directory . '*.mo');

    // If files are found
    if ($mo_files) {
    foreach ($mo_files as $file) {
    // Checking if the file exists
    if (file_exists($file))
    {
    // Get the file name without extension
    $domain_with_locale = basename($file, '.mo');

    $domain_parts = explode('-', $domain_with_locale); // We split the domain by the '-' symbol

    // If there is a locale at the end, remove the last element of the array
    if (count($domain_parts) > 1 && end($domain_parts) === $locale) {
    array_pop($domain_parts); // Remove the last element (locale)
    }

    // We assemble the domain back from the array
    $domain = implode('-', $domain_parts);

    // Add the domain to the array if it doesn't exist yet
    if (!in_array($domain, $textdomains)) {
    $textdomains[] = $domain;
    }
    }
    }
    }
    }
    $locale = determine_locale(); // Determining the current locale
    //error_log("locale: ".$locale);

    // Trying to find text domains for plugins and themes
    find_textdomains_from_files($plugin_custom_path, $locale, $textdomains);
    find_textdomains_from_files($theme_custom_path, $locale, $textdomains);

    if (!empty($textdomains)) {
    // error_log("Found text domains: " . implode(', ', $textdomains));
    } else {
    //error_log("No text domains registered.");
    return;
    }

    // We go through all registered text domains
    foreach ($textdomains as $domain)
    {
    //error_log("domain: ".$domain);

    // Skipping already loaded domains
    if (is_textdomain_loaded($domain)) {
    //error_log("Text domain '{$domain}' already loaded.");
    continue;
    }

    // Path to translation file for plugins
    $mo_plugin_file = $plugin_custom_path . $domain . '-' . $locale . '.mo';

    if (file_exists($mo_plugin_file)) {
    //error_log("Loading plugin translation for domain '{$domain}' from {$mo_plugin_file}");
    load_textdomain($domain, $mo_plugin_file);
    } else {
    //error_log("No translation file found for plugin domain '{$domain}' at {$mo_plugin_file}");
    }

    // Path to translation file for themes
    $mo_theme_file = $theme_custom_path . $domain . '-' . $locale . '.mo';

    if (file_exists($mo_theme_file)) {
    //error_log("Loading theme translation for domain '{$domain}' from {$mo_theme_file}");
    load_textdomain($domain, $mo_theme_file);
    } else {
    //error_log("No translation file found for theme domain '{$domain}' at {$mo_theme_file}");
    }
    }
    });
    • This reply was modified 1 week, 4 days ago by learnee.
    Thread Starter learnee

    (@learnee)

    Testing on the Eagle Booking plugin.
    I create a new language for it (Ru).
    I edit the text I need.
    If I move (inside the Loco plugin) the language file to the system or author’s – then the translation is pulled. If to the individual (languages/loco/plugins/) – then no.

    • This reply was modified 1 week, 4 days ago by learnee.
    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

    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 1 week, 4 days ago by learnee.
    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);
    }
    });
    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)

    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 1 week, 4 days ago by learnee.
    Thread Starter learnee

    (@learnee)

    Installing Loco Translate plugins 2.6.12-dev does not help

    • This reply was modified 1 week, 5 days ago by learnee.
    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 1 week, 5 days ago by learnee.
    • This reply was modified 1 week, 5 days ago by learnee.
    • This reply was modified 1 week, 5 days ago by learnee.
    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.

    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.

    #!/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 13 replies - 1 through 13 (of 13 total)