Implementing conditional gettext translation

WordPress provides the _x() function which is just like __(), but it adds the $context parameter which is used to differentiate between identical strings. In the example below, some output is generated in the footer. The translatable string is Message is used in both cases, but in the first instance, Message is given the context … Read more

loco translate plugin edits file in plugin folder

I thought (and hoped) that the translations were written in the folder wp-content/languages/loco/plugins/my-plugin. They are, but only when you create the file in that location. Any users wishing to customize your provided translations should create a new translations file and not edit yours. Opening your provided PO file and starting to edit will not automatically … Read more

Change template copy with po/mo files

i had a similar question posted some time ago: why is translation not working on theme? it might be the solution to put your translation files into the right location (languages directory in wp-content/languages/themes/) and prefix them with the theme name like themename-pt_PT.po

Replace text string on individual page

I can’t comment so I’ll answer and slightly adjust Bhagyashree’s which is exactly what you’ll need to do based on your question. Except you may want to know how to include the 2 pages rather than duplicating the function. And also passing in an array of strings to replace. function replace_some_text( $content ) { // … Read more

Transliterating search term in another language

If you have PHP’s Intl extension installed, you can use the wonderful Transliterator class. I get some pretty good results, like this: $t = Transliterator::create(‘Latin-Greek’, Transliterator::FORWARD ); var_dump( [ ‘alfa’ => $t->transliterate(‘alfa’), ‘alpha’ => $t->transliterate(‘alpha’), ] ); Both these greeklish forms give me “άλφα”. I don’t know how it knows where to put the accent, … Read more

Child Theme Translations with PoEdit

Found a solution that works for me: add_action( ‘after_setup_theme’, ‘avia_lang_setup’ ); function avia_lang_setup() { $lang = apply_filters(‘parent-theme-slug’, get_template_directory() . ‘/lang’); load_theme_textdomain(‘avia_framework’, $lang); load_child_theme_textdomain( ‘child-theme-text-domain’, get_stylesheet_directory() . ‘/lang’ ); } Note: Exchange “parent-theme-slug” (typically the parent theme name in small letters) and “child-theme-text-domain” (child theme text domain of your choice)