• Resolved realfufu

    (@realfufu)


    Hi Community

    I’m developing an extension for WordPress and WooCommerce.
    The extension is working very fine, only the localization is not working.

    I included in the header of my main pluginfile this lines:

     * Text Domain: myextension
     * Domain Path: /i18n/languages/

    In my code I used the __ and _e functions like this:
    __( 'Example string', 'myextension' )

    And I moved my .po and .mo files in ‘myextension/i18n/languages/’.
    My .po files look like this:
    ‘myextension-de_DE.po’:

    msgid ""
    msgstr ""
    "Project-Id-Version: My Extension 1.0\n"
    "POT-Creation-Date: 2016-09-07 11:08+0200\n"
    "PO-Revision-Date: 2016-09-07 11:51+0200\n"
    "Language-Team: Me <x@x.x\n"
    "MIME-Version: 1.0\n"
    "Content-Type: text/plain; charset=UTF-8\n"
    "Content-Transfer-Encoding: 8bit\n"
    "X-Generator: Poedit 1.8.9\n"
    "X-Poedit-Basepath: ..\n"
    "Plural-Forms: nplurals=2; plural=(n != 1);\n"
    "X-Poedit-KeywordsList: __;_e\n"
    "Last-Translator: \n"
    "Language: de\n"
    "X-Poedit-SearchPath-0: .\n"
    "X-Poedit-SearchPath-1: classes\n"
    "X-Poedit-SearchPath-2: functions\n"
    "X-Poedit-SearchPathExcluded-0: i18n\n"
    
    #: classes/Example.php:128
    msgid "Example string"
    msgstr "Beispiel String"
    
    ...... cutted

    But, if I change the language in Settings>general to German, everything is translated except everything from my plugin.

    So, where did I failed?

    I also tried to delete and reinstall my plugin. Also I tried to switch the language a few times.

    FuFu

Viewing 1 replies (of 1 total)
  • Thread Starter realfufu

    (@realfufu)

    Ok I figured it out.

    I had to add this:

    function myextension_i18n() {
    
    	// get the directory containing the .mo file, relative to the plugin directory
    	$i18n_dir = plugin_basename( GRDS_IP_DIR . '/i18n/languages' );
    
    	// For WordPress 2.6 and up, the directory must end with a trailing slash
    	if ( substr( $i18n_dir, -1 ) != '/' ) {
    		$i18n_dir .= '/';
    	}
    
    	// Load translation files
    	if( load_plugin_textdomain( 'myextension', false, $i18n_dir ) ){
    		return true;
    	} 
    	return false;
    
    }
    add_action('plugins_loaded', 'myextension_i18n');

    Source: https://codex.wordpress.org/I18n_for_WordPress_Developers

    Have a nice day

    FuFu

Viewing 1 replies (of 1 total)

The topic ‘Localization not working’ is closed to new replies.