20scoops-localizer 中文文档教程

发布于 3年前 浏览 44 更新于 3年前

Localizer

Localizer 是一个脚本,用于在 google sheet 上检索语言环境数据并保存到文件 在应用程序中使用。

它看起来怎么样?

Usage

yarn add 20scoops-localizer
yarn localizer

第 1 步

创建名为 localizer.js 的文件。 唯一需要的最低配置是 url 这是您要从中检索语言环境数据

module.exports = {
  url:
    'https://docs.google.com/spreadsheets/d/1RzakawKOAo9JLz-MTkM9Iz5dqYmC6XvqcVmegUCos48/edit#gid=0',
}

并运行脚本

yarn localizer

的 google 工作表 url 第 2 步

提示将询问您的密钥 (什么是密钥以及如何检索它?)。

它只会在您第一次安装此软件包时询问。

第 3 步

提示将要求访问 url 并提供令牌 (什么是令牌以及如何检索它?)。 这是为了检索私人 谷歌表。

它只会在您第一次安装此软件包时询问。

第 4 步

就是这样。 如果您提供正确,它将显示文件的保存位置。

提供错误不用担心,重新运行即可提供 正确的令牌/秘密。

How to retrieve secret key and token

Secret key

它是 OAuth google 的密钥。 您可以从 slack 频道#general-dev 获取它。 我会在“20scoops-localizer”部分下固定在那里,或者您可以在 渠道。

Token

令牌是授权密钥,以便脚本可以在私人谷歌上检索数据 表代表你。 您可以通过脚本的 url 获取此令牌 在 Usage 部分的第 3 步 中提供或运行脚本 localizer --get-refresh-token

Continuous Integration (CI)

如何在持续集成 (CI)

上使用 环境 您可以从

Option 获取刷新令牌

Example for Github Actions

- name: Localizer
  env:
    LOCALIZER_CREDENTIAL_TOKEN: ${{ secrets.LOCALIZER_CREDENTIAL_TOKEN }}
    LOCALIZER_REFRESH_TOKEN: ${{ secrets.LOCALIZER_REFRESH_TOKEN }}
  run: yarn localizer

How localizer read/export locales from google sheet

Example google sheet

可以通过合并工作表行来划分标题。

google-sheet-example

esm格式

//en.js

const en = {
  translation: {
    btnLogin: 'Login',
    username: 'Username',
    password: 'Password',
    welcome: 'Welcome',
    hello: 'Hello',
    morning: 'Morning',
  },
}
export default en
//de.js

const de = {
  translation: {
    btnLogin: 'Anmeldung',
    username: 'Nutzername',
    password: 'Passwort',
    welcome: 'herzlich willkommen',
    hello: 'Hallo',
    morning: 'Guten morgen',
  },
}
export default de

输出示例 commonjs 格式

//en.js

module.exports = {
  btnLogin: 'Login',
  username: 'Username',
  password: 'Password',
  welcome: 'Welcome',
  hello: 'Hello',
  morning: 'Morning',
}
//de.js

module.exports = {
  btnLogin: 'Anmeldung',
  username: 'Nutzername',
  password: 'Passwort',
  welcome: 'herzlich willkommen',
  hello: 'Hallo',
  morning: 'Guten morgen',
}

本地化器假设第一行是标题。 它将在之后开始检索数据 第一行。

此外,Localizer 具有以下规则

  • The first column is the key for developer.
  • The second to last column is the name of the language that is exported. There will be a key to each file.

Options

OptionsParametersDescriptionDefault value
--clientID=$clientIDCredential client_id in google credential.If not organization 20Scoops-CNX. Can input new client_id from google credential.client_id of 20Scoops CNX
--projectID=$projectIDCredential project_id in google credential.If not organization 20Scoops-CNX. Can input new project_id from google credential.project_id of 20Scoops CNX
--localizerFile=$localizerFileLocation file localizerIf file localizer isn't stay in root project can input location file./localizer.js
--get-refresh-tokenN/AGet refresh token for run with CI.N/A

Config

您可以通过在根项目上创建 localizer.js 来配置脚本。

示例

module.exports = {
  dest: './locales',
  filename: {
    en: 'en.js',
    de: 'de.js',
  },
  url:
    'https://docs.google.com/spreadsheets/d/1RzakawKOAo9JLz-MTkM9Iz5dqYmC6XvqcVmegUCos48/edit#gid=0',
  ignoreColumns: ['th', 'description'],
  sheetName: '',
  module: 'esm',
}
KeyValueRequiredDefault
urlGoogle Sheets URL.YesN/A
destLocation of local file storage.No./locales/
filenameFilename will corresponds to language.No{en: 'en.js',de: 'de.js',}
ignoreColumnsScript will ignore columns is selectNo[]
sheetNameScript will retrieve locales from specified sheet name via this config.No''
moduleType of output esm, commonjs, android-xml or ios-strings.Noesm

