我正在开发一个应该接受多种语言输入的小型解析器。我将有大约 50 个字符串作为解析输入的关键字/锚。在 PHP 中,组织这些翻译后的关键字的最佳方式是什么?
我想到的一种可能的解决方案是使用关联数组。像这样:
$lang = array('us' => array('totalDebt' => 'Total Debt', 'color' => 'Color'),
'gb' => array('totalDebt' => 'Total Debt', 'color' => 'Colour'))
然后我可以使用以下内容访问:
$langCode = 'en';
$debtPos = strpos($lang[$langCode]['totalDebt']);
有没有更好的、经过验证的方法来处理一堆翻译成多种语言的短字符串?