Skip to content

Commit

Permalink
Merge pull request #11 from zakkudo/updateVersionsAddCli
Browse files Browse the repository at this point in the history
Update versions. Add cli interface
  • Loading branch information
zakkudo committed Feb 10, 2019
2 parents 25f0542 + c102ad8 commit 03c6777
Show file tree
Hide file tree
Showing 33 changed files with 4,437 additions and 4,620 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Expand Up @@ -7,7 +7,7 @@ insert_final_newline = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.{js}]
[*.js]
charset = utf-8
indent_style = space
indent_size = 2
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,4 +1,6 @@
node_modules
locales
.locales
build
yarn-error.log
documentation
Expand Down
4 changes: 1 addition & 3 deletions .travis.yml
@@ -1,11 +1,9 @@
language: node_js
cache: yarn
node_js:
- "6"
# - "7" NOT SUPPORTED BY fs-extra
- "8"
- "9"
- "10"
- "11"
install:
- yarn add --dev codecov snyk coveralls
script:
Expand Down
72 changes: 56 additions & 16 deletions README.md
Expand Up @@ -10,8 +10,10 @@ A library for scanning javscript files to build translation mappings in json aut

## Why use this?

- Automated code splittiing
- You no longer have to manage hierarchies of translations
- Designed for architectures leveraging dynamic imports, allowing splitting of the translations based off of file structure
- Includes a handy commandline program called `update-translations`
- Designed for architectures leveraging dynamic imports
- Templates are automatically generated for the translators where they only need to fill in the blanks
- The translations are annoted if they are new or unused as well as the file names and line numbers of usages
- Easy auditing for missing or non-updated translation strings with never running your application or enlisting QA
Expand Down Expand Up @@ -39,7 +41,26 @@ yarn add @zakkudo/translation-static-analyzer

## Setup
1. Wrap strings you want to be translated in `__('text')` or `__n('singlular', 'plural', number)` or `__p('context', 'text')` or `__np('context', 'singular', 'plural', number)` using a library like `@zakkudo/translator`
2. Initialize the analyzer in your build scripts similar to below.
2. Initialize the analyzer in your build scripts similar to below:
``` console
$ npm install -g @zakkudo/translation-static-analyzer
$ update-translations --help
usage: update-translations [--help] [--version] [--watch] [--templates=path] [--target=glob] [--debug] [--locales=es,fr] ...source-files-glob

A console application for updating gettext style translations in a javscript application.

-h/--help Show this help information.
-V/--version Show the program version.
-w/--watch Update the translations as the files change. ctrl-c to quit.
--templates=path The output target of the developer centric translations. A 'locale' directory will be created in this localition.
--target=glob The output target of the developer centric translations. A '.locale' directory will be created in this location.
--debug Show debugging messages.
-l/--locales=es,fr The locales to generate translation templates for, comma separated.
$ update-translations --target src --locales fr --templates . --debug 'src/**/*.js'
```

or you can use the api directly, which is used to make `@zakkudo/translate-webpack-plugin` and other handy wrappers:

``` javascript
const TranslationStaticAnalyzer = require('@zakkudo/translation-static-analyzer');
const analyzer = new TransalationStaticAnalyzer({
Expand Down Expand Up @@ -137,14 +158,37 @@ document.body.innerHTML = __n('There is one user', 'There are %d users', 2);

## Examples

### Use the command-line program, using the git repository of this project
```console
# Install the command globally
$ npm install -g @zakkudo/translation-static-analyzer
# Copy the project
$ git clone https://github.com/zakkudo/translation-static-analyzer.git
$ cd translation-static-analyzer/example/src
# Check out the help for the fun of it
$ update-translations --help
usage: update-translations [--help] [--version] [--watch] [--templates=path] [--target=glob] [--debug] [--locales=es,fr] ...source-files-glob

A console application for updating gettext style translations in a javscript application.

-h/--help Show this help information.
-V/--version Show the program version.
-w/--watch Update the translations as the files change. ctrl-c to quit.
--templates=path The output target of the developer centric translations. A 'locale' directory will be created in this localition.
--target=glob The output target of the developer centric translations. A '.locale' directory will be created in this location.
--debug Show debugging messages.
-l/--locales=es,fr The locales to generate translation templates for, comma separated.
# Generate some translations
$ update-translations --locales=es,fr
# View what was created
$ ls .locales # For the developers
$ ls ../locales # For the translators
```

### Configure the analyzer to build a single `.locales` directory
``` javascript
const TranslationStaticAnalyzer = require('@zakkudo/translation-static-analyzer');
const analyzer = new TransalationStaticAnalyzer({
files: 'src/**/*.js',
locales: ['es', 'fr'],
target: 'src'
});
``` console
$ npm install -g @zakkudo/translation-static-analyzer
$ update-translations --templates . --target src --locales es,fr 'src/**/*.js'
```

