Articles of xgettext

Translate a child theme with pure PHP and gettext

I’m trying to translate a child theme of a parent theme that has all msgstr empty. Therefore, I’ve created the file de_DE.mo using the “WordPress i18n tools” recommended in the docs together with msgfmt. I put the file into my child theme directory’s subfolder languages/child. To tell WordPress about it, I added this to my […]

Localization of WP theme

I am working on WP theme localization. On custom search template I have function which gets text of some search terms and replace them with other (just visually). function search_replace_search() { $search_term = esc_attr( apply_filters( ‘the_search_query’, get_search_query( false ) ) ); // Get search term $search = array(‘word1’, ‘word2’ ); $replace = array(‘something 1’, ‘something […]

How does translation (gettext) work for translating config file of plugin?

I am doing translation of my plugin. I am using __ & _e in php files. But can’t figure out how to do same for config file that contains constants added using define(name, value)? Does it automatically get translated using WordPress translation dictionary once plugin adds code for loading text-domain? Also, Do I need to […]

How to ignore extra whitespaces in translation functions like _e?

I am passing few big strings in my code for translation to _e(). These strings were earlier broken into multiple lines with few leading white spaces before every line to maintain indentation & readability. And since HTML ignore extra white spaces, it doesn’t affect anything. But now, on passing these strings through _e(), these white […]

Can I set WordPress to display languages based on system language without a plugin?

This question seems extremely straightforward, but hours of googling have led to no results. Here’s the basic gist: I am building a site for Japanese viewers, and am using the theme’s language folder to replace certain text (e.g. “Read More” and “Older Entries”) with Japanese text. It works just fine when I set the WP […]

Can't we use strings defined as PHP constants if we want to translate them in a plugin?

I want to translate constant strings in my plugin defined as: define( ‘CONSTANT’, __( ‘string-A’, ‘textdomain’ ) ); And later using it somewhere like: $x= ‘<h4>’.CONSTANT_NAME.'<h4>’; echo $x; But I am still getting English text even after adding that locale’s .mo file & the text-domain. This is happening only for strings defined by PHP constants, […]

How to use gettext for specific user role

I am trying to replace the publish button text to Submit for review only for specific user role. But I can’t find anything which can specify current user role and apply the filter. Here’s my code, it’s not working. add_filter( ‘gettext’, ‘change_publish_button’, 10, 2 ); function change_publish_button( $translation, $text ) { if( !current_user_can(‘administrator’) ) { […]

How to translate “$before” with get text in get_the_term_list?

How can I make $before (Books:) a translateable string <?php echo get_the_term_list( $post->ID, ‘book’, ‘Books: ‘,’, ‘, ‘ ‘, ” ); ?> with this method?: <?php the_content(__(‘Read more…’, “ft”)); ?>

Using wordpress translations strings in plugin

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 […]

How can I see my theme's text domain?

Where can I discover my current theme’s text domain for use with translation (GetText)?