replace-i18n-for-script.js 313 B

1234567891011121314151617
  1. const matchI18nReg = /this.\$t\('?(.*?)'?\)/g
  2. function replace (code, map = {}, options = {}) {
  3. if (!code) {
  4. return
  5. }
  6. code = code.replace(matchI18nReg, function (a, b) {
  7. return addQuotes(map[b] || b)
  8. })
  9. return code
  10. }
  11. exports.replace = replace
  12. function addQuotes (str) {
  13. return `'${str}'`
  14. }