UNPKG

646 BJavaScriptView Raw
1import path from 'path';
2import {writeFileSync} from 'fs';
3import {Compiler} from 'angular-gettext-tools';
4
5
6export default class ConvertPoToJson {
7 constructor(_dir) {
8 this.dir = _dir;
9 this.compiler = new Compiler({format: 'json'});
10 this.languageDir = path.resolve(_dir, 'translation');
11 this.convertedPath = path.resolve(this.languageDir, 'default.json');
12 }
13
14 convert(_pos) {
15 let converted = null;
16 try {
17 converted = JSON.parse(this.compiler.convertPo(_pos));
18 writeFileSync(this.convertedPath, JSON.stringify(converted, null, 2));
19 } catch (e) {
20 console.log(e);
21 }
22
23 return converted;
24 }
25}