Tag Info

Hot answers tagged

19

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', ...


14

Internationalization and localization (commonly abbreviated as i18n and l10n respectively) are terms used to describe the effort to make WordPress (and other such projects) available in languages other than English, for people from different locales, who use different dialects and local preferences. __() is used when the message is passed as an ...


12

Never rely on core strings for translation, they may change or get a context parameter any time. Once that happens your users get a partially translated interface, and your translators have no way to fix that. Also keep in mind the same string is not necessary translated everywhere with the same word. Even without a context parameter it might be useful to ...


11

__ (double underscore) is the base translate function. It translates a string and returns it as a string. _e does the same as __, but echo's the result immediately. _x is the contextual translate function. It has a second option to provide context to people doing the translation. _ex is the same as _x, but echo's the result. Example of using _x: ...


9

I wouldn't try to localize your slugs. Instead, why not give your users the option to change them by adding another field to the permalink settings page? Hook into load-options-permalink.php and set up some things to catch the $_POST data to save your slug. Also add a settings field to the page. <?php add_action( 'load-options-permalink.php', ...


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

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 .pot file, using Update from POT ...


6

__(), _e() and _x(), _ex() __() and _e() are essentially both a wrapper of translate() (do not use directly) and almost the same. The difference lies in that __() returns the translated string and _e() echoes it. Both need to be fed a string as a required parameter and usually, though optional, also a textdomain. Analogously, there's _x() and _ex(), which ...


6

It's used for translate text. The second argument is a kind of namespace (called domain here) to retrieve the translation (for example from a dedicated file or something else). So Anyword here, should be the guy behind the template, or the company or what ever that can be a domain/namespace. edit: The doc from wordpress give more explanation on how to ...


6

Use the filter 'mce_external_languages'. From wp-includes/class-wp-editor.php: The following filter loads external language files for TinyMCE plugins. It takes an associative array 'plugin_name' => 'path', where path is the include path to the file. The language file should follow the same format as /tinymce/langs/wp-langs.php and ...


6

This is not a problem if every string gets its own template for translation. If you use the string You can include a %s in a childtheme. more than one time for different nouns it is not translatable. An example, taken from a recent article: New %s is in German (yes, we have gendered nouns too) … Neues Buch (for a book, neutral) Neuer Film (for a movie, ...


6

The second part is not required, it just loads a PHP file with language specific functions. Examples In some countries/regions/religions it is not allowed to use capital letters in a word for anything else than the name of some god. In these cases you probably want to remove the Wordpress to WordPress filter. Some languages (Chinese) do not use spaces (in ...


6

If you're creating this theme or plugin for inclusion in the official plugin or theme directories on WordPress.org, then you need to use the plugin or theme's slug as the text-domain. You cannot have multiple text domains, and the text domain cannot be anything other than the slug of the plugin or theme. This is due to the new language pack support coming ...


6

Stylesheet Printing Order WordPress does not load themes' alternative rtl.css files using wp_register_style() or wp_enqueue_style(). As such, the stylesheet does not get added to WordPress's style queue, and cannot be specified as a dependency when registering or enqueueing additional stylesheets. Instead, this stylesheet's <link> element is added ...


5

Instead of using 'if' loop it's better to use special function: <?php echo _n( 'article', 'articles', $count, 'my-plugin-domain' ); ?> http://codex.wordpress.org/Function_Reference/_n


5

Filter template_include: add_filter( 'template_include', 'prefix_translate_template' ); function prefix_translate_template( $template ) { if ( 'category-' . __( 'news', 'your_textdomain' ) . '.php' === $template ) return 'category-news.php'; return $template; } But I think templates based on slugs are not a good idea in that case.


5

Should such messages be localized at all or are they out of scope for localization? Yes, they should be localized ... but don't depend on the text returned by the API. Does something like __( $message ); even make sense? Not really. First of all, you're not providing a text domain for the string to use in localization. It should really be __( ...


4

Yes, but please don't. This is like coding standard, better follow it even when you can get a small advantage by bypassing it. Better reasons: In version 3.5 WordPress don't have a monolith translation files, it was broken into 3 part for performance reasons. If this trend continues, can you be sure that the default domain will be loaded at all when you ...


4

You can try this codestyling-localization plugin:. You can translate you plugins and themes using this.


4

WordPress has a nice function mainly for that wp_localize_script To use it first queue your script: wp_enqueue_script( 'My_Script_handle', 'path/to/script.js' ); then create an array of strings you want to localize: $data = array( 'exit' => __( 'Exit','my-plugin-domain' ), 'open' => __( 'Open','my-plugin-domain' ), 'close' => __( ...


4

Within the code, can you see any syntax like either of the following? __( 'Hello, dear user!', 'my-text-domain' ) _e( 'Your Ad here', 'my-text-domain' ) That is, strings starting with __ (double underscores) or _e. If so, where the above says my-text-domain, you should find the name of your text domain.


3

I'm trying to do a similiar thing, and the experts on the wp-hackers mailing list (Otto, Nacin) told me this: Don't try to change WPLANG, you can't change a define'd constant. Instead, change the global $locale, or put a filter on 'locale'. So the best solution is to apply a filter on the 'locale' global variable. The only way to do that is by ...


3

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 download (export) them ...


3

wp_schedule_event can not be used for PRECISE time measurements as you are trying to do. An event scheduled with wp_schedule_event rarely runs exactly when it is scheduled to run, it runs sometime after the time which it has been configured for. To understand this, you must understand that php doesn't know what time it is until you ask it to look. Wordpress ...


3

Re-saving the language of the first site with the ID #1 solved the problem. One can do this within Settings » General » Site Language


3

In your theme, you enqueue the stylesheet usually like this: add_action( 'wp_enqueue_scripts', 't5_enqueue_style' ); function t5_enqueue_style() { wp_enqueue_style( 'theme-name-default', get_template_directory_uri() . '/css/default.min.css' ); } The extra RTL stylesheet is enqueued here too, listing the default as dependency: ...


3

I suggest also http://poeditor.com/. It is a web-based translation tool that works great with .po, .mo, .pot and other types of files.


3

Your example is correct, simply because it works. There are hundreds of ways to localize strings wich are displayed including html, all good and elegant in their own way. I like to do this as follows: printf( '<div class="updated"> <p>%1$s</p> </div>', __( 'All options are restored successfully.', 'mytextdomain' ) ); ...


3

I belive you can use a load_textdomain_mofile filter... add_filter('load_textdomain_mofile', 'custom_load_textdomain_mofile', 10, 2); function custom_load_textdomain_mofile( $mofile, $domain){ if ($domain == 'bp-ass') $mofile = 'somepath/to/your/mo/file.mo'; return $mofile; } Difference (comparing Otto) is you can actually specify your mo ...


3

The issue is, there is no value for local_package in the URL. At first I thought this might be a bug. Similar issues have been reported before (see here and here. I then stumbled on comment in trac ticket 8729 where user nbachiyski explains how localization should work: There are two ways to localize WordPress: Drop some translation files. ...



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