Giter Site home page Giter Site logo

traduora-cli's Introduction

Traduora CLI

CLI for traduora translation management

Config

Options are set using one of the following

package.json property "traduora"
.tradourarc
.traduorarc.json
.traduorarc.yaml
.traduorarc.yml
.traduorarc.js
traduora.config.js

In combination with all-caps snake cased variants of the property names in process.env, prefixed with TR. E.g TR_BASE_URL is equivalent to base-url in config files.

Note that the prefix itself is also configurable but it can not be set via environment variables.

CLI Script

CLI-Scripts are usable as npm scripts:

Example package.json scripts:

    "//": "make traduora cli accessible in the project directory context -> ease of use for build steps",
    "traduora": "traduora"

If you want to have your environment defined in a .env file, you can use dotenv, too:

    "traduora": "node --require 'dotenv/config' ./node_modules/.bin/traduora"

pull

To fetch the translated terms, run

traduora --task pull
# short:
traduora -t pull

push

To perform remote creation for each new term found in push-from

traduora --task push
# short:
traduora -t push

Input files must be jsonflat. Input files are matched with glob patterns. The message keys must be unique across all aggregated files.

example

{
  "menu.home.button": "Home",
  "messages.welcome": "Welcome {user.displayName}"
}

How to use a unsuited input json schema

In order to transform the output of babel-plugin-react-intl to the desired format, consider using jq.

As an example

jq --slurp --sort-keys \
  'add | reduce .[] as $item ({} ; . + {"\($item.id)": $item.defaultMessage})' \
   ./intl/push/**/*.json \
   >| intl/push/aggregated.jsonflat

Which might be used as a preliminary step ahead of pushing the translations to traduora. Combined with dotenv:

...
  "traduora": "node --require 'dotenv/config' ./node_modules/.bin/traduora"
  "preintl:push": "jq --slurp --sort-keys 'add | reduce .[] as $item ({} ; . + {\"\\($item.id)\": $item.defaultMessage})' $(find ./intl/push/* -name \"*.json\") >| build/messages/aggregated.jsonflat",
  "intl:push": "npm run traduora -- -t push",

In conjunction with traduora-config

"push-from": "<rootDir>/intl/push/aggregated.jsonflat",

translations

traduora --task translations --output ./locales.json
# short:
traduora -t translations -o ./locales.json

Obtains the locale codes which have translations. For example the resulting ./locales.json may look like

{
  "de_DE": {
    "region": "Germany",
    "language": "German",
    "id": "0ab1eed9-f98a-465a-93fd-6b3a67353164"
  },
  "en_GB": {
    "region": "United Kingdom",
    "language": "English",
    "id": "544b64bb-2679-41fb-b39b-5758edbe092a"
  }
}

Options:

Strings containing <rootDir>, <locale> or <hash:\d+> will be interpolated. Examples:

  • <rootDir> will be replaced with the absolute Path to the project root
  • <locale> will be replaced respective of context.
  • <hash:6> will be replaced with the hash of the respective file, shortened to 6 characters.
property value env var (default)
client-id {String} client id for the client credentials flow TR_CIENT_ID
client-secret {String} Warning take care not to expose it in version control
client key for the client credentials flow
TR_CIENT_SECRET
project-id {String} traduora project ID TR_PROJECT_ID
base-url {String} <scheme>://<host>/<basePath> โ€“ e.g. https://traduora.example.com/ TR_BASE_URL
base-path {String} most likely /api/v1/ is correct TR_BASE_PATH
env-prefix {String="TR"} Prefix to assume when interpolating environment variables for config options. n/a
locale {String} locale for authoring translation terms n/a
locales {Array<String>} locales to obtain from traduora n/a
pull-to {String="<rootDir>/intl/pull/<locale>.<hash:6>.json"} TBD n/a
push-from {GlobString,Array<GlobString}=["<rootDir>/intl/push/**/<locale>.json"] The interpolated Paths are serving as a pattern for globby n/a
pull-format {String="jsonflat"} TBD n/a
root-dir {[String]} Means to override <rootDir> TR_ROOT_DIR
max-retry {Integer=5} Retries if API calls fail n/a

Semver

Until traduora-cli reaches a 1.0 release, breaking changes will be released with a new minor version. For example 0.5.1, and 0.5.4 will have the same API, but 0.6.0 will have breaking changes.

Recommendations

Using React?

Let your react components be the source of truth where i18n key-value pairs come to existence. Try

Using Eslint?

traduora-cli's People

Contributors

iilei avatar jekiwijaya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

traduora-cli's Issues

enhancements planned

  • task: rm-stale
    to remove all remote terms that are not in the aggregated local translations
  • option: --force
    applicable on push task, overrides terms that are already defined remote
  • in case pull-to option contains <hash.*> - write a mapping file to i18n-map โœ…

Refactoring:
use habitat

error, because data in camelCase

Hello, I tried to use this, and I getting error

{
  "error": {
    "message": "Request failed with status code 400",
    "data": "{\"grantType\":\"client_credentials\",\"clientId\":\"xxx\",\"clientSecret\":\"xxx\"}"
  }
}

As I see, everything in this code is in camcelCase
https://github.com/iilei/traduora-cli/blob/master/src/modules/getAuthToken.js#L6-L8

but in swagger, everything is snake_case

https://docs.traduora.com/docs/api/v1/swagger/#/Authentication/post_api_v1_auth_token

How you can get this work?

Thank you

@iilei

Error in nodejs package v0.12.0

Hi,
In v0.12.0 the package has not been updated in getAuthToken it still has wrong method: return response.data.data.accessToken;
can you make a new release? the github release is fine

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.