基于语言环境的Symfony资产多输出文件

时间:2017-01-04 07:21:07

标签: javascript php symfony assetic

我使用symfony assetic管理javascripts& css资产(缩小并合并所有1个文件)

{% javascripts
    '@CmsBundle/Resources/public/js/translations/en.js'
    '@TempBundle/Resources/public/js/jquery.js' 
    '@AppBundle/Resources/public/js/functions.js' 
    filter='?uglifyjs2'
    output='@HomeBundle/Resources/public/js/all.min.js'
%}
    <script src="{{ asset_url }}"></script>
{% endjavascripts %}

此代码运行正常,并在目录输出1个文件:

  

@ HomeBundle /资源/公共/ JS / all.min.js

我想根据请求的区域设置添加更多javascript翻译文件

@CmsBundle/Resources/public/js/translations/en.js
@CmsBundle/Resources/public/js/translations/de.js
@CmsBundle/Resources/public/js/translations/fr.js

具有基于输入区域设置的内容的预期输出文件:

@HomeBundle/Resources/public/js/all_en.min.js
@HomeBundle/Resources/public/js/all_de.min.js
@HomeBundle/Resources/public/js/all_fr.min.js

我尝试使用变量生成带有基于输入语言环境文件的内容的定位文件:

{% javascripts
    '@CmsBundle/Resources/public/js/translations/*'
    '@TempBundle/Resources/public/js/jquery.js' 
    '@AppBundle/Resources/public/js/functions.js' 
    filter='?uglifyjs2'
    output='@HomeBundle/Resources/public/js/all_{locale}.min.js'
    vars= ['locale']
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}

配置资产:

assetic:
    variables:
        locale: [ en,de,fr ]

生成了3个语言环境文件,但内容相同,并合并了3个输出文件中的所有语言环境文件。

我希望文件all_en.min.js只包含en.js和其他非语言环境javascript文件的内容

1 个答案:

答案 0 :(得分:0)

变化

@CmsBundle/Resources/public/js/translations/*

@CmsBundle/Resources/public/js/translations/all_{locale}.min.js