            * Format date based on given pattern
            * @todo Use global function instead of filter. It's more flexible. For now it's filter
            *       just because it's faster to use and easier replacement for old filter
-           * @param {number} value               Date which should be formatted
-           * @param {string} format = '0,0[.]00' Pattern as per http://momentjs.com/docs/#/displaying/
-           * @param {string} locale = locale     Locale name
+           * @param {number} value                  Date which should be formatted
+           * @param {string} format = '0,0[.]00'    Pattern as per http://momentjs.com/docs/#/displaying/
+           * @param {string} locale = currentLocale Locale name
            * @return {string} Formatted date
           ###
-          env.addFilter '_d', (date, format = 'DD MMM YYYY', locale = locale) ->
+          env.addFilter '_d', (date, format = 'DD MMM YYYY', locale = currentLocale) ->
             moment.locale(locale);
             moment(date).format(format)
 

           * Format number based on given pattern
           * @todo Use global function instead of filter. It's more flexible. For now it's filter
           *       just because it's faster to use and easier replacement for old filter
           * @param {number} value               Number which should be formatted
           * @param {string} format = '0,0[.]00' Pattern as per http://numbrojs.com/format.html
           * @param {string} locale = locale     Locale name as per https://github.com/foretagsplatsen/numbro/tree/master/languages
           * @return {string} Formatted number
          ###
          env.addFilter '_n', (value, format = '0,0[.]00', locale = locale) ->
            numbro.language(locale)
            numbro(value).format(format)


  # Construct task
  Task = ->
    # Define targets, with unique options and files, for each locale
    locales.forEach (currentLocale) =>
      localeDir = resolveLocaleDir(currentLocale)

      @[currentLocale] = {}

      @[currentLocale].options =
        paths: '<%= path.source.layouts %>/'
        autoescape: false
        data:  '<%= data %>'
        configureEnvironment: (env) ->
          # Append url with locale name based on whether it's base locale or not
          env.addFilter 'resolveUrl', (url, locale) ->
            locale = locale || currentLocale
            return (if resolveLocaleDir(locale) then '/' + resolveLocaleDir(locale) else '') + url

          # Output or not locale name based on whether it's base locale or not.
          env.addFilter 'resolveLocaleDir', (locale) ->
            if resolveLocaleDir(locale) then '/' + resolveLocaleDir(locale) else ''

          # Load string from current locale
          env.addGlobal '_t', (string, ph) ->
            ph  = ph || {}
            sprintf(i18n.dgettext(currentLocale, string), ph)

          # Load string from specified locale
          # @note So far `sprintf` support only named placeholders
          env.addGlobal '_dt', (locale, string, ph) ->
            locale = locale || currentLocale
            ph  = ph || {}
            sprintf(i18n.dgettext(locale, string), ph)

          ###*
           * Nunjucks extension for Markdown support
