I have a bi-lingual blog with English as the main language and Arabic. Currently I use the post "Custom Field" to indicate that the post is Arabic and I use that in my child theme to change the direction to RTL and the text translation to Arabic, however, I do that manually which means I fully customize the theme with strings in both languages and pick the correct one based on the custom field value and also set the direction for the html tags for the post title, body and comments. It is working, however, changing the theme later means I need to redo everything. I am also trying to use a comment plugin "wpDiscuz" but there is no easy way to control the language other than editing the plugin itself which I don't want to do since I want to be able to update it easily and not redo the changes after every update.
Since WP already supports Arabic language and has the translations as .mo files with the correct rtl css, and also the new plugin supports .mo translations. I thought I will utilize that and find a away to change wordpress language to Arabic only for certain posts. However, I am still not bale to do it.
I created a plugin with single file functions.php
and this is the content:
function my_reset_locale($locale) {
$locale = 'ar';
return $locale;
}
add_filter('locale','my_reset_locale',10);
This one changes it for everything (front page and all single posts), i tried reading the post ID
global $post;
$postId = isset($post) ? $post->ID : '';
But the first 4 calls to my function happens before $post->ID is set and if I wait until it is set it becomes too late as the language got loaded already and changing $locale after that does nothing.
So what can I do to get information about the post early and before the language is read (i think it is "load_textdomain" that is called to select the translation based on the locale")