John Davidson

php - Problems with translating text including hyperlink in WordPress theme using mo file

0 comments
Message:


Is this WordPress theme internationalization with hyperlink in it done right? I've spent whole day looking for fix to this but translation is not showing up on page. Only original English version of this.


MO file is generated with Loco Translate into my-theme/languages folder.


In footer.php:


$anchor = esc_html_x( 'Link', 'link text for Link', 'my-theme' );
$domain = esc_url( __( 'https://myaddress.com', 'my-theme' ) );
$link = sprintf( '<a href="%s" rel="noopener" target="_blank">%s</a>', $domain, $anchor );
echo sprintf( esc_html__( ' Check this %1$s', 'my-theme' ), $link );

In my-theme.pot file:


#: footer.php:56
msgid "Link"
msgstr ""

#: footer.php:59
msgid " Check this %1$s"
msgstr ""

In functions.php file:


function my_theme_textdomain() {
load_theme_textdomain( 'my-theme', get_template_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'my_theme_textdomain' );

Also text domain is included in style.css comment.



My Answer:
%2$s', $domain, $anchor );_ echo $link;_In my-theme/languages/my-theme.pot:_msgid "Link"_msgstr "Liên kết"_msgid "https://myaddress.com"_msgstr "https://dia-chi-cua-toi.com"_In my-theme/languages/my-theme-vi_VN.mo:_msgid "Link"_msgstr "Liên kết"_msgid "https://myaddress.com"_msgstr "https://dia-chi-cua-toi.com"_The translation for "Link" and "https://myaddress.com" seems to be correct in the .mo file, but when I switch the language to Vietnamese on my WordPress site, the hyperlink is not showing up as expected. Only the text "Link" is displayed without the hyperlink._I've tried different ways of formatting the translation in the .mo file, but none of them seem to work. Any help or suggestions would be greatly appreciated.

Rate this post

5 of 5 based on 3343 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us