A had same question, I resolved it this way:
fist step you have to create a .mo with a text domain. You can use loco translate plugin: https://br.wordpress.org/plugins/loco-translate/
Load your text domain linking .mo file:
load_textdomain('your_text_domain', '/your/file.mo');
Change wordpress location via hook. Create a function wich returns wanted location. Use Wordpress Locale Id ever, you can see all locales Id here: https://wpastra.com/docs/complete-list-wordpress-locale-codes/
Lets write the function:
function wpsx_redefine_locale($locale){
return 'ja';
}
add_filter('locale','wpsx_redefine_locale',10);
You can change by user location. This way wordpress sets the same language was be set by user in its control panel:
$user_locale = get_user_locale();
function wpsx_redefine_locale($locale){
global $user_locale;
return $user_locale;
}
add_filter('locale','wpsx_redefine_locale',10);
Obs: My wordpress version is 5.7. This way can no work in another versions. Good look!
unload_textdomain('my-plugin-txt-domain');
load_plugin_textdomain('my-plugin-txt-domain', __DIR__ . '/../../languages');
– Kylakylah