Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

i18nexus-cli

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18nexus-cli - npm Package Compare versions

Comparing version 2.1.0 to 3.0.0

baseUrl.js

153

bin/index.js

@@ -5,3 +5,7 @@ #!/usr/bin/env node

const program = require('commander');
const pull = require('../pull');
const pull = require('../commands/pull');
const addString = require('../commands/addString');
const updateString = require('../commands/updateString');
const deleteString = require('../commands/deleteString');
const importJson = require('../commands/importJson');

@@ -12,3 +16,5 @@ // Using Next's env variable loader because

loadEnvConfig(process.cwd());
if (process.env.I18NEXUS_NO_DOT_ENV !== 'true') {
loadEnvConfig(process.cwd());
}

@@ -49,2 +55,145 @@ program.version(pkg.version);

program
.command('add-string')
.alias('a')
.description('Add a new base string to a namespace')
.requiredOption(
'-k, --api-key <apiKey>',
'The API key for your project',
process.env.I18NEXUS_API_KEY
)
.requiredOption(
'-t, --pat <personalAccessToken>',
'A personal access token generated for your account in i18nexus.',
process.env.I18NEXUS_PERSONAL_ACCESS_TOKEN
)
.requiredOption('-K, --key <stringKey>', 'The key of the string to create')
.requiredOption(
'-v, --value <stringValue>',
'The value of the string to create'
)
.requiredOption(
'-ns, --namespace <stringNamespace>',
'The namespace in which to create the string'
)
.option(
'-d, --details <stringDetails>',
'The details of the string to create (optional)'
)
.action(options => {
addString({
key: options.key,
value: options.value,
details: options.details,
namespace: options.namespace,
apiKey: options.apiKey,
pat: options.pat
});
});
program
.command('update-string <namespaceOfString> <keyOfString>')
.alias('u')
.description('Update a base string through PATCH request')
.requiredOption(
'-k, --api-key <apiKey>',
'The API key for your project',
process.env.I18NEXUS_API_KEY
)
.requiredOption(
'-t, --pat <personalAccessToken>',
'A personal access token generated for your account in i18nexus.',
process.env.I18NEXUS_PERSONAL_ACCESS_TOKEN
)
.option('-K, --key <stringKey>', 'The new key of the string')
.option('-v, --value <stringValue>', 'The new value of the string')
.option(
'-ns, --namespace <stringNamespace>',
'The new namespace of the string'
)
.option('-d, --details <stringDetails>', 'The new details of the string')
.option(
'--reset-confirmed',
'Reset confirmed translations of this string with machine translations.'
)
.option(
'--retain-confirmed',
'Do not reset confirmed translations of this string with machine translations.'
)
.action((namespaceOfString, keyOfString, options) => {
updateString({
id: {
namespace: namespaceOfString,
key: keyOfString
},
key: options.key,
value: options.value,
details: options.details,
namespace: options.namespace,
apiKey: options.apiKey,
pat: options.pat,
resetConfirmed: options.resetConfirmed,
retainConfirmed: options.retainConfirmed
});
});
program
.command('delete-string <namespaceOfString> <keyOfString>')
.alias('d')
.description('Delete a base string and its translations')
.requiredOption(
'-k, --api-key <apiKey>',
'The API key for your project',
process.env.I18NEXUS_API_KEY
)
.requiredOption(
'-t, --pat <personalAccessToken>',
'A personal access token generated for your account in i18nexus.',
process.env.I18NEXUS_PERSONAL_ACCESS_TOKEN
)
.action((namespaceOfString, keyOfString, options) => {
deleteString({
id: {
namespace: namespaceOfString,
key: keyOfString
},
apiKey: options.apiKey,
pat: options.pat
});
});
program
.command('import <filePath>')
.description(
'Import base strings into your i18nexus project from a local JSON file.'
)
.requiredOption(
'-k, --api-key <apiKey>',
'The API key for your project',
process.env.I18NEXUS_API_KEY
)
.requiredOption(
'-t, --pat <personalAccessToken>',
'A personal access token generated for your account in i18nexus.',
process.env.I18NEXUS_PERSONAL_ACCESS_TOKEN
)
.requiredOption(
'-ns, --namespace <namespace>',
'The namespace in which your strings will be imported.'
)
.option(
'--overwrite',
'If any keys already exist in the target namespace, overwrite the values with the imported values.',
false
)
.action((filePath, options) => {
importJson({
apiKey: options.apiKey,
path: filePath,
overwrite: options.overwrite,
namespace: options.namespace,
pat: options.pat
});
});
program.parse(process.argv);

