[wp-hackers] Trying to add i18n

Otto otto at ottodestruct.com
Tue Oct 23 06:31:10 UTC 2012


Two things:
1. You should use the plugins_loaded hook, not "init", although init
will work fine for many cases.

2. Using plugin_dir_path(__FILE__) is probably wrong.
plugin_dir_path() gets the path to the plugin directory in an absolute
form. The third parameter to that function call is a relative path to
the plugin directory only.

If you examine the codex, it shows this method:
http://codex.wordpress.org/Function_Reference/load_plugin_textdomain

load_plugin_textdomain( 'my-plugin', false, dirname( plugin_basename(
__FILE__ ) ) );

-Otto


On Tue, Oct 23, 2012 at 1:08 AM, Tom Barrett <tcbarrett at gmail.com> wrote:
> I'm trying to add language support to my plugin.
>
> What I have done:
>
> 1. This is how I add my text domain.
>
> add_action( 'init', 'tcb_wpg_localisation' );
> function tcb_wpg_localisation() {
>   load_plugin_textdomain( 'wp-glossary', false, plugin_dir_path(__FILE__) .
> '/lang/' );
> }
>
> 2. I used the wp.org 'Generate POT file' to create a .pot file - and put it
> in /lang/
>
> 3. Installed http://wordpress.org/extend/plugins/codestyling-localization/ to
> test and create .po and .mo files - translating 2 of the items.
>
> 4. Editing wp-config.php to change my language.
>
> The problem:
>
> I'm not seeing the translated text. Here are two code snippets:
> 1. the_content filter: $content .= '<div class="glossary-references"><h4>'
> . __('Reference:', 'wp-glossary') . ' ' . $title . '</h4></div>';
> 2. CPT slug: 'rewrite' => array('slug' => __('glossary', 'wp-glossary')),
>
>
> What have I missed?
>
> --
> http://www.tcbarrett.com | http://gplus.to/tcbarrett |
> http://twitter.com/tcbarrett
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers


More information about the wp-hackers mailing list