@voerkai18n/babel
Version:
Babel插件,实现自动文本映射
43 lines (39 loc) • 1 kB
TypeScript
import { PluginPass } from '@babel/core';
import * as t from '@babel/types';
import { NodePath } from '@babel/traverse';
/**
* 转译源码中的t翻译函数的翻译内容转换为唯一的id值
*
* - 将源文件中的t("xxxxx")转码成t("id")
* - 自动导入languages/index.js中的翻译函数t
*
* 查看AST: https://astexplorer.net/
* Babel插件手册: https://github.com/jamiebuilds/babel-handbook/blob/master/translations/zh-Hans/plugin-handbook.md
*
* 使用方法:
*
* {
* plugins:[
* ["voerkai18n",{
*
* }]
* ]
*
*
*
* }
*
*
*
*/
type Voerkai18nBabelPluginOptions = {
autoImport?: boolean | string;
idMap?: Record<string, string>;
};
declare function voerkai18nPlugin(babel: any): {
visitor: {
Program(path: NodePath<t.Program>, state: PluginPass & Voerkai18nBabelPluginOptions): void;
CallExpression(path: NodePath<any>): void;
};
};
export { type Voerkai18nBabelPluginOptions, voerkai18nPlugin as default };