"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MainThreadLocalization = void 0;
const tslib_1 = require("tslib");
const di_1 = require("@opensumi/di");
const ide_connection_1 = require("@opensumi/ide-connection");
const ide_core_browser_1 = require("@opensumi/ide-core-browser");
const ide_file_service_1 = require("@opensumi/ide-file-service");
const common_1 = require("../../../common");
const vscode_1 = require("../../../common/vscode");
const ext_types_1 = require("../../../common/vscode/ext-types");
let MainThreadLocalization = class MainThreadLocalization {
    constructor(rpcProtocol) {
        this.rpcProtocol = rpcProtocol;
        this.proxy = this.rpcProtocol.getProxy(vscode_1.ExtHostAPIIdentifier.ExtHostLocalization);
        this.currentLanguage = this.preferenceService.get('general.language', 'en').toLocaleLowerCase();
        this.proxy.$setCurrentLanguage(this.currentLanguage);
    }
    async $fetchBuiltInBundleUri(id, language) {
        try {
            // 当插件为内置插件时，从 Language Packs 中获取
            const languagePack = await this.extensionNodeClient.getLanguagePack(language || this.currentLanguage);
            if (languagePack && languagePack.translations[id]) {
                return ext_types_1.Uri.file(languagePack.translations[id]);
            }
            return undefined;
        }
        catch (e) {
            return undefined;
        }
    }
    async $fetchBundleContents(uriComponents) {
        const contents = await this.fileService.readFile(ext_types_1.Uri.revive(uriComponents).fsPath.toString());
        return contents.content.toString();
    }
};
exports.MainThreadLocalization = MainThreadLocalization;
tslib_1.__decorate([
    (0, di_1.Autowired)(ide_file_service_1.IFileServiceClient),
    tslib_1.__metadata("design:type", Object)
], MainThreadLocalization.prototype, "fileService", void 0);
tslib_1.__decorate([
    (0, di_1.Autowired)(ide_core_browser_1.PreferenceService),
    tslib_1.__metadata("design:type", Object)
], MainThreadLocalization.prototype, "preferenceService", void 0);
tslib_1.__decorate([
    (0, di_1.Autowired)(common_1.ExtensionNodeServiceServerPath),
    tslib_1.__metadata("design:type", Object)
], MainThreadLocalization.prototype, "extensionNodeClient", void 0);
exports.MainThreadLocalization = MainThreadLocalization = tslib_1.__decorate([
    tslib_1.__param(0, (0, di_1.Optional)(ide_connection_1.IRPCProtocol)),
    tslib_1.__metadata("design:paramtypes", [Object])
], MainThreadLocalization);
//# sourceMappingURL=main.thread.localization.js.map