Symfony 2 setlocale (LC_ALL, #39;de_DE#39;)(Symfony 2 setlocale (LC_ALL, de_DE))
问题描述
我想用德语在 TWIG 中显示日期.
I would like to display a date in TWIG in German.
{{ event.beginnAt |date('l d.m.Y')}}
但输出是Friday 28.06.2013".
But the output is "Friday 28.06.2013".
我应该在哪里使用以德语显示日期的 setlocale 函数?
Where should I use the setlocale function that displays the date in German?
推荐答案
您需要启用 twig intl extension(它需要启用 intl 函数a> 在 php 中)a 然后你只需使用:
You need to enable twig intl extension (it requires enabled intl functions in php) a then you just use:
{{ event.beginAt | localizeddate('full', 'none', locale) }}
<小时>
已编辑:
如果您只想本地化日期名称,可以创建自己的 Twig 扩展:
Edited:
If you want to just localized name of day, you can create your own Twig extension:
src/Acme/Bundle/DemoBundle/Twig/DateExtension.php
namespace AcmeBundleDemoBundleTwig;
class DateExtension extends Twig_Extension
{
public function getFilters()
{
return array(
new Twig_SimpleFilter('intl_day', array($this, 'intlDay')),
);
}
public function intlDay($date, $locale = "de_DE")
{
$fmt = new IntlDateFormatter( $locale, IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'Europe/Berlin', IntlDateFormatter::GREGORIAN, 'EEEE');
return $fmt->format($date);
}
public function getName()
{
return 'date_extension';
}
}
然后在services.yml中注册
Then register it in services.yml
src/Acme/Bundle/DemoBundle/Resources/config/services.yml
parameters:
acme_demo.date_extension.class: AcmeBundleDemoBundleTwigDateExtension
services:
acme_demo.twig.date_extension:
class: %acme_demo.date_extension.class%
tags:
- { name: twig.extension }
在您的 Twig 模板中,您可以只使用:
In your Twig template you can use just:
{{ event.beginAt|intl_day }} {{ event.beginAt|date('d.m.Y') }}
这篇关于Symfony 2 setlocale (LC_ALL, 'de_DE')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Symfony 2 setlocale (LC_ALL, 'de_DE')
- 从 PHP 中的输入表单获取日期 2022-01-01
- Laravel 仓库 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01