admin管理员组文章数量:1325756
I'm trying to translate the month names as underlined in this image, without changing the entire WP backend as well, as I require the backend to remain English.
I managed to translate the default strings via's Astra's Default String page, but they don't provide strings for the month names.
Any help would be appreciated!
Thank you :)
I'm trying to translate the month names as underlined in this image, without changing the entire WP backend as well, as I require the backend to remain English.
I managed to translate the default strings via's Astra's Default String page, but they don't provide strings for the month names.
Any help would be appreciated!
Thank you :)
Share Improve this question edited Aug 12, 2020 at 14:35 QQQ asked Aug 12, 2020 at 14:21 QQQQQQ 114 bronze badges2 Answers
Reset to default 0One easy solution, if you want the frontend to be a different language than the backend, is to change the site language under Settings > General (Spanish for example) and then change your user account's language by going to Users > Your Profile and changing the Language setting to English.
In addition, you can add this code to functions.php
to make sure the language is English for you (or any other administrator) on the frontend. You could tweak the logic if you don't want it to apply to all administrators.
/**
* Sets the locale to English on the frontend if the current user is an administrator.
*
* @param string $locale The locale ID.
*
* @return string
*/
function sx372871_set_administrator_locale( $locale ) {
// If the current user is an admin, make sure locale is set to English.
if ( current_user_can('administrator') && ! is_admin() ) {
return 'en_US';
}
return $locale;
}
add_filter( 'locale', 'sx372871_set_administrator_locale' );
The following code will translate month names from English to Spanish on the frontend:
/**
* Translates month names on the frontend of the site.
*/
function sx372871_translate_month_names( $translated_text ) {
if ( is_admin() ) {
return $translated_text;
}
$months = array(
'january' => 'Enero',
'february' => 'Febrero',
'march' => 'Marzo',
'april' => 'Abril',
'may' => 'Mayo',
'june' => 'Junio',
'july' => 'Julio',
'august' => 'Agosto',
'september' => 'Septiembre',
'october' => 'Octubre',
'november' => 'Noviembre',
'december' => 'Diciembre',
);
if ( array_key_exists( strtolower( $translated_text ), $months ) ) {
return $months[strtolower($translated_text)];
}
return $translated_text;
}
add_filter( 'gettext', 'sx372871_translate_month_names' );
本文标签: translationHow do I translate month names in post metadata
版权声明:本文标题:translation - How do I translate month names in post metadata? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742191624a2430322.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论