How to add i18n to a plugin’s Twig template files?

Here’s how the Timber plugin handles this: $twig->addFunction( ‘__’, new Twig_SimpleFunction( ‘__’, function ( $text, $domain = ‘default’ ) { return __( $text, $domain ); } ) ); I’m guessing you’re doing something similar, in which case the reason these are being skipped is that you’re using a variable for the text domain. Have you … Read more

__() with sprintf returns untranslated string

The order of the functions being called is wrong. With this code: sprintf( __( ‘%s’, ‘my_text_domain’ ), $title ); You are trying to translate the string ‘%s’ in the domain ‘my_text_domain’. you are then replacing the translated string for ‘%s’ (which is ‘%s’), by the content of the variable $title. Therefore your code is similar … Read more

does a translation (i18n) have to start from an english PO?

Basically all themes out there are written in English, and localizations strings will look something like this _e( ‘Some English text’, ‘domainname’ );. Usually authors include a pot template with the theme. I qoute from the codex “POT (Portable Object Template) files The first step in the localization process is that a program is used … Read more

How to detect if text domain is already loaded?

I have to admit that I didb’t understand the setup ;), but it doesn’t matter as the lower level functions (load_textdomain IIRC) will check if a translation file is already loaded and will not load it again, therefor you can use the same file to include many translations, and call the loading function as many … Read more

Alphabetical sorting – local language

I managed to make it work: In wpconfig.php file I set define(‘DB_COLLATE’, ‘utf8_croatian_ci’); Do an SQL query on database in PhpMyadmin with: ALTER TABLE wp_posts CONVERT TO CHARACTER SET utf8 COLLATE utf8_croatian_ci I tried setting with utf8_unicode_ci first, sorting was slightly better but not quite accurate.

Localizing text from XML files

You should use a localized XML format like XLIFF or TMX , there is a tool to convert XLIFF to .po. If you cannot change the source XML you have a few options but it really depends how your outputting this XML info: Parse the XML ( for label) and create a .po with gettext … Read more