<commit_before>ng-translation-gen: Translation message accessors generator for Angular 2+.
---

This project is a NPM module that generates TypeScript classes from a JSON file
containing the translation keys used by an application.

## Rationale:
The idea of this project is to overcome the problems we found regarding I18N in 
an Angular 2 application:
- If using AOT compilation there is need for a separate application package for 
  each language (and also serve each one separately).
- Lack of possibility to translate a string that is not in a template but in code.
- Change from diferents translations dinamically.

## How to generate the classes:
In your project, run:
```bash
cd <your_angular2+_app_dir>
npm install ng-translation-gen --save-dev
node_modules/.bin/ng-translation-gen [-i input_dir] [-o output_dir]
```
Where:

- `input_dir` is the directory where the translation files reside.
  The default inoput directory if nothing is specified is `src/app/translations`.
- `output_dir` is the directory where the generated code will be outputted. It
  is recommended that this directory is ignored on GIT (or whatever source
  control software you are using), for example, by adding its name to
  `.gitignore`. The default output directory if nothing is specified is
  `src/app/messages`.

Please, run the `ng-translation-gen` with the `--help` argument to view all
available command line arguments.

## How to use it in your angular project:
Define a module as follow:
```typescript
import { BrowserModule } from '@angular/platform-browser';
import { NgModule, Provider, APP_INITIALIZER } from '@angular/core';
import { HttpModule, Http } from '@angular/http';

import { SystemMessages } from 'app/messages/system-messages';
import { AccessMessages } from 'app/messages/access-messages';


import { AppComponent } from './app.component';

import 'rxjs/add/operator/toPromise';

/**
 * This function will be executed when the application is initialized.
 * It loads the system translations.
 */
export function loadSystemMessages(system: SystemMessages, http: Http): Function {
  return () => http.get("assets/system-messages.json")
    .toPromise()
    .then(response => {<commit_msg>Documentation improvements<commit_after>ng-translation-gen: Translation message accessors generator for Angular 2+.
---

This project is a NPM module that generates TypeScript classes from a JSON file
containing the translation keys used by an application.

## Rationale:
The idea of this project is to overcome the problems we found regarding I18N in 
an Angular 2 application:
- If using AOT compilation there is need for a separate application package for 
  each language (and also serve each one separately).
- Lack of possibility to translate a string that is not in a template but in code.
- Change from diferents translations dinamically.

## How to generate the classes:
In your project, run:
```bash
cd <your_angular2+_app_dir>
npm install ng-translation-gen --save-dev
node_modules/.bin/ng-translation-gen [-i input_dir] [-o output_dir]
```
Where:

- `input_dir` is the directory where the translation files reside.
  The default inoput directory if nothing is specified is `src/app/translations`.
- `output_dir` is the directory where the generated code will be outputted. It
  is recommended that this directory is ignored on GIT (or whatever source
  control software you are using), for example, by adding its name to
  `.gitignore`. The default output directory if nothing is specified is
  `src/app/messages`.

Please, run the `ng-translation-gen` with the `--help` argument to view all
available command line arguments.

## How to use it in your Angular project:
Define a module as follow:
```typescript
import { BrowserModule } from '@angular/platform-browser';
import { NgModule, Provider, APP_INITIALIZER } from '@angular/core';
import { HttpModule, Http } from '@angular/http';

import { SystemMessages } from 'app/messages/system-messages';
import { AccessMessages } from 'app/messages/access-messages';


import { AppComponent } from './app.component';

import 'rxjs/add/operator/toPromise';

/**
 * This function will be executed when the application is initialized.
 * It loads the system translations.
 */
export function loadSystemMessages(system: SystemMessages, http: Http): Function {
  return () => http.get("assets/system-messages.json")
    .toPromise()
    .then(response => {
{'fraction_non_alphanumeric': 0.08573372646858698, 'fraction_numerical': 0.0022680880018144706, 'mean_word_length': 4.498753117206983, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4239269', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1136, 'n_words': 529}