Comments (5)
6.保留不翻译不提示不标注部分
如/* kiwi-disable*/
from kiwi.
重新梳理一下,到时候放出官方的 Roadmap,这个先关闭。
from kiwi.
3..kiwi/config支持的参数说明
4.usage文档
5.kiwi-clis 的参数,需要更加详细的说明
from kiwi.
7.多语言工具应该从kiwi-intl导出
现有的用法
/**
* @file 多语言工具
* @author 五灵
*/
import kiwiIntl from 'kiwi-intl';
import * as fs from 'fs-extra';
import * as path from 'path';
export enum LangEnum {
"zh-CN" = 'zh-CN',
"en-US" = "en-US",
"zh-TW" = "zh-TW"
}
/**
* 获取当前语言的Cookie
*/
export function getCurrentLang(): LangEnum {
const urlLang = new URL(window.location.href).searchParams.get('lang');
const cookieLang = (document.cookie.match(/kiwi-locale=([^;$]+)/) || [null, 'zh-CN'])[1];
const lang = (cookieLang as string).split(' ')[0];
if (Object.keys(LangEnum).includes(urlLang as string)) {
return urlLang as LangEnum;
}
return lang as LangEnum;
}
/**
* 获取文件夹下所有文件
* @function getAllFiles
* @param {string} dir Dir path string.
* @return {string[]} Array with all file names that are inside the directory.
*/
export const getAllFiles = dir =>
fs.readdirSync(dir).reduce((files, file) => {
const name = path.join(dir, file);
const isDirectory = fs.statSync(name).isDirectory();
return isDirectory ? [...files, ...getAllFiles(name)] : [...files, name];
}, []);
/**
* 适配不同的语言文件夹位置
*/
function dirAdaptor(rootPath) {
const kiwiLangPerfix = `${rootPath}/.kiwi/zh-CN/`;
const langPrefix = `${rootPath}/langs/zh-CN/`;
/** 兼容 zh_CN 情况 */
const _kiwiLangPerfix = `${rootPath}/.kiwi/zh_CN/`;
const _langPrefix = `${rootPath}/langs/zh_CN/`;
if (fs.existsSync(kiwiLangPerfix)) {
return kiwiLangPerfix;
} else if (fs.existsSync(langPrefix)) {
return langPrefix;
} else if (fs.existsSync(_kiwiLangPerfix)) {
return _kiwiLangPerfix;
} else if (fs.existsSync(_langPrefix)) {
return _langPrefix;
} else {
const files = getAllFiles(`${rootPath}/`);
const matchFiles = files.filter((fileName) => {
if (fileName.includes('/.kiwi/zh-CN/index.ts')
|| fileName.includes('/langs/zh-CN/index.ts')
|| fileName.includes('/.kiwi/zh_CN/index.ts')
|| fileName.includes('/langs/zh_CN/index.ts')) {
return true;
}
return false;
});
if (matchFiles.length) {
return matchFiles[0].replace('index.ts', '');
}
}
}
const langs = {
// "en-US": enUsLangs,
"zh-CN": {},
// "zh-TW": zhTWLangs
};
// import enUsLangs from '../.kiwi/en-US/';
// import zhCNLangs from '../.kiwi/zh-CN/';
// import zhTWLangs from '../.kiwi/zh-TW/';
if (fs.existsSync(path.join(__dirname, "../.kiwi/zh-CN/"))) {
langs["zh-CN"] = require(path.join(__dirname, "../.kiwi/zh-CN/"));
} else {
console.log(path.join(__dirname, "../.kiwi/zh-CN/"));
console.error('未找到相关文件,请执行umi kiwiinit');
}
// 从 Cookie 中取语言值, 默认为 zh-CN
const defaultLang = getCurrentLang();
let curLang;
if (Object.keys(langs).indexOf(defaultLang) > -1) {
curLang = defaultLang;
} else {
// 如果没有对应的语言文件, 置为中文
curLang = 'zh-CN';
}
const I18N = kiwiIntl.init(curLang, langs);
export default I18N;
期望的用法:
import { kiwiI18N } from 'kiwi-intl';
这个可以提上日程了,同时可以支持 #24
from kiwi.
kiwi兼容现在的react-intl,你觉得如何?就是说我有一个旧项目,我先按现在react-intl的用法,使用kiwi工具
from kiwi.
Related Issues (20)
- 导入成功后,无法二次导入不同的文案,会一直告知导入成功 HOT 1
- 可以撤销国际化吗? HOT 1
- 在使用kiwi --translate之后不能成功翻译 HOT 1
- ignoreDirectory和ignoreFile属性能否release一个版本支持下
- extract时如果上级目录不存在会报错
- 翻译命令执行报II8N文件不存在
- kiwi --translate 西班牙语报错 (繁体,英文,泰语,日语没问题)
- kiwi-linter 一键提取中文字符串到对应的语言 Key 库的时候 文件路径能否支持vscode预先定义?! HOT 1
- kiwi --extract 新生成的文件没自动写入到导出的index.ts
- [email protected] 执行 kiwi --extract 无效 HOT 2
- kiwi-linter 在新版本的 VSCode 中使用报错
- 能否支持js、jsx文件的提取?并且一键提取中文字符串到对应的语言 Key 库的时候,是按照原来的文件路径新建的,变量名也是文件路径拼起来 HOT 3
- kiwi-linter@ v1.5.0 关键词错位
- 怎么实现增量更新 HOT 3
- 在vue3中切换语言无法实现响应式,需刷新才能切换 HOT 1
- kiwi在pnpm workspace不能运行
- [bug] npm版本和github版本不一致
- 能否在这里推荐一个全平台的国际化翻译系统呢
- [bug]插件 kiwi-linter 1.5.2版本 在vsCode中失效 HOT 3
- 安装依赖时报错:Error installing vscode.d.ts: Error: Request returned status code: 404
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kiwi.