如何在瑞典语中设置twig

如何在瑞典语中设置twig

本文介绍了Symfony2:如何在瑞典语中设置twig | date(“d F,Y”)过滤器输出月份?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我希望使用瑞典语输出几个月份(d F,Y)过滤器。 。我已经尝试在我的parameters.yml文件中设置locale:sv,但是没有效果。



在我从Symfony 2.1升级到2.3之前,它正在工作,所以我认为可能与它有关系。



有关如何解决这个问题的任何想法?

解决方案

Twig Intl Extension



您可以使用 。



它提供了一个本地化的日期过滤器,可以像这样使用:

  {{date | localized'('full','none',app.request.locale)}} 

使用 app.request.locale 作为当前语言环境的第三个参数,或只是'sv'



整合到您的项目



将正式扩展名添加到您的 composer.json 使用:

 作曲者需要twig / extensions:1.0。* @ dev 
作曲家更新twig / extensions

config.yml

  #enable intl extensions 
services:
twig.extension.intl:
class:Twig_Extensions_Extension_Intl
标签:
- {name:twig.extension}






快速提示:



另一个方便的扩展名是提供 truncate 的文本扩展名,...等过滤器

 服务:
twig.extension.text:
cl屁股:Twig_Extensions_Extension_Text
标签:
- {名称:twig.extension}


I'm having problems with the |date("d F, Y") filter in my twig templates.

I want the months to be outputted in Swedish. I have tried setting "locale: sv" in my parameters.yml files but I get no effect.

It was working before I upgraded to from Symfony 2.1 to 2.3 so I think that might have something to do with it.

Any thoughts on how to fix this?

解决方案

The Twig Intl Extension

You can use the Twig Intl Extension found in fabpot's official Twig extension repository.

It provides a localized date filter which can be used like this:

{{ date | localizeddate('full', 'none', app.request.locale ) }}

use app.request.locale as third parameter for current locale or just 'sv'.

Integration into your project

add the official extensions to your composer.json using:

composer require twig/extensions:1.0.*@dev
composer update twig/extensions

config.yml

#enable intl extensions
services:
    twig.extension.intl:
        class: Twig_Extensions_Extension_Intl
        tags:
            - { name: twig.extension }


quick tip:

another handy extension is the Text extension providing truncate,...etc filters

services:
    twig.extension.text:
        class: Twig_Extensions_Extension_Text
        tags:
            - { name: twig.extension }

这篇关于Symfony2:如何在瑞典语中设置twig | date(“d F,Y”)过滤器输出月份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 10:17