WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using Smarty Templates for the back-end and Handlebars for the front-end for the plugin that I'm building.

It's only now that I discovered that the localization doesn't work when I declare my labels this way:

$ecom_labels = array(
    'product_details' => __( 'Details', 'ecom' ),
    'technical_specs' => __( 'Specifications', 'ecom' ),
    'images' => __( 'Images', 'ecom' ),
    'customer_reviews' => __( 'Reviews', 'ecom' )

And then later on supply it on my templates:

$smarty->assign( 'label', $ecom_labels );

But it seems like its working on individual variables:

$var = __('Specifications', 'ecom');
echo $var; //especificaciones

And this leads me to a solution like this:

$details_label = __('Details', 'ecom');
$specs_label = __('Specifications', 'ecom');

$labels = array(
    'product_details' => $details_label,
    'technical_specs' => $specs_label,

But I'm declaring an extra variable for each item in the array just to make the localization work.


Playing with the code, I noticed that its actually working:

$labels = array(
'technical_specs' => __('Specifications', 'ecom'),

echo $labels['technical_specs']; //especificaciones

The variable I was using was declared globally. But when I tried to declare the variable directly inside the function for the ajax hook it echoed out the translated version of the text.

So I guess the problem here is how I structured my plugin. Because what I'm currently doing is declared all the variables that I plan to use globally in the global scope and then just use global keyword to access them later on inside the functions.

Any ideas?

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.