Multiple calls to setup hook function and problems with loading text domain
-
I’m adding a new section to a WordPress site developed by others and based on a child theme of a purchased theme.
To do this, I added the instruction at the bottom offunctions.php
:require_once('my_functions.php');
Inside
my_functions.php
there is a hook to load the text domain used by all my texts, that is,sandbox
:if (!function_exists('mySandobxSetup')) { function mySandboxSetup() { if ( is_user_logged_in() ) { $lang = get_user_meta(get_current_user_id(), 'locale', false); if ( !empty($lang) ) { setlocale(LC_ALL, $lang); } } $done = load_child_theme_textdomain('sandbox', get_stylesheet_directory() . '/languages'); log_rec("load_child_theme_textdomain", "user", get_current_user_id(), "done", $done, "TEST", __("Click here to work with your development plan", 'sandbox') ); } } add_action('after_setup_theme', 'mySandboxSetup');
I use a function of mine called
log_rec
to register a record in log.txt file.
Note that in the child theme directory there is a folder calledlanguages
that contains it_IT.po and .mo files.When I load a single page out of my section, and I logged in by using credentials associated to a user who set his preferred language as it_IT (Italian), I get the following:
?</img>"load_child_theme_textdomain"■"user"■303■"done"■true■"TEST"■"Clicca qui per lavorare con il tuo piano di sviluppo"■ ?</img>"load_child_theme_textdomain"■"user"■303■"done"■false■"TEST"■"Click here to work with your development plan"■ ?</img>"load_child_theme_textdomain"■"user"■303■"done"■true■"TEST"■"Clicca qui per lavorare con il tuo piano di sviluppo"■
It looks like:
- mySandoxSetup is called three times
- the first time the load works, the second does not, the third works again
BUT when I look at the page, I see the texts in English and not in Italian as expected.
I browsed the whole site code searching for other *_textdomain() function, but there are none, so I am the only one to load a text domain.So I have two questions:
- what could make that function to be called three times,
- why Italian text is not shown in page (where I use
__("my text", , 'sandbox')
, of course), even if the last call loaded the right text domain?
- The topic ‘Multiple calls to setup hook function and problems with loading text domain’ is closed to new replies.