UNPKG

@manuth/woltlab-compiler

Version:

A compiler for generating WoltLab-Package `.tar` Archives and other WoltLab-Package Components

183 lines 6.3 kB
import { LocalizationNode } from "../../../Globalization/LocalizationNode.js"; import { TranslationInstruction } from "../Globalization/TranslationInstruction.js"; import { NodeSystemInstruction } from "../NodeSystem/NodeSystemInstruction.js"; /** * Represents an instruction which provides options. * * @template TCategory * The type of the categories. * * @template TCategoryOptions * The type of the options for generating categories. * * @template TOption * The type of the options. * * @template TOptionOptions * The type of the data for generating options. */ export class OptionInstruction extends NodeSystemInstruction { /** * Initializes a new instance of the {@link OptionInstruction `OptionInstruction<TCategory, TCategoryOptions, TOption, TOptionOptions>`} class. * * @param options * The options of the option-instruction. * * @param generator * A component for creating categories. */ constructor(options, generator) { super(options, generator); /** * The categories to delete. */ this.categoriesToDelete = []; /** * The options to delete. */ this.optionsToDelete = []; /** * The path to save the translations to. Gets the path to save the translations to. */ this.translationDirectory = null; if ((options.TranslationDirectory !== null) && (options.TranslationDirectory !== undefined)) { this.TranslationDirectory = options.TranslationDirectory; } if ((options.CategoriesToDelete !== null) && (options.CategoriesToDelete !== undefined)) { this.CategoriesToDelete.push(...options.CategoriesToDelete); } if ((options.OptionsToDelete !== null) && (options.OptionsToDelete !== undefined)) { this.OptionsToDelete.push(...options.OptionsToDelete); } } /** * @inheritdoc */ get TranslationDirectory() { var _a; return (_a = this.translationDirectory) !== null && _a !== void 0 ? _a : this.Type; } /** * @inheritdoc */ set TranslationDirectory(value) { this.translationDirectory = value; } /** * @inheritdoc */ get OptionCategory() { return null; } /** * @inheritdoc */ get CategoryCategory() { return "category"; } /** * @inheritdoc */ get CategoriesToDelete() { return this.categoriesToDelete; } /** * @inheritdoc */ get OptionsToDelete() { return this.optionsToDelete; } /** * @inheritdoc * * @returns * The messages of the options-instruction. */ GetMessages() { let result = new TranslationInstruction({ FileName: null, Nodes: [] }); let translationRoot = new LocalizationNode({ Name: this.RootCategory }); let optionNode; if (this.OptionCategory) { optionNode = new LocalizationNode({ Name: this.OptionCategory }); translationRoot.Nodes.push(optionNode); } else { optionNode = translationRoot; } let categoryNode; if (this.CategoryCategory) { categoryNode = new LocalizationNode({ Name: this.CategoryCategory }); translationRoot.Nodes.push(categoryNode); } else { categoryNode = translationRoot; } for (let rootNode of this.Nodes) { for (let node of rootNode.GetAllNodes()) { if (node.Item) { let categoryTranslations = new LocalizationNode({ Name: node.FullName, Item: node.Item.DisplayName.GetLocales().length > 0 ? { Translations: node.Item.DisplayName.ToJSON() } : undefined }); if (node.Item.Description.GetLocales().length > 0) { categoryTranslations.Nodes.push(new LocalizationNode({ Name: "description", Item: { Translations: node.Item.Description.ToJSON() } })); } for (let option of node.Item.Options) { let optionTranslations = new LocalizationNode({ Name: option.Name, Item: option.DisplayName.GetLocales().length > 0 ? { Translations: option.DisplayName.ToJSON() } : undefined }); if (option.Description.GetLocales().length > 0) { optionTranslations.Nodes.push(new LocalizationNode({ Name: "description", Item: { Translations: option.Description.ToJSON() } })); } for (let optionItem of option.Items) { if (optionItem.DisplayName.GetLocales().length > 0) { optionTranslations.Nodes.push(new LocalizationNode({ Name: optionItem.Name, Item: { Translations: optionItem.DisplayName.ToJSON() } })); } } optionNode.Nodes.push(optionTranslations); } categoryNode.Nodes.push(categoryTranslations); } } } result.Nodes.push(translationRoot); return result.GetMessages(); } } //# sourceMappingURL=OptionInstruction.js.map