我有一个Symfony应用程序,我在OS X上开发并部署到Debian Jessie,它们都运行PHP 5.6.12。 Symfony(标准版)版本在两个系统上都是相同的:2.7.3。未启用转换程序服务,两个系统上的de
都设置为currency
(德语),并且在I18n或语言环境处理方面没有配置差异。
在此应用程序中,有一个表单使用“money”字段类型,EUR
设置为de
。在OS X上,字段值以逗号显示为小数点分隔符(在德语中很常见),在字段后面带有“€”符号。在Debian Jessie上,小数点分隔符是一个点,“€”符号显示在字段左侧。对于发送不同“Accept-Language”请求标头的客户端,此行为是相同的。
我的问题是:
<head>
语言环境?或者提出不同的问题:行为的差异可能来自哪里?答案 0 :(得分:2)
您必须确保安装了php-intl扩展。
因为Symfony Intl Component(缺少php-intl扩展名的替换层)仅支持区域设置:'en',您可以在their php files中看到。
public function __construct($locale = 'en', $style = null, $pattern = null)
{
if ('en' !== $locale && null !== $locale) {
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported');
}
....
}
还因为exception is thrown,如果您尝试调用以下代码。
\Locale::setDefault('de_DE');
未实现Symfony \ Component \ Intl \ Locale \ Locale :: setDefault()。请安装“intl”扩展以获得完整的本地化功能。
500内部服务器错误 - MethodNotImplementedException
正如上面链接的Stackoverflow问题中的答案所述,你必须安装php-intl。对于我在Ubuntu上的某种方式,PHP-5和PHP-7是可用的是一个问题。 PHP5-intl已安装,但未安装PHP7-intl。您应该通过调用 phpinfo(); 来确保扩展名已经加载。
我的回答是假设您在symfony中配置了语言环境,正如我在以下几行中所做的那样:
framework:
translator: { fallbacks: ["%locale%", 'en'] }
default_locale: de
symfony配置中的twig衍生物还支持以下(对于我们的问题不必要的)条目:
date:
format: d.m.Y, H:i:s
interval_format: '%%d Tage'
timezone: Europe/Paris
number_format:
decimals: 2
decimal_point: ','
thousands_separator: '.'