How to use esc_attr__ with custom translation function?

As your function returns the translated string, you could pass the translation function as parameter for esc_attr() and esc_attr_e(): esc_attr__( __myfunction( ‘no_comments’ ) ); esc_attr_e( __myfunction( ‘no_comments’ ) ); But esc_attr__() and esc_attr_e() will perform translation tasks that you don’t need because you handle the translation at your own, so I think it is better … Read more

Trying to localize a Underscores starter theme [duplicate]

Please note how the translation works: The Text Domain should be same in all the places of your theme. On this page you can see the Theme’s text domain setup: load_theme_textdomain( ‘_s’, get_template_directory() . ‘/languages’ ); And on this page (and many in this theme), you can see the implementation of the Text Domain: _e( … Read more

WordPress Translations

.po and .mo files are for translating strings in code files. For translating post content use a translation plugin. I’ve used a few and find WPML to be the best in many aspects. Incidentally, they have a built-in workflow for translating both content and strings in code files.

How to add a translatable string to post date

You should use placeholders: $time = sprintf( ‘<i class=”fa fa-clock-o” aria-hidden=”true”></i> %s: <time datetime=”%s”>%s</time>’, esc_html__(‘Posted on’, ‘textdomain’), get_the_time(‘Y-m-d’), get_the_time(‘j F Y’) );

How do you translate comments_number function text in a theme?

You have to make these strings translatable by using __() function: comments_number( __(‘Comments (0)’), __(‘Comments (1)’), __(‘Comments (%)’) ); If you want to use the custom textdomain, e.g. ‘test’: comments_number( __(‘Comments (0)’, ‘test’), __(‘Comments (1)’, ‘test’), __(‘Comments (%)’, ‘test’) ); For more information see: __() Theme internationalization Very good article by Samuel Wood a.k.a. Otto: … Read more

How to translate functions.php?

Added to the functions.php the next: $pather = get_stylesheet_directory().’/languages’; load_child_theme_textdomain( ‘Savia-child’, $pather ); And then called it as: __( ‘text to translate’, ‘Savia-child’); In the child theme I have created a dir: /languages and put there po and mo files with the names: [locale].po/.mp like: ru_RU.po and ru_RU.mo. That is.

POEDIT – Continue with translations

You can edit .po files in text editor. Structure is very simple (some header, do not touch it) and a number of translations like that: #: 404.php:21 msgid “Sorry! Page Not Found !” msgstr “” You can ignore comments started with #. msgid – string how it appears in php code msgstr – translation (if … Read more

/languages/ folder missing in default themes

Themes and plugins on wordpress.org don’t need a /language folder anymore. The translation is made via Glotpress on https://translate.wordpress.org/. Glotpress parses the files and you can start to translate. The translated .mo and .po files get automatic updates, if a translation string changes. They are stored in /wp-content/languages If you don’t host your Theme or … Read more