How do translated, escaped strings (esc_attr) in Themes work?

General difference between esc_attr and esc_attr_* The difference between esc_attr() and esc_attr__(), esc_attr_e(), esc_attr_x() is that the later three are just “wrappers” or in other words higher level API functions. When you look at the source of the later three, then you’ll see that those put in a single argument wrapped in a call to … Read more

How to debug failed load_theme_textdomain()?

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(), ‘my_theme’ ); die( “Could not find $path/$locale.mo.” ); }

generating po mo translating files from scratch in a wordpress theme

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 my_theme_setup(){ load_theme_textdomain(‘mytheme’, get_template_directory() . … Read more

How-to: Translate plural forms for themes/plugins with PoEdit

Step 1 Open your file in PoEdit. Step 2 Go to “Catalogue” » “Settings“ Step 3 Fill in “Language” and “Country” 1). Step 4 Fill “Pluralform” (last field). // For 2 plural forms nplurals=2; plural=n != 1; // For 3 plural forms (for e.g. russian), use: nplurals=3; plural=(n%10==1 && n%100!=11) ? 0 : ((n%10>=2 && … Read more

How to get a localized version of WordPress from a repository?

Download your languages files from the SVN repo… I would strongly advise against this. The repo, as storage of language files, is being discontinued, in favor of Translate WordPress. Right now, you have no guarantees that the repo has a current version of the file. The current method of getting language files is either to … Read more

Custom strings for translation using Polylang plugin

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 convenience (ex: ‘myplugin’) ‘$string’ => (required) the … Read more