npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vue-i18n-ast-loader

v1.0.0

Published

Webpack loader for Vue i18n AST transformation

Readme

vue-i18n-ast-loader

Vue 3 的 Webpack loader,使用 AST 解析实现 Vue SFC 文件的自动国际化转换。

安装

npm install vue-i18n-ast-loader
# 或
pnpm add vue-i18n-ast-loader

使用

// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.vue$/,
        use: [
          'vue-loader',
          {
            loader: 'vue-i18n-ast-loader',
            options: {
              localesDir: 'locales',
              sourceLocale: 'zh-CN',
              translateFn: '$t',
              scriptTranslateFn: 't',
            },
          },
        ],
      },
    ],
  },
}

配置选项

| 选项 | 类型 | 默认值 | 说明 | |------|------|--------|------| | localesDir | string \| string[] | 'locales' | 语言包目录名(向上查找)或绝对路径,支持数组 | | localesRules | LocalesRule[] | [] | 路径匹配规则 | | sourceLocale | string | 'zh-CN' | 源语言代码 | | translateFn | string | '$t' | 模板中的翻译函数名 | | scriptTranslateFn | string | 't' | 脚本中的翻译函数名 | | debug | boolean | false | 是否输出调试信息 |

功能

  • ✅ 转换 Vue 模板中的中文文本
  • ✅ 转换 Vue 模板属性中的中文
  • ✅ 转换脚本中的中文字符串
  • ✅ @i18n-ignore 注释支持
  • ✅ @i18n-ignore-start/end 区块忽略
  • ✅ tt 模式支持
  • ✅ 多语言包支持(localesDir 数组、向上查找)

示例

<!-- 转换前 -->
<template>
  <button>提交</button>
  <input placeholder="请输入" />
</template>

<script setup>
const msg = '欢迎使用'
</script>

<!-- 转换后 -->
<template>
  <button>{{ $t('button.submit') }}</button>
  <input :placeholder="$t('form.placeholder')" />
</template>

<script setup>
const msg = t('message.welcome')
</script>

多语言包支持

{
  loader: 'vue-i18n-ast-loader',
  options: {
    // 支持多个目录名,按优先级查找
    localesDir: ['locales', 'i18n', 'langs'],
    sourceLocale: 'zh-CN',
  },
}

License

MIT