# vue-i18n-extract-translations

> Extract all translations of vue-i18n-extract to json files

Latest version **0.1.3** (published 2020-04-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install vue-i18n-extract-translations
pnpm add vue-i18n-extract-translations
yarn add vue-i18n-extract-translations
bun add vue-i18n-extract-translations
```

Provides the command `vue-i18n-extract-translations`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2020-04-13 |
| First published | 2020-04-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=12 |
| Dependencies | 5 |
| Unpacked size | 12.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Igor Gaponov |
| Maintainers | gapon2401 |
| Keywords | vue, vue i18n, vue i18n extract |

## Links

- npm: https://www.npmjs.com/package/vue-i18n-extract-translations
- Repository: https://github.com/gapon2401/vue-i18n-extract-translations
- npm.io page: https://npm.io/package/vue-i18n-extract-translations

## Dependencies (5)

- [yargs](https://npm.io/package/yargs.md) ^15.3.1
- [globby](https://npm.io/package/globby.md) ^11.0.0
- [dot-object](https://npm.io/package/dot-object.md) ^2.1.3
- [vue-i18n-extract](https://npm.io/package/vue-i18n-extract.md) ^1.0.3
- [nested-object-assign](https://npm.io/package/nested-object-assign.md) ^1.0.3

## Alternatives

- [messageformat](https://npm.io/package/messageformat.md) — 329.7K weekly downloads
- [@mintlify/scraping](https://npm.io/package/@mintlify/scraping.md) — 294.8K weekly downloads
- [@mintlify/previewing](https://npm.io/package/@mintlify/previewing.md) — 209.5K weekly downloads
- [@mintlify/prebuild](https://npm.io/package/@mintlify/prebuild.md) — 209.5K weekly downloads
- [@mintlify/link-rot](https://npm.io/package/@mintlify/link-rot.md) — 206.3K weekly downloads

## Recent versions

- 0.1.3 (latest) — 2020-04-13
- 0.1.2 — 2020-04-13
- 0.1.1 — 2020-04-13

## README

<h1>vue-i18n-extract-translations</h1>

[![NPM version][npm-image]][npm-url]

`vue-i18n-extract-translations` allows you to get key-based and message locale strings from your `*.vue` and `*.js` files and save them to json files.
       
Based on [vue-i18n-extract](https://www.npmjs.com/package/vue-i18n-extract) and used it functionality for collecting keys.

## Installation:

```bash
npm install vue-i18n-extract-translations --save-dev
```
or
```bash
yarn add -D vue-i18n-extract-translations
```

## Usage :

Add to `package.json`:

```json
{
  "scripts": {
    "vue-i18n-extract-translations": "vue-i18n-extract-translations"
  }
}
```

Common usage:

```bash
yarn vue-i18n-extract-translations -v <path_to_vue_files> -l <path_to_locales> [options]
```

or

```bash
npm run vue-i18n-extract-translations -v <path_to_vue_files> -l <path_to_locales> [options]
```

### All options

Option        | Default    | Necessity  | Description
------------- | ---------- | ---------- | -----------
-v            |            | required   | Pattern path to vue files
-l            |            | required   | Pattern path to locale json files. <br> Automatically creates specified directory
--key         | ""         | optional   | Prefix for key-based translations. By default is empty
--def-locale  | en_US      | optional   | Default locale name. Option creates json file, if locales were not found
--keep-unused | false      | optional   | Keep old unused keys in locale files 
--fill        |            | optional   | Fill new translations with specified string. By default all new translation values equals their keys
-t, --target  | array      | optional   | List of locales to process. By default all locales will be processed.
-h, --help    |            | optional   | Show help
   
## Examples

###Extract all missing translations to json locale files.

```bash
yarn vue-i18n-extract-translations -v "./src/**/*.?(js|vue)" -l "./src/locales/"
```

Paths can be absolute or relative.

###Key-based format translations

By default script uses key-based format and extract dot strings as objects.

Your locale strings probably looks like: `$t('header.message')`, `$t('header.another_message')` or `$t('single_message')`. 

Generated json file will be: 

```json
{
    "header": {
      "message" : "header.message",
      "another_message" : "header.another_message"
    },
    "single_message": "single_message"  
}
```
###Message format translations

Your locale strings probably looks like: `$t('Some long  message. Love you')`

By default script will create such json file: 

```json
{
    "Some long message": {
      "Love you" : "Love you"
    }  
}
```

Use option `--key` to prevent it:

```bash
yarn vue-i18n-extract-translations -v "./src/**/*.?(js|vue)" -l "./src/locales/" --key "i18n"
```

Now all dots in the strings will be ignored: 

```json
{
    "Some long  message. Love you": "Some long  message. Love you"
}
```

###Combine key-based and message format

You may have both formats: `$t('header.message')`, `$t('header.another_message')`, `$t('Some long  message. Love you')`.

Use option `--key` with value `i18n` and change key-based strings like so: `$t('i18n.header.message')`, `$t('i18n.header.another_message')`

Result json:

```json
{
    "Some long  message. Love you": "Some long  message. Love you",
    "i18n": {
        "header": {
            "message" : "header.message",
            "another_message" : "header.another_message"
         }
    }
}
```

###Default locale folder

```bash
yarn vue-i18n-extract-translations -v "./src/**/*.?(js|vue)" -l "./src/locales/" --def-locale "fr_FR"
```

If locale directory is empty, script will create it and save translations to fr_FR.json file:

###Keep new translations empty

If you don't want the values of new translations to be keys, use option `--fill`.

You can make them empty:

```bash
yarn vue-i18n-extract-translations -v "./src/**/*.?(js|vue)" -l "./src/locales/" --fill "" 
```

or not:

```bash
yarn vue-i18n-extract-translations -v "./src/**/*.?(js|vue)" -l "./src/locales/" --fill "Translate me!" 
```

###Save translations only to specified locales

```bash
yarn vue-i18n-extract-translations -v "./src/**/*.?(js|vue)" -l "./src/locales/" --target "en_US" "ru_RU" 
```

This command will save translations only to en_US.json and ru_RU.json files. Nonexistent files will be created automatically.

[npm-url]: https://www.npmjs.com/package/vue-i18n-extract-translations
[npm-image]: https://img.shields.io/npm/v/vue-i18n-extract-translations

---
_Source: https://npm.io/package/vue-i18n-extract-translations · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