** 如果 sheetName 大于 1。您可以设置如下 sheetName:['sheet1', 'sheet2']

Localizer

Localizer is a script for retrieve locales data on google sheet and save to file for using in application.

How it looks like?

Usage

yarn add 20scoops-localizer
yarn localizer

Step 1

Create file called localizer.js. The only minimum config required is url which is google sheet url you want to retrieve locales data from

module.exports = {
  url:
    'https://docs.google.com/spreadsheets/d/1RzakawKOAo9JLz-MTkM9Iz5dqYmC6XvqcVmegUCos48/edit#gid=0',
}

and run script

yarn localizer

Step 2

Prompt will asked your secret key (What is secret key and how to retrieve it?).

It only ask for the first time when you install this package.

Step 3

Prompt will asked to visit the url and provide token (What is token and how to retrieve it?). This is for retrieve private google sheet.

It only ask for the first time when you install this package.

Step 4

That's it. If you provide correctly, it will show where files are saved.

Don't worry if you provide incorrectly, just run again and you can provide correct token / secret.

How to retrieve secret key and token

Secret key

It's secret key of OAuth google. You can get it from slack channel #general-dev. I'll pin on there under "20scoops-localizer" section or you can ask in the channel.

Token

Token is authorization key so that script can retrieve data on private google sheet on behalf of you. You can get this token by following the url the script provide in Step 3 on Usage section or run script localizer --get-refresh-token

Continuous Integration (CI)

How to use on Continuous Integration (CI)

Set up LOCALIZER_CREDENTIAL_TOKEN and LOCALIZER_REFRESH_TOKEN on environtment

You can get refresh token from Option

Example for Github Actions

- name: Localizer
  env:
    LOCALIZER_CREDENTIAL_TOKEN: ${{ secrets.LOCALIZER_CREDENTIAL_TOKEN }}
    LOCALIZER_REFRESH_TOKEN: ${{ secrets.LOCALIZER_REFRESH_TOKEN }}
  run: yarn localizer

How localizer read/export locales from google sheet

Example google sheet

Can divide the headers by merge row of sheet.

google-sheet-example

Example output for esm format

//en.js

const en = {
  translation: {
    btnLogin: 'Login',
    username: 'Username',
    password: 'Password',
    welcome: 'Welcome',
    hello: 'Hello',
    morning: 'Morning',
  },
}
export default en
//de.js

const de = {
  translation: {
    btnLogin: 'Anmeldung',
    username: 'Nutzername',
    password: 'Passwort',
    welcome: 'herzlich willkommen',
    hello: 'Hallo',
    morning: 'Guten morgen',
  },
}
export default de

Example output for commonjs format

//en.js

module.exports = {
  btnLogin: 'Login',
  username: 'Username',
  password: 'Password',
  welcome: 'Welcome',
  hello: 'Hello',
  morning: 'Morning',
}
//de.js

module.exports = {
  btnLogin: 'Anmeldung',
  username: 'Nutzername',
  password: 'Passwort',
  welcome: 'herzlich willkommen',
  hello: 'Hallo',
  morning: 'Guten morgen',
}

localizer assume first row is for headline. it will start retrieve data after the first row.

In addition, the Localizer has the following rules

  • The first column is the key for developer.
  • The second to last column is the name of the language that is exported. There will be a key to each file.

Options

OptionsParametersDescriptionDefault value
--clientID=$clientIDCredential client_id in google credential.If not organization 20Scoops-CNX. Can input new client_id from google credential.client_id of 20Scoops CNX
--projectID=$projectIDCredential project_id in google credential.If not organization 20Scoops-CNX. Can input new project_id from google credential.project_id of 20Scoops CNX
--localizerFile=$localizerFileLocation file localizerIf file localizer isn't stay in root project can input location file./localizer.js
--get-refresh-tokenN/AGet refresh token for run with CI.N/A

Config

You can config script by creating localizer.js on your root project.

Example

module.exports = {
  dest: './locales',
  filename: {
    en: 'en.js',
    de: 'de.js',
  },
  url:
    'https://docs.google.com/spreadsheets/d/1RzakawKOAo9JLz-MTkM9Iz5dqYmC6XvqcVmegUCos48/edit#gid=0',
  ignoreColumns: ['th', 'description'],
  sheetName: '',
  module: 'esm',
}
KeyValueRequiredDefault
urlGoogle Sheets URL.YesN/A
destLocation of local file storage.No./locales/
filenameFilename will corresponds to language.No{en: 'en.js',de: 'de.js',}
ignoreColumnsScript will ignore columns is selectNo[]
sheetNameScript will retrieve locales from specified sheet name via this config.No''
moduleType of output esm, commonjs, android-xml or ios-strings.Noesm

** If sheetName more than 1. You can set follow sheetName:['sheet1', 'sheet2']

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文