Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.
/ better-crowdin Public archive
forked from cabify/better-crowdin

Crowdin CLI on steroids

License

Notifications You must be signed in to change notification settings

Webador/better-crowdin

 
 

Repository files navigation

DEPRECATION NOTICE

This project is no longer maintained, see cabify#39 for more info

better-crowdin

Crowdin CLI on steroids.

This CLI is based on Official CLI and adds several features like project translation status, list branches, delete branches, pretranslation etc. Moreover, it offers automatic sync between Git branches and Crowdin branches.

NOTE: This CLI doesn't cover 100% of the features of the official client and error handling is not polished. Please open PRs if you find something wrong.

Installation

$ npm install @jouwweb/better-crowdin

Configuration

In order to use inside your project, the easiest way is to have a crowdin.yml config file, with the same shape than the official client one, plus some new config options

project_identifier: 'your-project-identifier'
api_key: 'your-api-key'
base_path: 'your/base/path'

## New options

# List of Git branches that will not generate a Crowdin branch when uploading sources.
base_branches: ['master'] 

# List of Crowin language codes that will be ignored when calling "better-crowdin status.
skip_validation: ['ja', 'en', 'es-MX'] 

# Trigger automatic pretranslation for configured Crowdin language codes after upload.
pre_translation_engine: 'deepl'
pre_translation_languages: ['en', 'de', 'es-MX']

files:
  - source: 'path/to/*.pot'
    translation: '%two_letters_code%/%original_file_name%.po'
    languages_mapping:
      two_letters_code:
        ru: ros
        uk: ukr

Basic usage

$ better-crowdin [command]

Commands:
  better-crowdin delbranch         Delete the current or the given branch
  better-crowdin download          Download translations
  better-crowdin branches all      show all crowdin branches
  better-crowdin files             list sources and translations files

  better-crowdin status            Get translation status of the current branch
                                                                       [default]
  better-crowdin upload sources       Uploads the configured source files
  better-crowdin upload translations  Uploads the configured translations
  better-crowdin sync              Upload sources to crowdin & download translations


Options:
  --version        Show version number                                 [boolean]
  --config         Crowdin configuration file path [crowdin.yml]
  -d, --dry-run    Do not execute write operations on crowdin
  -b, --branch     Crowdin branch to use with command (defaults to current git
                   branch)                                              [string]
  --relative-path  Make "base_path" property relative to config file path
                                                                       [boolean]
  -h               Show help                                           [boolean]
  -p, --porcelain  Print script-aware outputs (no colors, no human friendly
                   info)                                               [boolean]

Advanced usage: Work with feature branches

The main advantage of this client over the official one is the work with Crowdin branches integrated with gitflow (feature branches).

Briefly, the steps to add new keys to crowdin when working with feature branches are:

  • When developing a feature branch
    • better-crowdin upload everytime you want to add new keys (will take branch name automatically)
    • better-crowdin download to download new keys already translated (will take branch name automatically)
  • When merging with base branch that has new keys
    • better-crowdin sync to upload new base branch keys to your branch & download latest translations
  • To check if the feature is fully translated (for instance in a pull request check script)
    • better-crowdin status
  • After merging with base branch
    • better-crowdin upload sources To upload merged base files
    • better-crowdin upload translations To upload merged translations
    • better-crowdin delbranch -b <branch_name> To remove finished branch
    • better-crowdin status To check everything is correct

Show me the code

  1. Your project has some strings already translated in master branch:
$ better-crowdin status
> better-crowdin status
- es-ES
   - src/locales/source.json. 10 / 10
- pt-PT
   - src/locales/source.json. 10 / 10
Everything fully translated. Enjoy!
  1. Then, you want to develop a feature with new translation keys:
  $ git checkout -b feature/my-new-feature
  ... (Add new key to "src/locales/source.json")
  1. After adding the new keys to the source files, you'll need to sync with crowdin
$ better-crowdin upload
> better-crowdin upload sources on feature_my-new-feature
- Creating feature_my-new-feature...OK
- src/locales/source.json...OK
  1. When content team translate new keys, you'll need to download them
$ better-crowdin download
> better-crowdin download on feature_my-new-feature
 - Building translations... BUILT
 - Downloading translations
   - src/locales/pt-PT.json
   - src/locales/es-ES.json

$ better-crowdin status
> better-crowdin status on feature_my-new-feature
- es-ES
   - src/locales/source.json. 1 / 1
- pt-PT
   - src/locales/source.json. 1 / 1
Everything fully translated. Enjoy!
  1. When someone else add new keys to master, you'll need to sync your branch to keep everything updated
$ better-crowdin sync
> better-crowdin upload sources on feature_my-new-feature
- Creating feature_my-new-feature...OK
- src/locales/source.json...OK
> better-crowdin download on feature_my-new-feature
 - Building translations... BUILT
 - Downloading translations
   - src/locales/pt-PT.json
   - src/locales/es-ES.json
  1. After everything is translated, you decide to merge the branch into master
  $ git checkout master
  $ git merge feature/my-new-feature (solve merge issues with translations)
  1. Then you'll need to sync again with crowdin, to add the feature keys to the main branch
$ better-crowdin upload sources; better-crowdin upload translations
> better-crowdin upload sources
- src/locales/source.json...OK
> better-crowdin upload translations
 - Uploading es-ES...OK
 - Uploading pt-PT...OK
  1. After that, you can remove the unused crowdin branch
$ better-crowdin delbranch -b feature_my-new-feature
> better-crowdin delbranch on feature_my-new-feature
OK
  1. Then, you can see that the new keys have been added to main branch
$ better-crowdin status
> better-crowdin status
- es-ES
   - src/locales/source.json. 11 / 11
- pt-PT
   - src/locales/source.json. 11 / 11
Everything fully translated. Enjoy!

Removing keys

If you remove some key/keys in your source.json file, only run the next commands:

> better-crowdin upload
> better-crowdin download