Search code examples
javascriptphpsymfonyassetic

Symfony assetic multiple output files based in locale


I'm using symfony assetic to manage javascripts & css assets (minify & merge all to 1 file)

{% 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 %}

This code is working perfectly and output 1 file at the dir:

@HomeBundle/Resources/public/js/all.min.js

I want to add more javascript translations files based in the requested locale

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

The expected output files with a content based in the input locale:

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

I tried to use variables to generate localed files with a content based in the input locale file:

{% 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 %}

The config assetic:

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

The 3 locales files was generated but with the same content and merged all locale files in the 3 output files.

I want the file all_en.min.js have only the content of en.js and other non-locale javascript files


Solution

  • change

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

    to

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