首页 > 解决方案 > Array of strings - translation

问题描述

I have an array of strings:

$items = array ('Silver', 'Black', 'Orange');

I would like to use WordPress _() function to make strings translation-ready, so I constructed the following and it works:

  $items = array( __( 'Silver', 'my-textdomain' ), __( 'Black', 'my-textdomain' ), __( 'Orange', 'my-textdomain' ));

How can I avoid repeating text domain or even better, use my first array to create second array?

标签: phpwordpress

解决方案


这似乎有效:

$items = array ('Silver', 'Black', 'Orange');   

foreach ($items as &$item) {
    $item = __( $item, 'my-textdomain' );       
}
unset($item);

推荐阅读