[wp-hackers] Plugins using post types with localization

Diana K. Cury dianakac at gmail.com
Mon Jul 4 16:43:18 UTC 2011


Thanks Heiko, (thanks also for Codestyling plugin, I love that!)

I tried the a) load the translation directly in front of constructor 
executions, and didn't work. Again, translation only in some parts. About 
b), not sure how that should be, but I wil try.

Also, I tried to use differente events from init for post types, with no 
sucess. Translation always work, but only for some parts :(

Maybe is better to merge the post type files into a single file?


----- Original Message ----- 
From: "Heiko Rabe" <heiko.rabe at code-styling.de>
To: <wp-hackers at lists.automattic.com>
Sent: Monday, July 04, 2011 2:41 AM
Subject: Re: [wp-hackers] Plugins using post types with localization


function PETPostType() {
$this->labels = array(
'name' => __('Pets','ADA'),
'singular_name' => _x('Pet', 'post type singular name',
'ADA'),
'add_new' => __('Add Pet','ADA'),
'add_new_item' => __('Add Pet','ADA'),
'edit_item' => __('Edit Pet','ADA'),
'new_item' => __('New Pet','ADA'),
'view_item' => __('View Pets','ADA'),
'search_items' => __('Search Pets','ADA'),
'not_found' =>  __('Not Found!','ADA'),
'not_found_in_trash' => __('Nothing found in Trash','ADA'),
'parent_item_colon' => ''
);


add_action( 'init', 'adafunc_setup' );

function adafunc_setup(){
load_plugin_textdomain('ADA', null, dirname( plugin_basename( __FILE__ ) ) .
'/lang' );
}

You are loading your translation at the init hook processing but your
constructor for PETPostType executes before loading your translation file
inside the plugin class constructor. So any translation stands at english
while translation is missing.

You have 2 options:
a) load your translation directly in front of your constructor
executions. (not recommended)
b) hook into init hook execution, load the textdomain and 2nd define
now the posttype objects.

regards

-----Ursprüngliche Nachricht-----
Von: wp-hackers-bounces at lists.automattic.com
[mailto:wp-hackers-bounces at lists.automattic.com] Im Auftrag von Diana K.
Cury
Gesendet: Montag, 4. Juli 2011 07:22
An: wp-hackers at lists.automattic.com
Betreff: Re: [wp-hackers] Plugins using post types with localization

Tried the priority and still no changes. Also, the metabox script never get
translated, I think some problem there.

I tried to move the
    $PETPostType = new PETPostType();
    $LOSTPostType = new LOSTPostType();
For their "respective" file, but no luck.

Pasted in pastebin http://pastebin.com/Zwj0akPX



----- Original Message ----- 
From: "Dion Hulse (dd32)" <wordpress at dd32.id.au>
To: <wp-hackers at lists.automattic.com>
Sent: Monday, July 04, 2011 2:10 AM
Subject: Re: [wp-hackers] Plugins using post types with localization


> On 4 July 2011 14:58, Diana K. Cury <dianakac at gmail.com> wrote:
>
>> Thanks Hulse, I don't undertand too much about all this, quite adapted
>> the
>> plugin from many sources.
>>
>> I think your note on priority can be helpful (no tested yet).
>> I don't understand how register post is being loaded before anything or
>> the
>> post types are always handled firstly, by default !?
>>
>>
> My apologies, It looks like i've misread the code, It's hard skimming code
> where indentation isn't consistent.
> The post type isn't being registered before init, it's being registered on
> init.
>
> However, The post type structure,
>
http://plugins.trac.wordpress.org/browser/ada-plugin/trunk/creation/pet_post
_type.php?rev=404248#L14IS
> being run on plugin inclusion basically.. It's creating the $labels
> array
> before the language files are loaded, so __(something, 'ADA') is returning
> 'something' since at that point in time, the translations functions havn't
> been loaded..
>
> So;
> * PETPostType() is run at plugin inclusion time, this sets the labels and
> attemptt to translate them (and fails);
> * Then on init, adafunc_setup() is called loading the translations.
> * And then, on init again, PETPostType::register() is called, registering
> the post type, with the previously "untranslated" strings from step 1.
>
> That combined with the priorities, should be able to get you on the right
> line.. Make sense?
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

_______________________________________________
wp-hackers mailing list
wp-hackers at lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers

_______________________________________________
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