Test Failed
Push — develop ( 424bfb...c8c23d )
by Endre
02:45
created

Translator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 16
dl 0
loc 19
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A translate 0 12 3
1
export interface IValueMap {
2
  [pattern: string]: string
3
}
4
5
export interface ILanguageData {
6
  [key: string]: string
7
}
8
9
export default class Translator {
10
  language: ILanguageData;
11
12
  constructor(languageData: ILanguageData) {
13
    this.language = languageData;
14
  }
15
16
  public translate(key: string, valueMap: IValueMap = {}) {
17
    if (this.language.hasOwnProperty(key)) {
18
      let translated = String(this.language[key]);
19
      for (let pattern in valueMap) {
20
        translated = translated.replace(new RegExp('{' + pattern + '}', 'g'), valueMap[pattern]);
21
      }
22
23
      return translated;
24
    }
25
26
    return key;
27
  }
28
}