由于 symfony 2.3 国家名称可以使用 Intl 和RegionBundle进行翻译。
默认返回的数组getCountryNames()
如下所示:
=> 数组('AF' => '阿富汗', ...)
如果您只对国家/地区名称感兴趣,请使用以下内容:
use Symfony\Component\Intl\Intl;
// get all country names in locale "locale"
$countries = array_values(Intl::getRegionBundle()->getCountryNames('de'));
// get all country names for current locale
$countries = array_values(Intl::getRegionBundle()->getCountryNames());
...如果您只想使用翻译器翻译数组。
$translator = $this->get('translator');
foreach ($countries as $key => $country) {
$countries[$key] = $translator->trans($country, array(), null, 'de');
}
请参阅翻译 API 文档并阅读说明书章节翻译。