php - 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?
解决方案
这似乎有效:
$items = array ('Silver', 'Black', 'Orange');
foreach ($items as &$item) {
$item = __( $item, 'my-textdomain' );
}
unset($item);
推荐阅读
- jenkins - Centos7上的Jenkins安装错误-文件不包含节标题
- csv - RULE planner 不支持调用过程(使用 apoc.do.when 时)
- python - 确定最低计数的最pythonic方法
- swift - 跨 .swift 文件传输用户默认值
- django - Django 自定义用户管理面板无法登录
- regex - 为什么我不能在“|”处分开 在clojure中
- swift - 在 CoreData 中为一个属性保存多个对象
- java - Thymeleaf 无法评估国际化表达
- vb.net - 使用 WebClient 下载在 mscorlib.dll 中发生抛出错误“System.Reflection.TargetInvocationException”
- android - WritableArray.size() 在 RN 0.55.4 (Android) 中始终为 1