@brainly/onesky-utils

中文文档
1.4.2发布于 2023/06/28MITCommonJS近 30 天下载 1.4万

Node.js utils for working with OneSky translation service.

原始使用文档
文档目录17 节
  1. Install
  2. Example
  3. getFile
  4. getFiles
  5. getMultilingualFile
  6. postScreenshot
  7. postFile
  8. getLanguages
  9. API
  10. getFile(options)
  11. getFiles(options)
  12. getMultilingualFile(options)
  13. postScreenshot(options)
  14. postFile(options)
  15. getLanguages(options)
  16. Tests
  17. License

nodejs-onesky-utils Build Status Code Climate npm version

Node.js utils for working with OneSky translation service.

Install

$ npm i @brainly/onesky-utils

Example

getFile

var onesky = require('@brainly/onesky-utils');

var options = {
  language: 'en_EN',
  secret: '1234567',
  apiKey: 'abcdefg',
  projectId: '123',
  fileName: 'translations.po'
};

onesky.getFile(options).then(function(content) {
  console.log(content);
}).catch(function(error) {
  console.log(error);
});

getFiles

var onesky = require('@brainly/onesky-utils');

var options = {
  secret: '1234567',
  apiKey: 'abcdefg',
  projectId: '123',
};

onesky.getFiles(options).then(function(content) {
  console.log(content);
}).catch(function(error) {
  console.log(error);
});

getMultilingualFile

var onesky = require('onesky-utils');

var options = {
  language: 'en_EN',
  secret: '1234567',
  apiKey: 'abcdefg',
  projectId: '123',
  fileName: 'translations.po',
  format: 'I18NEXT_MULTILINGUAL_JSON'
};

onesky.getMultilingualFile(options).then(function(content) {
  console.log(content);
}).catch(function(error) {
  console.log(error);
});

postScreenshot

var onesky = require('onesky-utils');

var options = {
  secret: '1234567',
  apiKey: 'abcdefg',
  projectId: '123',
  name: 'screenshot-name',
  image: 'base64-encoded-image',
  tags: [
    {
      key: 'translation-key',
      x: 100,
      y: 100,
      width: 100,
      height: 100,
      file: 'translations.po',
    },
  ],
};

onesky.postScreenshot(options).then(function(response) {
    console.log(response);
  }).catch(function(error) {
    console.log(error);
  });

postFile

var onesky = require('onesky-utils');

var options = {
  language: 'en-US',
  secret: '1234567',
  apiKey: 'abcdefg',
  projectId: '123',
  fileName: 'translations.json',
  format: 'HIERARCHICAL_JSON',
  content: JSON.stringify(translations),
  keepStrings: true
};

onesky.postFile(options).then(function(content) {
  console.log(content);
}).catch(function(error) {
  console.log(error);
});

getLanguages

var onesky = require('onesky-utils');

var options = {
  apiKey: 'abcdefg',
  secret: '1234567',
  projectId: '123'
};

onesky.getLanguages(options).then(function(content) {
  console.log(content);
}).catch(function(error) {
  console.log(error);
});

API

getFile(options)

Downloads translation file from OneSky.

Returns file content via promise.

The options object is required. Options include:

  • options.projectId - Numerical ID of the project
  • options.fileName - Name of the translation file
  • options.language - Language version
  • options.secret - secret and apiKey are used for authentication
  • options.apiKey

getFiles(options)

Returns every files' information via promise.

The options object is required. Options include:

  • options.projectId - Numerical ID of the project
  • options.secret - secret and apiKey are used for authentication
  • options.apiKey

getMultilingualFile(options)

Downloads multi-language translations from OneSky.

Returns file content via promise.

The options object is required. Options include:

  • options.projectId - Numerical ID of the project
  • options.fileName - Name of the translation file
  • options.format - Response file format (Optional. Defaults to I18NEXT_MULTILINGUAL_JSON)
  • options.language - Language version
  • options.secret - secret and apiKey are used for authentication
  • options.apiKey

postScreenshot(options)

