• Resolved sameh.serag

    (@samehserag)


    I downloaded the plugin and installed it. I developed a plugin and it is multi-language.

    i added a
    Text Domain: wp_klido
    and it is appear on you plugin ready to be translated and i choose spanish and the path to save to and i stated translating
    Also i change the website language to Spanish.

    But nothig change on th backend UI … Also i tried to install different plpugins to test it on example “Advanced Custom Field” the same happen no translated text appear

    Thanks in advance

    https://www.ads-software.com/plugins/loco-translate/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Tim W

    (@timwhitlock)

    Did Loco save a MO file at <DomainPath>/wp_kildo-es_ES.mo inside your plugin folder?

    So this is your own plugin? Are you loading the text domain correctly when your admin pages load? Perhaps you could provide a download link to your source code. Otherwise I’m guessing.

    Thread Starter sameh.serag

    (@samehserag)

    Yes Tim, it’s created
    wp_kildo-es_ES.mo and wp_kildo-es_ES.po under <DomainPath>/languages/

    And i am loading it like that

    // Load translation files
    add_action( ‘plugins_loaded’, ‘wp_kildo_load_plugin_textdomain’ );
    function wp_kildo_load_plugin_textdomain() {
    load_plugin_textdomain( ‘wp_kildo’, false, plugin_dir_url(__FILE__) . ‘/languages’ );
    }

    Thread Starter sameh.serag

    (@samehserag)

    And here is sample of my plugin just to test translation
    https://drive.google.com/file/d/0B0LLr-wdE_T6TlRTUE5MUVlkV0U/view?usp=sharing

    Thanks in advance

    Plugin Author Tim W

    (@timwhitlock)

    All my plugin does is create the files. If they exist then the problem is with how you’re telling WordPress to load them. Loco does not interfere with this process at all.

    The load_plugin_textdomain function takes a relative path. I’ve no idea what your STORE_LOCATOR_PLUGIN_URL contains, but I suspect that’s your problem. You should debug the load_plugin_textdomain function to see why your targeting is incorrect.

    Also I notice from your examples that sometimes you are using an underscore (above) and other times a hyphen (in your code). something to be careful of.

    Thread Starter sameh.serag

    (@samehserag)

    Thanks for your reply

    Sorry it’s a mistake while coping the code to test plugin to simplify the plugin code

    It should be wp-kildo_PLUGIN_URL instead of STORE_LOCATOR_PLUGIN_URL
    It should all hyphen not underscore as in example files.

    Also i tried relative path and absolute path for function “load_plugin_textdomain”

    Thanks in advance

    Plugin Author Tim W

    (@timwhitlock)

    Have you debugged the load_plugin_textdomain and looked at the exact path WordPress is trying to load?

    Thread Starter sameh.serag

    (@samehserag)

    Yes it looked at the correct path

    Plugin Author Tim W

    (@timwhitlock)

    And the path is readable? If so the problem must be in your actual translation calls. Perhaps you are trying to display them before they are loaded. I’m guessing now.

    This question isn’t related related to my plugin now as we’ve established the files exist and are named correctly. I am marking as resolved for this reason.

    If you need general help with localising your plugin please post complete code that can be installed and tested.

    Thread Starter sameh.serag

    (@samehserag)

    I established my plugin without existing of translation files. My plugin is just file called wp-kildo.php contain this code

    <?php
    /*
      Plugin Name: wp kildo
      Description: wp kildo
      Version: 1.0
      Text Domain: wp-kildo
      License: GPL
     */
    
    if (!defined('ABSPATH')) {
        exit; // Exit if accessed directly
    }
    
    define('wp_kildo_PLUGIN_URL', plugin_dir_url(__FILE__));
    define('wp_kildo_PLUGIN_PATH', plugin_dir_path(__FILE__));
    
    //create 'wp-kildo' custom post type
    add_action('init', 'wp_kildo_init');
    function wp_kildo_init() {
        $labels = array(
            'name' => __('Kildo', 'wp-kildo'),
            'singular_name' => __('Kildo', 'wp-kildo'),
            'menu_name' => __(' Kildo', 'wp-kildo'),
            'name_admin_bar' => __('Kildo', 'wp-kildo'),
            'add_new' => __('Add New Kildo', 'wp-kildo'),
            'add_new_item' => __('Add New Kildo', 'wp-kildo'),
            'new_item' => __('New Kildo', 'wp-kildo'),
            'edit_item' => __('Edit Kildo', 'wp-kildo'),
            'view_item' => __('View Kildo', 'wp-kildo'),
            'all_items' => __('Kildo List', 'wp-kildo'),
            'search_items' => __('Search Kildo', 'wp-kildo'),
            'parent_item_colon' => __('Kildo Kildo:', 'wp-kildo'),
            'not_found' => __('No Kildo found.', 'wp-kildo'),
            'not_found_in_trash' => __('No Kildo found in Trash.', 'wp-kildo')
        );
    
        $args = array(
            'labels' => $labels,
            'description' => __('Description.', 'wp-kildo'),
            'public' => true,
            'show_ui' => true,
            'show_in_menu' => true,
            'query_var' => true,
            'rewrite' => array('slug' => 'wp-kildo'),
            'capability_type' => 'post',
            'has_archive' => true,
            'hierarchical' => false,
            'menu_position' => null,
            'menu_icon' => "dashicons-location-alt",
            'supports' => array('thumbnail')
        );
    
        register_post_type('wp-kildo', $args);
    }
    
    // Load translation files if exists
    add_action( 'plugins_loaded', 'wp_kildo_load_plugin_textdomain' );
    function wp_kildo_load_plugin_textdomain() {
        load_plugin_textdomain( 'wp-kildo', false, wp_kildo_PLUGIN_URL );
    }

    After installing the plugin i use your loco plugin to create translation files (Spanish) and i added translation to spanish and save.

    But nothing appeared in spanish for my plugin.

    You can install these code and test as you wish.
    I hope you can find the issue

    Thanks in advance

    Plugin Author Tim W

    (@timwhitlock)

    I don’t think you have properly debugged the function as I suggested, because I can immediately see that wp_kildo_PLUGIN_URL produces a URL, not a path.

    Add the following code to inspect the MO file paths:

    add_action('load_textdomain', 'debug_load_textdomain', 10, 2 );
    function debug_load_textdomain( $domain, $mofile ){
        if( 'wp-kildo' === $domain ){
            echo '<pre>',esc_html($mofile),'</pre>';
        }
    }
    Thread Starter sameh.serag

    (@samehserag)

    Thanks a lot Tim for your help.

    I already did debugging for the path but not with this hook. I tried it relative and absolute (in my hook)

    Now It’s working! i debugged it in your hook and get the right path now

    Thanks again for your help

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Translation to Spainish doesn't work’ is closed to new replies.