56 votes

How to create .pot files with POedit?

I found the easiest way now is to use the WP-CLI. Navigate to your theme or plugin and execute the following command (after WP-CLI is installed): wp i18n make-pot . languages/my.pot (See ...
lhermann's user avatar
  • 683
17 votes

Different Language for Frontend vs Backend

Since WordPress version 4.7, different Backend users can set their own preferred admin language using the native WordPress language selector. This way, they see the WordPress interface in their ...
serge's user avatar
  • 273
16 votes
Accepted

Is it ok to use a function to output the text domain name in a wordpress theme

No, this is not okay. NO NO NO. Here's my favourite Otto quote: Inside all translation functions, no PHP variables are allowed in the strings, for any reason, ever. Otto explains this in more ...
cjbj's user avatar
  • 14.5k
12 votes

generating po mo translating files from scratch in a wordpress theme

Install wp-cli on your development machine. Run wp i18n make-pot . languages/my-theme.pot in your plugin/theme folder (wp-cli i18n) Choose a unique identifier, I chose my-theme as an example, wrap ...
Lucas Bustamante's user avatar
10 votes

Different Language for Frontend vs Backend

In the WordPress 5.x it real simple to get a different frond and back end language To change the site language go to Setting -> General -> Site Language and select the site language. For the Admin ...
Mike van Eckendonk's user avatar
9 votes
Accepted

Is a text-domain necessary for a child theme

TL;DR: If you use strings that are in the parent theme, exaclty how they are used in parent theme, you don't need to have a text domain for your child theme. But if you use strings that aren't used in ...
gmazzap's user avatar
  • 46.1k
8 votes
Accepted

Why can I not use a class constant as text domain?

The value of a constant or variable can be evaluated by a PHP parser only. The tool that is used to extract the translatable strings is written in PHP, but is just a string parser. It doesn't run your ...
fuxia's user avatar
  • 107k
8 votes
Accepted

How to print translation supported text with HTML URL

Since esc_html_e will escape HTML link (hence will show the HTML anchor as plain text), you'll need to segment the text and escape the non-HTML part with esc_html_e or esc_html__, and print the HTML ...
Fayaz's user avatar
  • 8,909
8 votes

Overriding single plugin translation

Here's an example where a string from a certain text domain is translated using the gettext filter: /** * Translate a certain string from a particular text domain. * * @param string $translation ...
Dave Romsey's user avatar
  • 17.7k
7 votes
Accepted

How to escape the single quote character in i18n translation strings?

Use the first option. translated strings are supposed to be "raw", and escaped only by the calling function. In addition many will not understand what ' mean and how to translate it without ...
Mark Kaplun's user avatar
  • 23.4k
6 votes
Accepted

Can't set proper WooCommerce language translation

After installing WordPress version 4.6.1 and WooCommerce version 2.6.6, both with the default enabled language, English (United States), I followed the steps below and had the translation successfully ...
nyedidikeke's user avatar
6 votes
Accepted

How does gettext works for translating readme file of plugin?

Translations for readmes on .org are done through https://translate.wordpress.org. You could contribute translations for your own plugin if you wanted. Start by picking a locale/language you want to ...
Jacob Peattie's user avatar
6 votes

Using polylang, how can I see which post is the "original" and which are the "translated children"?

Thanks to mmm, basing on his answer I found in Polylang API (v.2.3.7) a function pll_get_post_translations( $post_id ) that do the same. This function obtains an array with language as key and ID of ...
Golka's user avatar
  • 61
6 votes
Accepted

Unknown language json files

what are these language files for? (I guess it is for localizing javascript?) You guessed right. The JSONs are for use specifically with the new wp_set_script_translations function in WordPress 5. ...
Tim's user avatar
  • 662
5 votes
Accepted

Make a custom theme translate-ready

To do it properly, you need to generate a valid .mo file and load the text domain in your theme functions.php: function wpse222346_localize_theme() { load_theme_textdomain( 'your_theme_domain', ...
Luis Sanz's user avatar
  • 756
5 votes
Accepted

How to translate a string that contains a WordPress sitename

You can use sprintf: echo sprintf( __('Follow %s on Facebook', 'yanse'), get_bloginfo('name') );
wpclevel's user avatar
  • 3,419
5 votes
Accepted

How to escape single and plural i18n text strings?

esc_html_e() and esc_attr_e() are merely wrapper functions for _ to save a little bit of typing and help with readability. You're right, there isn't one for _n, so you'll just need to do the "wrapping"...
TheDeadMedic's user avatar
  • 36.4k
5 votes
Accepted

Override plugin text domain in child theme

If you want to override a plugin text domain, create (if not exist) a folder named languages and another one plugins (in languages) in the wp-content folder. This folders is intended, with the ...
Benoti's user avatar
  • 2,426
5 votes
Accepted

Translating an error message

The gettext filter can be used to change strings that use the gettext functions. add_filter( 'gettext', 'wpse_change_error_string', 10, 3 ); /** * Translate text. * * @param string $translation ...
Dave Romsey's user avatar
  • 17.7k
5 votes

Changing the language of a single page

The locale filter that allows you to set the locale specifically. You can check the current page, and alter the value based on that. add_filter('locale', 'change_my_locale'); function ...
Johansson's user avatar
  • 15.3k
4 votes

How to make a WordPress plugin translation ready?

Nabil’s answer is fairly complete but there is an easy variation provided: Your plugin is on the WordPress.org plugin repository You’re willing to require that your plugin only work with WordPress 4....
thespacecamel's user avatar
4 votes

Different Language for Frontend vs Backend

If anyone is still looking for that, here is what you should do since version 4.7 function wp_noshor_redefine_locale($locale) { if( is_admin() ): switch_to_locale('en_US'); endif; } ...
Motaz M. El Shazly's user avatar
4 votes

Change the text on the Publish button

For consistency, I'm assuming you'd prefer to use "Save" instead of "Publish" throughout Wordpress instead of just on the text of the button. Based on the solution provided by @Rarst, I expanded the ...
rinogo's user avatar
  • 1,441
4 votes

__(): What if I have to pass in a variable?

To translate a string in WordPress, as in most CMSs that use PHP, you have to wrap the string in a GetText translation function (i.e. __ (), _e (), _n (), _x () ... etc). The string has also to be ...
Juan Guerrero's user avatar
4 votes

Override default WordPress core translation

I was about to use the "add_filter( 'gettext'..." solution suggested above but then read at https://developer.wordpress.org/reference/hooks/gettext/ that this solution can have quite a ...
GoldyOnline's user avatar
4 votes

Changing the language of a single page

You should use locale hook to solve your task. Important note that you can't add it in theme and use is_page function, because it will define later. So you have to create plugin or must use plugin ...
Anton Lukin's user avatar
4 votes
Accepted

use __($str) to translate strings (symfony/twig)

I have my own implementation of twig in WordPress as plugin and my translations are working. You can check my code. Keep in mind couple of things when when you will test the code: be sure that your ...
kierzniak's user avatar
  • 2,432
4 votes
Accepted

WordPress i18n in Array throws Error

This is a PHP issue, not specific to WordPress. PHP does not allow you to declare a property as an expression. It should be a literal. So you can not call a function inside a property declararion. (...
Leo Germani's user avatar
4 votes
Accepted

load_plugin_textdomain in `plugins_loaded` or `init`?

Load translation files as late as possible for your plugin's use-case. This allows other plugins as much time as possible to fully initialise. Why should you care about other plugins? Because they ...
Tim's user avatar
  • 662
3 votes
Accepted

How to add extra language packs to WordPress

The easiest way for me is to change language settings for main blog multiple times (as mach as many languages I need) and WordPress will load these languages automatically. And after that I ...
Andrew's user avatar
  • 121

Only top scored, non community-wiki answers of a minimum length are eligible