y.js 490 B

123456789101112131415161718192021
  1. 'use strict'
  2. const path = require('path')
  3. const yargs = require('yargs')
  4. const y18n = require('y18n')({
  5. directory: path.join(__dirname, 'locales'),
  6. locale: yargs.locale(),
  7. updateFiles: process.env.NPX_UPDATE_LOCALE_FILES === 'true'
  8. })
  9. module.exports = yTag
  10. function yTag (parts) {
  11. let str = ''
  12. parts.forEach((part, i) => {
  13. str += part
  14. if (arguments.length > i + 1) {
  15. str += '%s'
  16. }
  17. })
  18. return y18n.__.apply(null, [str].concat([].slice.call(arguments, 1)))
  19. }