1

There is a function of internationalization plugins on WP. If I make .pot files I can translate my plugin to any language. When I install a plugin to website I can choose any language and the plugin will be translated to any language from possible.

The problem is to translate plugin per user by own settings. If any user set language other from main site language then in admin dashboard any plugin will be translated to users language.

But another situation is on frontend of site: all plugins has only one translation (main site language).

Is there any solution to change localization by user settings? How to get translations from .pot files from frontend of WP by user locale?

1
  • Hi All, I have found a solution for logged in users with plugin: wordpress.org/plugins/jsm-user-locale - now for full solution I am looking for anyplugin which will help me to set translation of plugin by session of user. For example, I need translation of Woocommerce, if my user is logged in I `ve got the translation. But if my user is logout then Woocomerce will not be translated. How to get session translation for logged out users? Jun 22, 2021 at 17:14

1 Answer 1

1

Thank you for interest to my theme. I have found solution of my task.

First of all the easiest way is to use a plugin, JSM-user-locale is good plugin for this task: wordpress.org/plugins/jsm-user-locale

Another way is to use standard WP functions. You can get user locale with function

get_user_meta( $user_id, 'locale', $single = true );

Site localization you can check with

get_locale();

If you have to update user`s localization with function

update_user_meta( $user_id, 'locale', $user_locale );

And for switching localization you can use function:

switch_to_locale( $user_locale );

This function will switch localization for one session.

All above functions help updating user functions.

I hope this will be helpful for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.