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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@alitajs/autointl

v0.0.2

Published

auto intl

Downloads

69

Readme

autoIntl

一键提取项目中的中文,自动引入 react-intl-universal 。 特别适用于一开始项目没有国际化要求,快上线的时候,说要国际化的情景。 注意不要中英文标点混用,可能会导致程序卡死,请使用Ctrl+C退出。 使用英文标点,会使你的中文被切割成很小的片段。

使用方法

$ npm i autoIntl -g

自动提取 src 目录下的所有的 js|jsx 文件

autoIntl src/

会在根目录下生成 i18n.js

const langZh = {
  test_i18n_Y823: '姓名?',
  test_i18n_3MK2: '年,龄。',
  test_i18n_lP1N: '编(号)',
  test_i18n_NUbK: '哈哈哈!',
};
export default langZh;

例如: test/index.js

const cardNum = 123;
const ss = [
  {
    title: '姓名?',
  },
  {
    age: '年,龄。',
  },
  {
    id: '编(号)',
  },
  {
    job: '哈哈哈!',
  },
  {
    card: `银行卡号是${cardNum},余额20万`,
  },
  {
    more: `更多信息是${cardNum},余额20万`,
  },
];

运行

autoIntl test

 ✅ 国际化文件替换成功

 ✅ 国际化词条整理成功
✨  Done in 0.22s.

test/index.js

import intl from 'react-intl-universal';
const cardNum = 123;
const ss = [
  {
    title: intl.get('test_i18n_k4ff'),
  },
  {
    age: intl.get('test_i18n_rXqn'),
  },
  {
    id: intl.get('test_i18n_LINE'),
  },
  {
    job: intl.get('test_i18n_ypGq'),
  },
  {
    card: `${intl.get('test_i18n_XiiD')}${cardNum}${intl.get('test_i18n_X5BP')}20${intl.get(
      'test_i18n_soPx'
    )}`,
  },
  {
    more: `${intl.get('test_i18n_8zH3')}${cardNum}${intl.get('test_i18n_X5BP')}20${intl.get(
      'test_i18n_soPx'
    )}`,
  },
];

生成 i18n.js

const langZh = {
  test_i18n_k4ff: '姓名?',
  test_i18n_rXqn: '年,龄。',
  test_i18n_LINE: '编(号)',
  test_i18n_ypGq: '哈哈哈!',
  test_i18n_XiiD: '银行卡号是',
  test_i18n_X5BP: ',余额',
  test_i18n_soPx: '万',
  test_i18n_8zH3: '更多信息是',
};
export default langZh;

可以直接通过LocaleProvider,在项目中使用

import { LocaleProvider } from 'antd';
import zhCN from 'antd/lib/locale-provider/zh_CN';
import intl from 'react-intl-universal';

import langZh from './i18n';
// locale data
const locales = {
  'zh-CN': zhlang,
};
const compents = {
  'zh-CN': zhCN,
};

const getLocale = () => {
  // 服务器应返回当前请求ip所在区域,并设置在cookie里
  // 优先获取用户选择的语言
  let locale = getCookie('userLocale');
  if (!locale) {
    // 如果用户没有选择语言,获取服务器返回的区域语言
    locale = getCookie('areaLocale');
  }
  if (!locales[locale]) {
    // 不存在cookie 或者 不支持当前语言
    locale = 'zh-CN';
  }
  window.locale = locale;
  return locale;
};
ReactDOM.render(
  <LocaleProvider locale={compents[getLocale()]}>
    <Provider store={store}>
      <CApp />
    </Provider>
  </LocaleProvider>,
  document.getElementById('root')
);