45

There is a second argument in the __() function. It should be set to the domain you are are using for your plugin or theme. In the examples below I use 'text_domain'. Your domain string should be unique. It should not match any other domain string. Not using a text domain argument defaults to 'default' the WordPress domain name. See the link for more details....


44

If you want to echo the translated string, then you will be using _e and when you just want to have the translated string, then you will be using __. Example: _e('this is a message', 'twentyfourteen'); is same as echo __('this is a message', 'twentyfourteen');


41

1. Write with localization in mind Don't use echo or print() to produce text output, instead use the WordPress functions __() and _e(): /** Not localization friendly */ echo "Welcome to my plugin"; // OR print("Welcome to my plugin"); /** Localization friendly */ _e('Welcome to my plugin', 'my-plugin'); // OR $my_text = __('Welcome to my plugin', 'my-...


39

Here is how you can create a .pot file for your theme with Poedit (free edition, version 1.6.10) on OS X. Best practise is to save language files in a folder named "languages" in your theme directory. If you haven't already, create it before you start. In Poedit: In the "File" menu select "New" Select the language that you used in your theme (probably ...


27

You can do this with the WordPress tools, without POEdit. First, do an svn checkout of http://develop.svn.wordpress.org/trunk/: svn co http://develop.svn.wordpress.org/trunk/ wpdev Then, switch to the i18n tools directory in it: cd wpdev/tools/i18n/ Then just run the makepot.php over your theme's directory: php makepot.php wp-theme /path/to/your/theme ...


25

In this case, 'themify' is the defined textdomain for the Theme, used to make the Theme translatable. (Codex reference: load_theme_textdomain()). Making a Theme translation-ready requires a few steps. Define the Theme's textdomain: load_theme_textdomain( 'themify', TEMPLATEPATH.'/languages' ); Define translatable strings in the template. This is done ...


21

When adding _x to the keywords, try it this way: _x:1,2c This tells the parser to watch out for _x and to take the first argument as msgid and the second argument as a comment, which will then be recognized as context by poEdit and inserted as msgctxt. Oddly enough, my poEdit then shows me the msgid twice in the "new/old" messages window. However, in the ...


20

You may try Eazy Po. From file menu select “New from source code files..”. In xgettext Command Manager window; Press “Browse folder” to select base source folder. In Build pane press “Execute Command” button to generate Pot file.


18

You could use gettext filter: add_filter( 'gettext', 'cyb_filter_gettext', 10, 3 ); function cyb_filter_gettext( $translated, $original, $domain ) { // Use the text string exactly as it is in the translation file if ( $translated == "Categorie: %s" ) { $translated = "Sectie: %s"; } return $translated; } If you need to filter a ...


17

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 documentation of the command) You can then edit this file with Poedit or any other handy translation tool.


14

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 detail, but the simple way to say it is that translation calls are parsed, not executed . So your variable (let alone your function) may not be evaluated and the ...


13

Use this pll_register_string() on functions.php Use it like this: pll_register_string Allows plugins to add their own strings in the “strings translation” panel. The function must be called on admin side (the functions.php file is OK for themes). Usage: pll_register_string($name, $string, $multiline); ‘$name’ => (required) name provided for sorting ...


13

You can do it with printf(). E.g. printf( __( 'We deleted %d spam messages.', 'my-text-domain' ), $count );


12

I just found the answer and instead of putting this in the Title: <!--:en-->My English Title<!--:--><!--:fr-->My French Title<!--:--> We need to put this code: [:en]My English Title[:fr]My French Title and qTranslate does the rest :)


11

load_theme_textdomain() returns TRUE on success and FALSE if no file was found. For debugging try the following change: function my_theme_setup(){ $path = get_template_directory() . '/languages'; $result = load_theme_textdomain('my_theme', $path ); if ( $result ) return; $locale = apply_filters( 'theme_locale', get_locale(), '...


10

I think I found a solution, but before a little Premise load_theme_textdomain() and load_child_theme_textdomain() are basically equal, the only difference is the default path they use: they get the current language (using get_locale()) and add the relative .mo file to the path passed as argument; then they call load_textdomain() passing as argument both the ...


9

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 language and can more easily manage content.


9

Use the fourth parameter for get_post_time(): $time = get_post_time( 'F j, Y', // format TRUE, // GMT get_the_ID(), // Post ID TRUE // translate, use date_i18n() ); get_post_time() calls mysql2date() internally, and it passes the $translate argument through. In mysql2date() we find this: if ( $translate ) ...


8

(Here is an EXAMPLE of translation to DEUTSCH. CHANGE the customs to YOUR DESIRED ones.) in every plugins head, there is an unique name. (for example: /* Plugin Name: my-pluginname ....... */ then, in that plugin's folder, create a folder "languages"; then, into your plugin .php file (somewhere in the top), insert the initialization code: class ...


8

Use date_i18n(): date_i18n( 'Y. F j.', strtotime( get_the_time( "Y-m-d" ) ) ); From the function’s description: Retrieve the date in localized format, based on timestamp. If the locale specifies the locale month and weekday, then the locale will take over the format for the date. If it isn't, then the date format string will be used instead. ...


8

You can use the tool POEdit to translate your theme from scratch or update/add new strings into the .po/.mo files. Here is the tool usage tutorial: Translating_With_Poedit There is a plugin that can do the job for you: codestyling-localization STEPS: 1. Load a text domain for the theme. add_action('after_setup_theme', 'my_theme_setup'); function ...


8

If you don't provide any textdomain, WordPress translated strings are used. If you use, for example, __( 'Add New Tag' );, the translation from WordPress core will be used because 'Add New Tag' exists in WordPress. Your problem is that your are defining labels that don't exist in WordPress core, so they are not included in any WordPress translation files. I ...


8

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 parent theme, to make them translatable, you'll need another text domain with related translation (.mo) files. Translation workflow When WordPress encounter a ...


7

Is it enough to just create a child-theme - let's say technically without adding anything else but the bare minimum style.css - to have the translation of the parent-theme being used automatically for the child-theme as well? Basically, the answer is NO, ... but... there's an option: Add a mu-plugin. This (MU-)Plugin does several things: It hooks into ...


7

quick-and-dirty hint to solve this problem: find the function list_translation_updates() in wp-admin/update-core.php $updates = wp_get_translation_updates(); if ( ! $updates ) <- locate the if ... } else { <- add this print_r ( $updates ); } add the else-case and save the file reload the dashboard page ...


7

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 code, because that would be too slow and error prone. Here is an example for how complex that could be: interface FooTranslate { const TEXT_DOMAIN = 'foo'...


7

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 &apos; mean and how to translate it without looking at the actual page which can be annoying.


7

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 LINK part without HTML escaping. Method-1 (just for your understanding): You may do it in parts, like this: esc_html_e( 'Dear Guest, with Your information we ...


6

The list is available in $GLOBALS['l10n'][ $text_domain ]. To get the looong list of translatable WordPress strings just use: print '<pre>' . htmlspecialchars( print_r( $GLOBALS['l10n']['default'], TRUE ) ) . '</pre>'; Do not use these strings in your theme or plugin. They are internal, de facto private. They can change any time, even in ...


6

You can use plugins for that: http://wordpress.org/extend/plugins/kau-boys-backend-localization/ or http://wordpress.org/extend/plugins/wp-native-dashboard/


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