Closed Jimmi08 closed 7 years ago
Hello, thank you for this report.
To help me find out the problem, may I ask you:
Hello, at first, I just got already existed site to manage.
Active language: Czech (default), English WP lang installation: Czech
If I print $sublanguage->current_language, values are:
stdClass Object
(
[ID] => 1208
[post_name] => cs
[post_title] => Čeština
[post_content] =>
[post_excerpt] =>
[menu_order] => 0
)
stdClass Object
(
[ID] => 1209
[post_name] => en
[post_title] => English
[post_content] =>
[post_excerpt] =>
[menu_order] => 0
)
I was able to get my theme files translated by this in functions.php:
add_filter( 'locale', 'my_theme_localized' );
function my_theme_localized( $locale )
{
global $sublanguage;
if($sublanguage->current_language->post_name == 'cs') {
$locale = "cs_CZ";
}
else $locale = "en_EN";
return $locale;
}
add_action( 'after_setup_theme', 'my_theme_setup' );
function my_theme_setup(){
load_theme_textdomain(THEME_NS, get_template_directory() . THEME_LANGS_FOLDER);
}
Thanks
I think you'd just need to set post_content of the Czech language object to "cs_CZ". For this you can just open the Czech language in Menu > Languages and set the "Locale" box value to "cs_CZ".
Thanks, but I am afraid it would influence already existed translations.
No it won't influence existing translations. I will also correct this problem occurring when Sublanguage is installed when the admin language is not english. Thnx for pointing me this issue.
On Frontend: $locale = get_locale(); in functions.php returns empty value. WP tries to load this: /wp-content/themes/gitisit/languages/.mo
If I comment your filter 'locale' in your file site.php, translation works.
add_filter('locale', array($this, 'get_locale'));
WP tries to load correct way: /wp-content/themes/gitisit/languages/cs_CZ.moOtherwise everything works.
I load load_theme_textdomain() in after_setup_theme action, maybe this is problem and I should use different action. Thank you for help