I would like to translate all items from button style dropdown list on the settings page in my plugin.
Normally, when I want to translate something, I use this pattern:
__( 'Theme style', 'qty-increment-buttons-for-woocommerce' )
However, this is not a plain text, but a setting that I use for example in defaults array:
$defaults = array ( 'qib_auto_table' => false, 'qib_merge_buttons' => true, 'qib_button_height' => 35,
'qib_button_width' => 35, 'qib_button_style' => 'Silver', 'qib_quantity_field_width' => 52 );
Then in my plugin I do checks like this:
switch ( $args['button_style'] ) {
case 'Theme style':
Can I translate these options and refer to them using my normal translation pattern (in $items array as well)? Or it can break if, for instance, someone saves settings in one language and then changes the language of the website?
public function qib_button_style_callback() {
$items = array ('Theme style', 'Silver', 'Black', 'Orange');
echo '<select id="qib_button_style" name="qib_settingz[qib_button_style]">';
foreach($items as &$item) {
$selected = (isset( $this->options['qib_button_style'])) && ( $item == $this->options['qib_button_style']) ? 'selected="selected"' : '';
$item = __( $item, 'qty-increment-buttons-for-woocommerce' );
printf(
'<option value="%1$s" %2$s>%1$s</option>',
esc_attr($item),
$selected
);
}
printf(
'</select>
<p class="description">%1$s</p>',
__( 'To use button colors from your theme, choose "Theme style". Otherwise plugin will use its own style to color increment buttons. It includes background, font, hover background and focus outline. Also quanity input field\'s border is colored. If for example custom background color is needed, you can override rule with child theme CSS.', 'qty-increment-buttons-for-woocommerce' )
);
}