Theme Options Page: translation inside array.
I’ve successfully coded an Options page for the theme I’m developing for my personal Website but translation doesn’t work inside an array.
Here’s the code:
$options = array ( array( "name" => __( 'Title', 'my_theme' ), "type" => "title"), array( "type" => "open"), array( "name" => __( 'Title separation character', 'my_theme' ), "desc" => __( 'Enter the character(s) you want the title be separated with.', 'my_theme' ), "id" => $shortname."_t_s", "type" => "text", "std" => "|"), array( "name" => __( 'Title pages separation character', 'my_theme' ), "desc" => __( 'Enter the character(s) you want the page title be separated with.', 'my_theme' ), "id" => $shortname."_t_p_s", "type" => "text", "std" => "::"), array( "type" => "close"),
Translation inside other pages and inside the options page works. In arrays just doesn’t work 🙁
What’s wrong in the code?
I’m using Poedit for Windows. Strings appear as translated.
Thanks in advance,
Marco (from Italy)
I had the same kind of problem as you. The problem with (no) translations occured when I tried to set default values which were in an array. I finally solved it by including this array in an update_option function and let the admin_init hook callback that function.
Admin_init is the first thing triggered when you access an admin page and all functions of the Settings API are tied to the admin_init hook:
add_action(‘admin_init‘, callback: my_init_function)
my_init_function includes: register_setting function + add_settings_field functions
the add_settings_field functions include a callback
that callback is a function that outputs the input field html
Could it be that your options array is not part of an add_settings_field callback function?
I hope this points you in the right direction to solve your problem.
Ehrm I can barely understand but I’ll read everything carefully and let you know. Thank you very much for your precious help! 🙂
I still believe this is a Poedit-related issue, because __(); function displays the text I put inside the array hard-definition so I believe it’s being parsed by WordPress translation engine right? Is there something I’m missing with the method WP engine works?
I mean you have to tell, manually, in Poedit what functions it has to look for inside the source code. Maybe nested functions are not supported?
WordPress’ translation is based on ‘gettext’ (part of GNU Translation Project). Poedit is not only used for WordPress, but for gettext in general. If you wouldn’t manually tell Poedit what functions to look for it would only find gettext() and ngettext() for plurals. That you can add functions is just to make it possible for projects to use a custom function, like WordPress its __() and _e().
All that Poedit does is creating a catalog (.po/.mo files). It did find the strings in your $options array, right? You said the strings appear as translated. So they are in the catalog and then it can’t be Poedit related.
Maybe you can show a bit more of your code to make clear where the $options array comes in.
- The topic ‘Theme Options Page: translation inside array.’ is closed to new replies.