How to set locale in ajax requests?

(this kind of issues is part of why my standard recommendation is to not have front end with two languages) The core reason to the problem is that your ajax returns text. AJAX should be treated like API which provide machine level values which the front end translate to human text. When your code is … Read more

How to extract translatable (double underscores and _e) strings?

One way is to use the WordPress i18n tools. I had to checkout WordPress trunk to make it work. On the command line: svn co http://develop.svn.wordpress.org/trunk once you have trunk somewhere, you’ll then want to call the makepot script. Again, on the command line: php /path/to/wordpress/trunk/tools/i18n/makepot.php wp-theme /path/to/your/theme/ After that script has run, the pot … Read more

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 go to Update page and update language packages (loads languages for themes, plugins, etc.)

List of Default Translated Phrases

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 minor updates. … Read more

Set language per post

I couldn’t find an answer so I ended up providing the solution. It wasn’t simple given that I am not an expert with wordpress nor with php but WordPress documentation is great so here is the solution: // Set the post language when loading up the page based on the store meta function ppl_set_post_language() { … Read more

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” yourself: printf( esc_attr( _n( ‘%s item’, ‘%s items’, $count, ‘textdomain’ ) ), number_format_i18n( $count ) );