Preparing a string in an array for localization

You can’t do that, at least not from a GUI translation helper app, because these are set to pick up strings from standard functions like __(), _e etc, they can’t read variables (including string variables)

Instead try:

var $control_types = array(
    array(
        'key' => 'manual',
        'value' => __('Manual', 'yourtextdomain')
    )
);

But if $control_types is a static variable from a class then you won’t be able to assign the return value of a function as it’s value. Why not make it a normal variable inside the process_class_vars() method? Or just make it a function:

public static function control_types(){
 return
    array(
        'manual' => __('Manual', 'yourtextdomain'),
        ...
    )
);

...
foreach ($this->control_types() as $control_type => $label) 
{
    // I'm pretty sure you don't need 'key' / and 'value' as key name here either...
    $temp_array[] = array(
        'key' => $control_type,
        'value' => $label,
    );
}

Leave a Comment