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

nangongmoyan-i18n-toolkit

v0.1.2

Published

nangongmoyan-i18n-toolkit是一个fork [i18n-toolkit](https://github.com/JinYuSha0/i18n-toolkit) 项目而生成的多语言工具包

Downloads

4

Readme

nangongmoyan-i18n-toolkit

nangongmoyan-i18n-toolkit是一个fork i18n-toolkit 项目而生成的多语言工具包

prefix - operation

在正式使用之前,我们需要进行 Google Sheets 授权一些相关配置

1.Create Google Cloud Project(新建 Google Cloud 项目)

链接:https://console.cloud.google.com/projectcreate

create

image.png

success created

image.png

2. Enable Google Sheets API And Apps Script API(启用Google Sheets API And Apps Script API)

Enable Google Sheets API

image.png

image.png

Enable Apps Script API

image.png

image.png

3. OAuth consent screen(OAuth 同意屏幕)

链接:https://console.cloud.google.com/apis/credentials/consent

3.1. Select User Type(选择用户类型)

这边我选择External(任何拥有 Google 帐户的测试用户均可使用)

image.png

3.2. Edit app registration(填写相关信息)

image.png

3.3. Add Scopes(添加授权范围)

image.png

  • Checked All Google Sheets API (所有都勾选上)

image.png

  • Checked All Apps Script API (所有都勾选上)

image.png

3.4. Summary(概括)

image.png

4. Create Credential(创建凭证)

链接:https://console.cloud.google.com/apis/credentials

image.png

image.png

image.png

5. Create Google Sheets (创建 Google Sheets)

链接:https://docs.google.com/spreadsheets/u/0/

5.1. Blank spreadsheets(创建空白电子表格)

image.png

5.2. Add Apps Script (添加脚本)

image.png

将下面脚本添加进去

function onEdit(e) {
  AutoGenerateKey(e.range.getRowIndex(), e.value);
}

// 自动生成hash key
function AutoGenerateKey(rowIndex, value) {
  if (value == undefined) return;
  var targetColumn = "A";
  var sheet = SpreadsheetApp.getActive();
  var keyRange = sheet.getRange(targetColumn + rowIndex);
  var keyValue = keyRange.getValue();
  if (!!keyValue) return;
  var dateStr = new Date().toISOString();
  var rawHash = Utilities.computeDigest(
    Utilities.DigestAlgorithm.MD5,
    value + dateStr
  );
  var txtHash = "";
  for (i = 0; i < rawHash.length; i++) {
    var hashVal = rawHash[i];
    if (hashVal < 0) {
      hashVal += 256;
    }
    if (hashVal.toString(16).length == 1) {
      txtHash += "0";
    }
    txtHash += hashVal.toString(16);
  }
  sheet.getRange(targetColumn + rowIndex).setValue(txtHash);
}

image.png

6. 添加配置文件i18n.config.json到项目根目录

{
  "apiKey": "上面第四步生成的key",
  "outputDir": "i18n", // 输出目录
  "spreadsheetId": "<google表格url中很长的那一段>",
  "tableIndex": 0, // 谷歌表格第一个子表
  "langues": ["zh-CN", "en-US"] // 支持的语言
}

7. 表格填写

当在对应语言下面填入相关内容,第一列会根据脚本自动生成一个hash值

image.png

usage

Installation

Npm

npm install nangongmoyan-i18n-toolkit

Yarn

yarn add nangongmoyan-i18n-toolkit

添加i18n.config.json配置文件

{
  "apiKey": "上面第四步生成的key",
  "outputDir": "i18n", // 输出目录
  "spreadsheetId": "<google表格url中很长的那一段>",
  "tableIndex": 0, // 谷歌表格第一个子表
  "langues": ["zh-CN", "en-US"] // 支持的语言
}

在package.json中的scripts中添加

"intl": "nangongmoyan-i18n-toolkit"

命令行执行npm run intl

npm run intl

就会将对应语言的json文件下载下来:

image.png

在VS Code中可以显示语言对应的具体文案

  • 安装VS Code 插件: i18n ally

image.png

  • 显示英文

Tips:点击右下角红框可以选择在编辑器中显示对应语言的文本

image.png

  • 显示中文

image.png

页面显示

image.png

点击 changeLanguage 会切换成另外一个语言

image.png

上面demo链接, 本地执行npm start就可以看到效果