6

package.json
{
"name": "i18nexus-cli",
"version": "2.1.0",
"version": "3.0.0",
"description": "Command line interface (CLI) for accessing the i18nexus API",

@@ -10,5 +10,5 @@ "main": "index.js",

"keywords": [
"i18next",
"i18nexus",
"cli"
"cli",
"i18next"
],

@@ -15,0 +15,0 @@ "author": "i18nexus",

# i18nexus-cli
**A command line interface for accessing translations from the i18nexus API**
**A command line interface for accessing and managing translations through the i18nexus API**
## New to i18nexus?
[i18nexus](https://i18nexus.com) is a translation management web application designed for use with i18next. Learn more with this [5 minute React walkthrough](https://javascript.plainenglish.io/react-localization-the-winner-is-i18next-i18nexus-b7cd9f14094e) or visit our [Quick Integration guide](https://i18nexus.com/quick-integration).
[i18nexus](https://i18nexus.com) is a translation management web application designed for use with i18next. Learn more with this quick [Next.js walkthrough](https://i18nexus.com/nextjs-tutorial) or this [React.js walkthrough](https://i18nexus.com/react-tutorial).
## Who is this CLI meant for?
- Developers using SSR/SSG or libraries such as [next-i18next](https://github.com/isaachinman/next-i18next)
- Developers who prefer to bundle their translation files with their app
- Developers who prefer to download and bundle their translation files with their app (especially useful for those who use SSR/SSG and libraries such as [next-i18next](https://github.com/isaachinman/next-i18next)).
- Developers who wish to add, edit, or delete strings in their i18nexus project from the command line.
The primary motivation for this CLI is to ease i18nexus integration with SSR/SSG frameworks such as NextJS. It is the best way to integrate i18nexus with [next-i18next](https://github.com/isaachinman/next-i18next).
## Installation
## Setup
### 1. Installation
```sh

@@ -24,6 +20,10 @@ npm install -g i18nexus-cli

### 2. Downloading your translations
## Environment Variables
The commands below have options that can be set with environment variables. Since the majority of our users are using this package in the context of their web or mobile application, this package will load the `.env` file in the current working directory to check for i18nexus variables. If you would prefer not to load your `.env` file, you can run `export I18NEXUS_NO_DOT_ENV=true`.
## Downloading your translations
```sh
i18nexus pull -k <YOUR_PROJECT_API_KEY>
i18nexus pull -k <PROJECT_API_KEY>
```

@@ -47,6 +47,4 @@

#### Options
### Options
`i18nexus pull`
| Option | Default value |

@@ -59,3 +57,3 @@ | ------------------- | ------------------ |

#### Details
### Notes

@@ -73,1 +71,161 @@ `--api-key`

Before download, clears your destination folder specified in --path. As a safety precaution, this only deletes folders with names that match a simple language code regex. You should still ensure you are not storing any files in your destination folder that you do not want deleted.
## Personal Access Tokens
The following commands require a Personal Access Token (PAT) because they write data to your i18nexus project. PATs are created in your i18nexus account dashboard.
REMEMBER: Keep these tokens a secret and do NOT publish them to any public code repositories such as Github. They should never be client facing. Treat each token as if it is your i18nexus password.
## Adding new strings
`i18nexus add-string` or `i18nexus a`
```sh
i18nexus a -K 'welcome_msg' -v 'Welcome to my app!' -ns 'common' -k <PROJECT_API_KEY> -t <YOUR_PERSONAL_ACCESS_TOKEN>
```
The above snippet will create a new string in your i18nexus project in your `common` namespace.
Translations for the string will be automatically generated and machine translated for all of your project's languages, just as if you added the string manually in the i18nexus web application.
### Options
| Option | Required? |
| ---------------------- | --------- |
| `--api-key` or `-k` | &#10004; |
| `--pat` or `-t` | &#10004; |
| `--namespace` or `-ns` | &#10004; |
| `--key` or `-K` | &#10004; |
| `--value` or `-v` | &#10004; |
| `--details` or `-d` | |
### Notes
`--api-key`
Your project API key (Can also be set using environment variable `I18NEXUS_API_KEY`)
`--pat`
A personal access token that you have generated in your i18nexus account (Can also be set using environment variable `I18NEXUS_PERSONAL_ACCESS_TOKEN`)
`--namespace`
The namespace in which to create the string
`--key`
The key of the string to create
`--value`
The value of the string to create
`--details`
The details of the string to create (optional)
## Updating existing strings
`i18nexus update-string <namespace> <key>` or `i18nexus u <namespace> <key>`
```sh
i18nexus u common welcome_msg -v 'Welcome' -k <PROJECT_API_KEY> -t <YOUR_PERSONAL_ACCESS_TOKEN>
```
The above snippet will update a the value of the string with key `welcome_msg` in your `common` namespace to `Welcome`.
The first 2 arguments are the namespace and the key of the string you wish to update.
You can then update the key, value, details, and/or namespace by using the command options:
### Options
| Option | Required? |
| ---------------------- | --------- |
| `--api-key` or `-k` | &#10004; |
| `--pat` or `-t` | &#10004; |
| `--namespace` or `-ns` | |
| `--key` or `-K` | |
| `--value` or `-v` | |
| `--details` or `-d` | |
| `--reset-confirmed` | |
| `--retain-confirmed` | |
### Notes
`--api-key`
Your project API key (Can also be set using environment variable `I18NEXUS_API_KEY`)
`--pat`
A personal access token that you have generated in your i18nexus account (Can also be set using environment variable `I18NEXUS_PERSONAL_ACCESS_TOKEN`)
`--namespace`
The new namespace of the string
`--key`
The new key of the string
`--value`
The new value of the string
`--details`
The new details of the string
#### If you are updating the value of a string that contains translations that have been marked confirmed in i18nexus, you will be required to include one of the following options to your command:
`--reset-confirmed`
Confirmed translations of this string will be reset with machine translations of the new value
`--retain-confirmed`
Confirmed translations of this string will be retained
## Deleting strings
`i18nexus delete-string <namespace> <key>` or `i18nexus d <namespace> <key>`
```sh
i18nexus d common welcome_msg -k <PROJECT_API_KEY> -t <YOUR_PERSONAL_ACCESS_TOKEN>
```
The above snippet will delete the string `welcome_msg` from your `common` namespace, along with its associated translations.
### Options
| Option | Required? |
| ------------------- | --------- |
| `--api-key` or `-k` | &#10004; |
| `--pat` or `-t` | &#10004; |
### Notes
`--api-key`
Your project API key (Can also be set using environment variable `I18NEXUS_API_KEY`)
`--pat`
A personal access token that you have generated in your i18nexus account (Can also be set using environment variable `I18NEXUS_PERSONAL_ACCESS_TOKEN`)
## Importing strings into your i18nexus project
`i18nexus import <filePath>`
```sh
i18nexus import ./en.json -ns common -k <PROJECT_API_KEY> -t <YOUR_PERSONAL_ACCESS_TOKEN>
```
The above snippet will read the contents of `./en.json` and import them into the base language of your i18nexus project.
This is the equivalent of using the Import tool in the i18nexus web application. However, this CLI command only allows for uploading a JSON file for your base language.
### Options
| Option | Required? |
| ------------------- | --------- |
| `--api-key` or `-k` | &#10004; |
| `--pat` or `-t` | &#10004; |
| `--overwrite` | |
### Notes
`--api-key`
Your project API key (Can also be set using environment variable `I18NEXUS_API_KEY`)
`--pat`
A personal access token that you have generated in your i18nexus account (Can also be set using environment variable `I18NEXUS_PERSONAL_ACCESS_TOKEN`)
`--overwrite`
If any keys already exist in the target namespace, overwrite the values with the imported values.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc