get-crowdin-file-ids

1.1.1 • Public • Published

get-crowdin-file-ids

Generate deep links to your content on Crowdin

Why?

Imagine you're serving up some Crowdin-translated content on your website and you want to add a link to each page that lets translators jump right into translating that content on the Crowdin site. Unfortunately, the URLs on Crowdin's translation pages are a bit cryptic. Here's an example:

https://crowdin.com/translate/electron/56/en-fr

Here 56 refers to Crowdin's internal id property for a given file.

This module creates a mapping between your filenames and their internal ids on Crowdin by fetching data from Crowdin's Project Details API and parsing its arcane response structure into a simple file-to-id map.

Installation

This module requires node 7 or greater because it uses async functions.

npm install get-crowdin-file-ids --save

Usage

Require the module:

const getIds = require('get-crowdin-file-ids')

The function expects a project name and Crowdin API key, and returns a promise:

const ids = await getIds('electron`, 'crowdinKey123')

If no API key is specified, it will fall back to the process.env.CROWDIN_KEY environment variable.

The result is an object mapping filenames to ids:

{
  'master/content/en-US/docs/glossary.md': '8',
  'master/content/en-US/docs/styleguide.md': '9',
  'master/content/en-US/docs/tutorial/about.md': '30'
}

Note how the paths above start with master. The Crowdin API returns a tree that includes the branch name as the top-level directory.

The ids can then be used to assemble URLs like this:

const url = `https://crowdin.com/project/${project}/${id}/${sourceLocale}-${targetLocale}`

Tests

npm install
npm test

Dependencies

  • got: Simplified HTTP requests

Dev Dependencies

  • chai: BDD/TDD assertion library for node.js and the browser. Test framework agnostic.
  • mocha: simple, flexible, fun test framework
  • nock: HTTP Server mocking for Node.js
  • standard: JavaScript Standard Style
  • standard-markdown: Test your Markdown files for Standard JavaScript Style™

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i get-crowdin-file-ids

Weekly Downloads

1

Version

1.1.1

License

MIT

Last publish

Collaborators

  • electronhq
  • zeke