UNPKG

woltlab-compiler

Version:

A compiler for WoltLab-Package Archives and WoltLab-Package Components

139 lines 5.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const util_1 = require("util"); const LocalizationNode_1 = require("../../../Globalization/LocalizationNode"); const TranslationInstruction_1 = require("../Globalization/TranslationInstruction"); const NodeSystemInstruction_1 = require("../NodeSystem/NodeSystemInstruction"); /** * Represents an instruction which provides options. */ class OptionInstruction extends NodeSystemInstruction_1.NodeSystemInstruction { /** * Initializes a new instance of the `OptionInstruction<TCategory, TCategoryOptions, TOption, TOptionOptions>` class. */ constructor(options, generator) { super(options, generator); /** * The categories to delete. */ this.categoriesToDelete = []; /** * The options to delete. */ this.optionsToDelete = []; if (!util_1.isNullOrUndefined(options.CategoriesToDelete)) { this.CategoriesToDelete.push(...options.CategoriesToDelete); } if (!util_1.isNullOrUndefined(options.OptionsToDelete)) { this.OptionsToDelete.push(...options.OptionsToDelete); } } /** * @inheritdoc */ get TranslationDirectory() { return this.Type; } /** * @inheritdoc */ get OptionCategory() { return null; } /** * @inheritdoc */ get CategoryCategory() { return "category"; } /** * @inheritdoc */ get CategoriesToDelete() { return this.categoriesToDelete; } /** * @inheritdoc */ get OptionsToDelete() { return this.optionsToDelete; } /** * @inheritdoc */ GetMessages() { let result = new TranslationInstruction_1.TranslationInstruction({ FileName: null, Nodes: [] }); let translationRoot = new LocalizationNode_1.LocalizationNode({ Name: this.RootCategory }); let optionNode; if (!util_1.isNullOrUndefined(this.OptionCategory)) { optionNode = new LocalizationNode_1.LocalizationNode({ Name: this.OptionCategory }); translationRoot.Nodes.push(optionNode); } else { optionNode = translationRoot; } let categoryNode; if (!util_1.isNullOrUndefined(this.CategoryCategory)) { categoryNode = new LocalizationNode_1.LocalizationNode({ Name: this.CategoryCategory }); optionNode.Nodes.push(categoryNode); } else { categoryNode = optionNode; } for (let rootNode of this.Nodes) { for (let node of rootNode.GetAllNodes()) { if (!util_1.isNullOrUndefined(node.Item)) { let categoryTranslations = new LocalizationNode_1.LocalizationNode({ Name: node.FullName, Item: node.Item.DisplayName.GetLocales().length > 0 ? { Translations: node.Item.DisplayName.Data } : undefined }); if (node.Item.Description.GetLocales().length > 0) { categoryTranslations.Nodes.push(new LocalizationNode_1.LocalizationNode({ Name: "description", Item: { Translations: node.Item.Description.Data } })); } for (let option of node.Item.Options) { let optionTranslations = new LocalizationNode_1.LocalizationNode({ Name: option.Name, Item: option.DisplayName.GetLocales().length > 0 ? { Translations: option.DisplayName.Data } : undefined }); for (let optionItem of option.Items) { if (optionItem.DisplayName.GetLocales().length > 0) { optionTranslations.Nodes.push(new LocalizationNode_1.LocalizationNode({ Name: optionItem.Name, Item: { Translations: optionItem.DisplayName.Data } })); } } optionNode.Nodes.push(optionTranslations); } categoryNode.Nodes.push(categoryTranslations); } } } result.Nodes.push(translationRoot); return result.GetMessages(); } } exports.OptionInstruction = OptionInstruction; //# sourceMappingURL=OptionInstruction.js.map