admin管理员组文章数量:1130349
I am trying to load localization file depends on users settings. Is this way is correct or there are better ways to implement locale changing depends on user settings?
<?php
add_filter( 'locale', 'theme_localized' );
function theme_localized( )
{
if(is_user_logged_in()) {
$locale = get_user_locale();
return $locale;
}
}
?>
This code is working but I am not sure that this is the conventional way of translating website.
I am trying to load localization file depends on users settings. Is this way is correct or there are better ways to implement locale changing depends on user settings?
<?php
add_filter( 'locale', 'theme_localized' );
function theme_localized( )
{
if(is_user_logged_in()) {
$locale = get_user_locale();
return $locale;
}
}
?>
This code is working but I am not sure that this is the conventional way of translating website.
Share Improve this question asked Nov 5, 2018 at 18:36 Nikolai MaksimovNikolai Maksimov 331 silver badge3 bronze badges1 Answer
Reset to default 0By default WordPress only loads translations according to the user's language when they're viewing admin pages.
You can see that in the code for the load_theme_textdomain function:
$locale = apply_filters( 'theme_locale',
is_admin() ? get_user_locale() : get_locale(),
// ^^^^^^^^
$domain );
So your code is fine if you want to override that behaviour for the front end of your site.
Is it conventional? Well, this is what filters are for. However, I'd say this isn't normally done unless the language of the actual content is also changing.
I am trying to load localization file depends on users settings. Is this way is correct or there are better ways to implement locale changing depends on user settings?
<?php
add_filter( 'locale', 'theme_localized' );
function theme_localized( )
{
if(is_user_logged_in()) {
$locale = get_user_locale();
return $locale;
}
}
?>
This code is working but I am not sure that this is the conventional way of translating website.
I am trying to load localization file depends on users settings. Is this way is correct or there are better ways to implement locale changing depends on user settings?
<?php
add_filter( 'locale', 'theme_localized' );
function theme_localized( )
{
if(is_user_logged_in()) {
$locale = get_user_locale();
return $locale;
}
}
?>
This code is working but I am not sure that this is the conventional way of translating website.
Share Improve this question asked Nov 5, 2018 at 18:36 Nikolai MaksimovNikolai Maksimov 331 silver badge3 bronze badges1 Answer
Reset to default 0By default WordPress only loads translations according to the user's language when they're viewing admin pages.
You can see that in the code for the load_theme_textdomain function:
$locale = apply_filters( 'theme_locale',
is_admin() ? get_user_locale() : get_locale(),
// ^^^^^^^^
$domain );
So your code is fine if you want to override that behaviour for the front end of your site.
Is it conventional? Well, this is what filters are for. However, I'd say this isn't normally done unless the language of the actual content is also changing.
本文标签: theme developmentHow to set different localization file for different users
版权声明:本文标题:theme development - How to set different localization file for different users? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749199912a2331621.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论