Tag Info

Hot answers tagged

23

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


13

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


13

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


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: ...


10

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


10

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 ) ...


7

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.


7

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


7

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


7

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


7

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


6

You are loading the rtl.css using the WordPress automatic way, that is, having a rtl.css in the theme folder will be loaded by WordPress automatically if it presents and direction of current language ir rtl (you should add this information to the question, it has been difficult to figure it out how you are loading the file). This process defines ...


6

i18n resource ... the hide & seek game Note up front: I'm not 100% sure about this, so please take the following with a grain of salt. I'm 99% sure by now, that the following information is correct. (Still, it's confusing even after years with WordPress). Non-Gettext translation for core The 18n.wordpress.org resource is used by the Glotpress ...


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

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

__(), _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

No, it is not. Use esc_html__( 'string', 'text_domain' ) instead (two underscores). Translated strings are unknown input. Unknown input is per default malicious. You don’t know where the language file comes from. It doesn’t even have to be the one you provided, because the path can be filtered or changed with a symlink. Even if it is your file: do you ...


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


5

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


5

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


5

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


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 __( ...


5

tl;dr Usually you should be safe by offering your Plugins in English first. If you create a good userbase, you could do your own resarch as to find out which languages are most important to your clients. Another thing to consider would be, if you want to support latin-signs only or if you want to offer all kinds of language signs. The big prolbem (for me) ...


4

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


4

The text domain is a unique identifier, which makes sure WordPress can distinguish between all loaded translations so Using the basename of your plugin/theme is always a good choice because plugin/theme basename is always unique though it is not mandatory to have plugin/theme basename as text domain, you can use any unique identifier. If you're translating ...


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

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



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