# epom-ng2-language-service
A service that allows you to create language constants and use them in the project, in components and templates.

### Installing

First of all you need to install module from npm

```sh
$ npm i --save epom-ng2-language-service
```
And provide it in your App.module

```javascript
import {LanguageService} from 'epom-ng2-language-service';
...
providers: [
  LanguageService,
  ...
];
```
And inject it in your App.component in order to set messages object into LanguageService
```javascript
    export class AppComponent {
  constructor(private lang: LanguageService) {
  this.lang.setMessage('MESSAGE_KEY', 'message');
}
}
```
## Parts
    .
    |-- epom-ng2-language-service
    |   |-- lang_en
    |   |   |-- messages.ts
    |   |   |-- ...
    |   |   |-- another-messages.ts
    |   |-- index



## Service public methods
| Method Declaration                                                      | Description |
| ----------------------------------------------------------------------- | ----------- |
| .**setMessages**(messages: {[message: string]: string}): void | Setting messages object to languageService, and it will seek current messages in this object |
|**print**(phrase: string, vars: Array<any>): string | find current string by language constant; if in message string was found substring '%s' it can be replaced with element from `vars` (second argument). |
| .**setMessage**(key: string, message: string): void | add single custom message to messages object |

Examples:
```javascript
//Setting messages
const MESSAGES = {
  message: 'This is my %s message
}
this.lang.setMessages(MESSAGES);
this.lang.setMessage('TERMS_TEXT', 'terms text');
this.lang.print('message', ['first']); // This is my first message
```

## Contributors
Gennady Strelets <g.strelets@itmgmedia.net>
