0

I am working on a Plugin for Wordpress and I'm not able to get the Internationalization working.

Here is the GitHub Link: https://github.com/dev-nm/WP-StudioLink-Integration

I used wppb.me as a Boilerplate and titan framework as a Admin Panel Framework. I created the pot, po and mo with poedit + Loco Translate (Cause I only have the free versio of poedit).

The following is happening: In the Plugins Menue the translated short description is shown. In my own Menue none of the Strings is translated.

Structure for Translation is the following:

  • studio-link-integration.php => new Studio_Link_Integration ( /includes/class-studio-link-integration.php )
  • __contruct => set_locale();

    private function set_locale() {
    
    $plugin_i18n = new Studio_Link_Integration_i18n();
    $plugin_i18n->set_domain( 'studio-link-integration' );
    
    $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
    
    }
    
  • in class Studio_Link_Integration_i18n

    public function load_plugin_textdomain() {
    
    load_plugin_textdomain(
        $this->domain,
        false,
        dirname( plugin_basename( __FILE__ ) ) . '/languages'
    );
    
    }
    

Language Files are in /languages/ and are named studio-link-integration-de_DE.

translation is done with __( 'Text to Translate', 'studio-link-integration' ).

I really dont know, why it wont work. Can someone look at my Files and help me? Am I forgetting some new specifications for translating? I read the whole Codex about Localization and Internationalisation but havent found anything new out that helped me.

Thanks :)

  • Please give an example of an actual string that doesn't work. Your German file contains a lot of translations in English including your main menu items. – Tim Jan 28 at 9:52
  • Well, none of the Strings works. The only Text that apperas in German is the short description, but it gets loaded in another way I guess, cause it is translated even before activationg the Plugin. EDIT: I just read the Translation File. The short description is not translated there. – Nicolas Mierbach Jan 28 at 9:55
  • EDIT: Nevermind the EDIT of the Commentabove. I just fergot to update the Files in the GitHub. Just uploaded it now – Nicolas Mierbach Jan 28 at 10:04
  • These Translations work: LINK – Nicolas Mierbach Jan 28 at 10:11
0

Your error is here

The path to your bundled translations resolve to a languages folder inside the includes folder, which is one level down from where it actually is.

Try it with an extra dirname and you will target it correctly:

dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'

Or to be a bit tidier:

plugin_basename( __DIR__.'/../languages' )
  • Tanks a lot! But now i see there is another Problem: the Titan Framework, I included into the Plugin does not load its localization. Do you have an Idea how to include it without editing the Source of the Framework? – Nicolas Mierbach Jan 28 at 15:15
  • It is located in admin/titan-framework/languages – Nicolas Mierbach Jan 28 at 15:16
  • You can filter on this. See WP docs for load_textdomain_mofile – Tim Jan 28 at 15:33
  • I'm curious why you unaccepted my answer after fixing the bug. – Tim Feb 11 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.