Giter Site home page Giter Site logo

Future about kiwi HOT 5 CLOSED

alibaba avatar alibaba commented on August 19, 2024
Future

from kiwi.

Comments (5)

xiaohuoni avatar xiaohuoni commented on August 19, 2024 1

6.保留不翻译不提示不标注部分
如/* kiwi-disable*/

from kiwi.

linhuiw avatar linhuiw commented on August 19, 2024 1

重新梳理一下,到时候放出官方的 Roadmap,这个先关闭。

from kiwi.

xiaohuoni avatar xiaohuoni commented on August 19, 2024

3..kiwi/config支持的参数说明
4.usage文档
5.kiwi-clis 的参数,需要更加详细的说明

from kiwi.

xiaohuoni avatar xiaohuoni commented on August 19, 2024

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.

xiaohuoni avatar xiaohuoni commented on August 19, 2024

kiwi兼容现在的react-intl,你觉得如何?就是说我有一个旧项目,我先按现在react-intl的用法,使用kiwi工具

from kiwi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.