```
Expand All @@ -165,13 +209,9 @@ File Structure
```

### Configure the analyzer for a split `.locales` directory
``` javascript
const TranslationStaticAnalyzer = require('@zakkudo/translation-static-analyzer');
const analyzer = new TransalationStaticAnalyzer({
files: 'src/**/*.js',
locales: ['es', 'fr'],
target: 'src/pages/*'
});
``` console
$ npm install -g @zakkudo/translation-static-analyzer
$ update-translations --templates . --target 'src/pages/*' --locales es,fr 'src/**/*.js'
```

```
Expand Down
8 changes: 8 additions & 0 deletions example/src/README.md
@@ -0,0 +1,8 @@
Run

```console
npm install -g @zakkudo/translation-static-analyzer
update-translations --locales fr,es
```

To see how translations are generated! There will be a `locales` directory generated in the parent directory and a `.locales` generated in the `src` directory.
9 changes: 9 additions & 0 deletions example/src/index.js
@@ -0,0 +1,9 @@

import Translator from '@zakkudo/translator';

const translator = new Translator();
const { __, __n } = translator;

console.log(__('Lets see how this works!'));
console.log(__n("I'm going to eat %d apple!", "I'm going to eat %d apples!", 3));

42 changes: 25 additions & 17 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "@zakkudo/translation-static-analyzer",
"version": "0.2.2",
"description": "A library for generating localization files using static analysis of source files similar to gettext",
"version": "0.3.0",
"description": "A library for generating localization files using static analysis of source files similar to gettext with code splitting",
"keywords": [
"gettext",
"i18n",
Expand All @@ -10,40 +10,48 @@
"localization",
"localize",
"translate",
"translation"
"translation",
"code splitting"
],
"main": "index.js",
"files": [
"*"
],
"bin": {
"update-translations": "update-translations.js"
},
"engines": {
"node": ">=6.0.0 <7.0.0 || >=8.0.0"
"node": ">=8.0.0"
},
"repository": "github:zakkudo/translation-static-analyzer",
"license": "BSD-3-Clause",
"devDependencies": {
"@babel/cli": "^7.0.0-beta.56",
"@babel/core": "^7.0.0-beta.56",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/preset-env": "^7.0.0-beta.56",
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@babel/plugin-transform-classes": "^7.2.2",
"@babel/plugin-transform-runtime": "^7.2.0",
"@babel/preset-env": "^7.0.0",
"babel-core": "^7.0.0-0",
"babel-jest": "^23.4.2",
"babel-jest": "^24.0.0",
"babel-plugin-transform-define": "^1.3.1",
"babel-plugin-transform-undefined-to-void": "^6.9.4",
"eslint": "^4.19.1",
"eslint": "^5.12.1",
"eslint-plugin-jasmine": "^2.10.1",
"eslint-plugin-jest": "^21.21.0",
"eslint-plugin-node": "^7.0.1",
"jest": "^23.4.2",
"jest-cli": "^23.4.2",
"eslint-plugin-jest": "^22.1.3",
"eslint-plugin-node": "^8.0.1",
"jest": "^24.0.0",
"jest-cli": "^24.0.0",
"jsdoc": "^3.5.5",
"jsdoc-to-markdown": "^4.0.1"
},
"dependencies": {
"@babel/runtime-corejs2": "^7.0.0",
"@babel/runtime-corejs2": "^7.3.1",
"@zakkudo/argument-parser": "0.0.1",
"chokidar": "^2.0.4",
"deep-equal": "^1.0.1",
"fs-extra": "^7.0.0",
"fs-extra": "^7.0.1",
"glob": "^7.1.2",
"json5": "^1.0.1",
"json5": "^2.1.0",
"safe-eval": "^0.4.1"
},
"scripts": {
Expand Down
5 changes: 4 additions & 1 deletion src/.babelrc.js
@@ -1,3 +1,5 @@
const packageConfig = require('../package.json');

module.exports = {
"presets": [
[
Expand All @@ -13,7 +15,8 @@ module.exports = {
],
"plugins": [
["@babel/transform-runtime", {"corejs": 2}],
"transform-undefined-to-void"
"transform-undefined-to-void",
["transform-define", {"__VERSION__": packageConfig.version}]
],
minified: false, // When enabled, makes debuggers confused even with source maps
comments: false
Expand Down
45 changes: 24 additions & 21 deletions src/.eslintrc.js
@@ -1,24 +1,27 @@
module.exports = {
"extends": [
"eslint:recommended",
"plugin:node/recommended"
],
"env": {
"jasmine": true,
"jest/globals": true
},
"plugins": [
"jasmine",
"jest"
],
"parserOptions": {
"ecmaVersion": 6,
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
},
"rules": {
'max-len': ["error", { "code": 100, "comments": 120 }],
"no-console": "off"
"extends": [
"eslint:recommended",
"plugin:node/recommended"
],
"env": {
"jasmine": true,
"jest/globals": true
},
"globals": {
"__VERSION__": true
},
"plugins": [
"jasmine",
"jest"
],
"parserOptions": {
"ecmaVersion": 6,
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
},
"rules": {
'max-len': ["error", { "code": 100, "comments": 120 }],
"no-console": "off"
}
};
72 changes: 56 additions & 16 deletions src/README.md
Expand Up @@ -10,8 +10,10 @@ A library for scanning javscript files to build translation mappings in json aut

## Why use this?

- Automated code splittiing
- You no longer have to manage hierarchies of translations
- Designed for architectures leveraging dynamic imports, allowing splitting of the translations based off of file structure
- Includes a handy commandline program called `update-translations`
- Designed for architectures leveraging dynamic imports
- Templates are automatically generated for the translators where they only need to fill in the blanks
- The translations are annoted if they are new or unused as well as the file names and line numbers of usages
- Easy auditing for missing or non-updated translation strings with never running your application or enlisting QA
Expand Down Expand Up @@ -39,7 +41,26 @@ yarn add @zakkudo/translation-static-analyzer

## Setup
1. Wrap strings you want to be translated in `__('text')` or `__n('singlular', 'plural', number)` or `__p('context', 'text')` or `__np('context', 'singular', 'plural', number)` using a library like `@zakkudo/translator`
2. Initialize the analyzer in your build scripts similar to below.
2. Initialize the analyzer in your build scripts similar to below:
``` console
$ npm install -g @zakkudo/translation-static-analyzer
$ update-translations --help
usage: update-translations [--help] [--version] [--watch] [--templates=path] [--target=glob] [--debug] [--locales=es,fr] ...source-files-glob

A console application for updating gettext style translations in a javscript application.

-h/--help Show this help information.
-V/--version Show the program version.
-w/--watch Update the translations as the files change. ctrl-c to quit.
--templates=path The output target of the developer centric translations. A 'locale' directory will be created in this localition.
--target=glob The output target of the developer centric translations. A '.locale' directory will be created in this location.
--debug Show debugging messages.
-l/--locales=es,fr The locales to generate translation templates for, comma separated.
$ update-translations --target src --locales fr --templates . --debug 'src/**/*.js'
```

or you can use the api directly, which is used to make `@zakkudo/translate-webpack-plugin` and other handy wrappers:

``` javascript
const TranslationStaticAnalyzer = require('@zakkudo/translation-static-analyzer');
const analyzer = new TransalationStaticAnalyzer({
Expand Down Expand Up @@ -137,14 +158,37 @@ document.body.innerHTML = __n('There is one user', 'There are %d users', 2);

## Examples

### Use the command-line program, using the git repository of this project
```console
# Install the command globally
$ npm install -g @zakkudo/translation-static-analyzer
# Copy the project
$ git clone https://github.com/zakkudo/translation-static-analyzer.git
$ cd translation-static-analyzer/example/src
# Check out the help for the fun of it
$ update-translations --help
usage: update-translations [--help] [--version] [--watch] [--templates=path] [--target=glob] [--debug] [--locales=es,fr] ...source-files-glob

A console application for updating gettext style translations in a javscript application.

-h/--help Show this help information.
-V/--version Show the program version.
-w/--watch Update the translations as the files change. ctrl-c to quit.
--templates=path The output target of the developer centric translations. A 'locale' directory will be created in this localition.
--target=glob The output target of the developer centric translations. A '.locale' directory will be created in this location.
--debug Show debugging messages.
-l/--locales=es,fr The locales to generate translation templates for, comma separated.
# Generate some translations
$ update-translations --locales=es,fr
# View what was created
$ ls .locales # For the developers
$ ls ../locales # For the translators
```

### Configure the analyzer to build a single `.locales` directory
``` javascript
const TranslationStaticAnalyzer = require('@zakkudo/translation-static-analyzer');
const analyzer = new TransalationStaticAnalyzer({
files: 'src/**/*.js',
locales: ['es', 'fr'],
target: 'src'
});
``` console
$ npm install -g @zakkudo/translation-static-analyzer
$ update-translations --templates . --target src --locales es,fr 'src/**/*.js'
```

```
Expand All @@ -166,13 +210,9 @@ File Structure


### Configure the analyzer for a split `.locales` directory
``` javascript
const TranslationStaticAnalyzer = require('@zakkudo/translation-static-analyzer');
const analyzer = new TransalationStaticAnalyzer({
files: 'src/**/*.js',
locales: ['es', 'fr'],
target: 'src/pages/*'
});
``` console
$ npm install -g @zakkudo/translation-static-analyzer
$ update-translations --templates . --target 'src/pages/*' --locales es,fr 'src/**/*.js'
```

```
Expand Down

0 comments on commit 03c6777

Please sign in to comment.