0

right now I'm building a helper plugin to make it easier for me to do simple tasks, such as registering post types. When doing this, i'd like to use some of wordpress base translations. Wordpress has the string 'Add New', which is translated in to other languages. Now, is it possible for me, to utilise the base translation, or will i have to re-translate 'Add New' for all of my post types?. Does wordpress have a text domain, in the same way plugins do. like __('Add New', 'wordpress'). I tried just adding __('Add New'), but that doesn't work either.

Worst comes to worst, ill just have to retranslate it - just seems silly, if i could rely on normal wordpress-strings.

Thanks!

2

Turns out that wordpress uses context strings for this piece of text: _x('Add New', 'post') and _x('Add New', 'page')

This is because the string 'Add New' is different depending on the following noun in some languages. i.e in Danish: 'Add New Post' => 'Tilføj Nyt Indløg' 'Add New Page' => 'Tilføj Ny Side'.

Notice the added 't' in 'Nyt'.

Might be helpful to others.

0

Omitting the text domain from localization functions such as __ and _e will result in the default textdomain being used. The reason that your strings are not being translated is most likely to be that you're registering the post type before the localization has been initialized. You should always call register_post_type on the init action:

add_action( 'init', 'wpse149257_content_types' );

function wpse149257_content_types() {
    // register_post_type()
}

This way, you ensure that all necessary functionality is loaded before registering your post type.

  • I am infact registering it with the init action, and it still isn't getting the localisation for some reason. Any other ideas? – Malibur Jun 11 '14 at 10:49
  • Is the localization working in other places? Is "Add New" translated for the default post types, such as post? – engelen Jun 11 '14 at 10:59
  • 1
    Yes it is. Turns out that wordpress uses context for this string. i.e. _x('Add New', 'post') and _x('Add New', 'page') because the word 'new' is different depending on the following noun - ind other languages then english. – Malibur Jun 11 '14 at 11:16

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.