Uploads screenshot file to OneSky.

The options object is required. Options include:

  • options.projectId - Numerical ID of the project
  • options.secret - secret used for authentication
  • options.apiKey - apiKey used for authentication
  • options.name - A unique name to identify where the image located at your website, apps, blogs, etc... (Hints: path of the webpage)
  • options.image - Base64 encoded image data in Data URI scheme structure. Please reference to Data URI scheme and Base64
  • options.tags[] - Translations bind to the screenshot
  • options.tags[].key - Key of the translation
  • options.tags[].x - X-axis of the translation component
  • options.tags[].y - Y-axis of the translation component
  • options.tags[].width - Width of the translation component
  • options.tags[].height - Height of the translation component
  • options.tags[].file (Optional) - Name of the string file

postFile(options)

Uploads translation file to OneSky.

The options object is required. Options include:

  • options.projectId - Numerical ID of the project
  • options.fileName - Name of the translation file
  • options.language - Language version
  • options.format - File format (list here)
  • options.content String with the content of the file
  • options.keepStrings Boolean saying if already uploaded strings not present on this file should be deprecated or keept
  • options.allowSameAsOriginal Keep the translations that are the same as source text (Optional. Defaults to false)
  • options.secret - secret and apiKey are used for authentication
  • options.apiKey

Returns JSON API response content via promise. Example:

{
    "meta": {
        "status": 200,
        "record_count": 16
    },
    "data": [
        {
            "name": "translations.json",
            "string_count": 236,
            "last_import": {
                "id": 123,
                "status": "in-progress"
            },
            "uploaded_at": "2013-10-07T15:27:10+0000",
            "uploaded_at_timestamp": 1381159630
        }
    ]
}

getLanguages(options)

Get list of project languages.

The options object is required. Options include:

  • options.projectId - Numerical ID of the project
  • options.secret - secret and apiKey are used for authentication
  • options.apiKey

Returns JSON API response content via promise. Example:

{
    "meta": {
        "status": 200,
        "record_count": 2
    },
    "data": [
        {
            "code": "en-US",
            "english_name": "English (United States)",
            "local_name": "English (United States)",
            "locale": "en",
            "region": "US",
            "is_base_language": true,
            "is_ready_to_publish": true,
            "translation_progress": "100%",
            "uploaded_at": "2013-10-07T15:27:10+0000",
            "uploaded_at_timestamp": 1381159630
        },
        {
            "code": "ja-JP",
            "english_name": "Japanese",
            "local_name": "日本語",
            "locale": "ja",
            "region": "JP",
            "is_base_language": false,
            "is_ready_to_publish": true,
            "translation_progress": "98%",
            "uploaded_at": "2013-10-07T15:27:10+0000",
            "uploaded_at_timestamp": 1381159630
        }
    ]
}

Tests

$ npm test

License

MIT

版本与发布记录

@brainly/onesky-utils 共发布 7 个版本,首次发布于 2018/03/01;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.4.2latest2023/06/283 年前
1.4.12020/08/066 年前
1.4.02020/02/266 年前
1.3.22019/09/057 年前
1.3.12018/05/298 年前
1.3.02018/03/018 年前

关于 @brainly/onesky-utils 的常见问题

@brainly/onesky-utils 是什么?

Node.js utils for working with OneSky translation service.

如何安装 @brainly/onesky-utils?

在项目目录运行 npm install @brainly/onesky-utils,或使用 pnpm add / yarn add / bun add。

@brainly/onesky-utils 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/brainly__onesky-utils 是否存在。

@brainly/onesky-utils 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@brainly/onesky-utils 可以商用吗?

@brainly/onesky-utils 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@brainly/onesky-utils 的下载量有多少?

根据 npm 官方下载统计,@brainly/onesky-utils 在 2026/10/09 – 2026/11/07 这 30 天内被下载 13,546 次,日均约 452 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@brainly/onesky-utils 还在维护吗?

最新版本 1.4.2 发布于 2023/06/28(3 年前);至今共发布 7 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/03/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。