RECOMMENDED: Possible variable $i found in translation function in customizer.php

34 views Asked by At

I am checking my theme from plugin theme checker and having following message:

RECOMMENDED: Possible variable $i found in translation function in inc/customizer.php.

I am using loop in customizer as below:

Category Customizer

$category_count = 4;

for ($i=1; $i <= $category_count ; $i++) { 
$wp_customize->add_setting( 'set_category'.$i, array(
'default'           => 0,
'sanitize_callback' => 'absint',
) );

$wp_customize->add_control( new My_Dropdown_Category_Control( $wp_customize, 'set_category'.$i, array(
'section'       => 'sec_home_page',
'label'         => __( 'Select the category '.$i, 'pahla-store' ),
'description'   => __( 'If no category is selected, the category will be disabled.', 'pahla-store' ),
) ) );
}

I searched from stackoverflow but couldn't find helpful answer. i am expecting to provide solution to pass my theme from theme check pluging.

1

There are 1 answers

0
Jarmo T On BEST ANSWER

You should not use variables inside string translations.

Instead you should use sprintf to add your variables to your translation, for example:

sprintf( __( 'Select the category %d', 'pahla-store' ), $i);