npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-i18n-extract-translations

v0.1.3

Published

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

Downloads

941

Readme

NPM version

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 and used it functionality for collecting keys.

Installation:

npm install vue-i18n-extract-translations --save-dev

or

yarn add -D vue-i18n-extract-translations

Usage :

Add to package.json:

{
  "scripts": {
    "vue-i18n-extract-translations": "vue-i18n-extract-translations"
  }
}

Common usage:

yarn vue-i18n-extract-translations -v <path_to_vue_files> -l <path_to_locales> [options]

or

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. 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.

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:

{
    "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:

{
    "Some long message": {
      "Love you" : "Love you"
    }  
}

Use option --key to prevent it:

yarn vue-i18n-extract-translations -v "./src/**/*.?(js|vue)" -l "./src/locales/" --key "i18n"

Now all dots in the strings will be ignored:

{
    "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:

{
    "Some long  message. Love you": "Some long  message. Love you",
    "i18n": {
        "header": {
            "message" : "header.message",
            "another_message" : "header.another_message"
         }
    }
}

###Default locale folder

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:

yarn vue-i18n-extract-translations -v "./src/**/*.?(js|vue)" -l "./src/locales/" --fill "" 

or not:

yarn vue-i18n-extract-translations -v "./src/**/*.?(js|vue)" -l "./src/locales/" --fill "Translate me!" 

###Save translations only to specified locales

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.