Format strings

Issue #1 resolved
Leandro Matos created an issue

How could I use sprintf-js to format strings that should be translated? Can you help me?

https://www.npmjs.com/package/sprintf-js

Comments (5)

  1. Doğan Çelik repo owner

    First you need to pass sprintf-js to the plugin function like so:

    var pugPipe = pug({
      i18n: {
        locales: 'locale/*',
        filename: '{{basename}}.{{lang}}.html'
      },
      data: {
        sprintf: require('sprintf-js')
      },
    });
    
    gulp.src('input/*.pug')
      .pipe(pugPipe)
      .pipe(gulp.dest('output/'))
    

    Then you can use sprintf function inside Pug:

    h1 Hello World
    h2 #{ sprintf($i18n.baseString, $i18n.variable1, $i18n.variable2) }
    
  2. Doğan Çelik repo owner

    Because require('sprintf-js') is an object and has sprintf() function inside.

    data: {
      sprintf: require('sprintf-js').sprintf
    }
    

    You should know what module contains, not me :)

  3. Log in to comment