Change language by clicking a button

By far the best (easiest) way is to use the locale filter (inside get_locale()). First set up a quick function for retrieving a different language to use on the locale filter. /** * A function returns with returns the user’s selectd locale, if stored. */ function wpse35622_get_new_locale($locale=false){ $new_locale = get_user_meta(get_current_user_id(), ‘wpse_locale’, true); if($new_locale) return $new_locale; … Read more

How to make a WordPress plugin translation ready?

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 … Read more

What is a Theme textdomain?

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 using one of a few translation functions: __() (for returned … Read more

Change the text on the Publish button

If you look into /wp-admin/edit-form-advanced.php, you will find the meta box: add_meta_box(‘submitdiv’, __(‘Publish’), ‘post_submit_meta_box’, $post_type, ‘side’, ‘core’); Note the __(‘Publish’) – the function __() leads to translate() where you get the filter ‘gettext’. There are two ways to handle your problem: 1. Address the string in a single specialized function (be sure to match the … Read more

Translate a plugin using .po .mo files

The Editor There are others, but this is most used: Poedit, a cross-platform gettext catalogs (.po files) editor. The Formats .mo stands for Machine Object — compiled export of the .po file which is used by WordPress .po stands for Portable Object — editable text file with the translations strings — based on the master … Read more

What is ‘\0’ in C++?

‘\0′ equals 0. It’s a relic from C, which doesn’t have any string type at all and uses char arrays instead. The null character is used to mark the end of a string; not a very wise decision in retrospect – most other string implementations use a dedicated counter variable somewhere, which makes finding the end of … Read more