Translation Localization (Syahir ?)

  • Anonymous

    #3981

    I have the function to translate the admin page in my plugin, and it’s working well. Now, if I want to include strings from a separate php file, how would I do this.

    Would I add a new function with the same method? Or would I include_once the file from my main file?

    Admin

    Syahir Hakim

    #26845

    With WordPress, you should be using a custom function to translate strings. WordPress uses gettext to translate strings, so you should too.

    See this Codex page for more info:

    http://codex.wordpress.org/I18n_for_WordPress_Developers

    Anonymous

    #26846

    Right. Here is my function:

    function jwl_ultimate_tinymce() {
    load_plugin_textdomain('jwl-ultimate-tinymce', false, basename( dirname( __FILE__ ) ) . '/languages' );
    }
    add_action( 'init', 'jwl_ultimate_tinymce' );

    And all strings are preceded with _e() or __().

    This function resides in my main.php file, which also renders most all of my admin page, settings, metaboxes, etc. Translations work fine here.

    Now, if I try to use this same method (preceding with _e()) in a different file, say main_different.php, it generates an undefined function error.

    Should I add the same function, but with a different name, to the secondary file (keeping the same text domain)?

    Admin

    Syahir Hakim

    #26847
    Quote:
    Should I add the same function, but with a different name, to the secondary file (keeping the same text domain)?

    Nope. Instead, you should place the function in the plugin’s file that contains the plugin information header. I believe this is the file that has the same name as your plugin’s directory name.

    Or you can also include a separate file that contains that function into the plugin’s primary file. Point is, that function must be executed on every page load when the plugin is active (or where the translatable strings appear). How you achieve that is up to you (though there are certainly best practices, such as the ones I described above).

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

Do NOT follow this link or you will be banned from the site!