Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Resolve locale properly

* Clean constructor

* Use state instead of passing in argument
  • Loading branch information
auxves authored and shanalikhan committed Jun 19, 2019
1 parent 272273e commit 91cb127
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/localize.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from "fs-extra";
import * as path from "path";
import { extensions } from "vscode";
import { state } from "./state";

interface IConfig {
locale?: string;
Expand All @@ -12,7 +13,7 @@ interface ILanguagePack {

export class Localize {
private bundle: ILanguagePack;
constructor(private options: IConfig = {}) {}
private options: IConfig;
/**
* translate the key
* @param key
Expand All @@ -24,6 +25,26 @@ export class Localize {
return this.format(message, args);
}
public async init() {
this.options = {
locale: "en"
};

try {
const pathToLocale = path.resolve(
state.environment.USER_FOLDER,
"locale.json"
);
if (fs.existsSync(pathToLocale)) {
const contents = fs.readFileSync(pathToLocale, "utf-8");
this.options = {
...this.options,
...(contents ? JSON.parse(contents) : {})
};
}
} catch (err) {
//
}

this.bundle = await this.resolveLanguagePack();
}
/**
Expand Down Expand Up @@ -100,20 +121,7 @@ export class Localize {
}
}

let config: IConfig = {
locale: "en"
};

try {
config = Object.assign(
config,
JSON.parse((process.env as any).VSCODE_NLS_CONFIG)
);
} catch (err) {
//
}

const instance = new Localize(config);
const instance = new Localize();

const init = instance.init.bind(instance);

Expand Down

0 comments on commit 91cb127

Please sign in to comment.