/** * @module translationsio * Handles CSV import/export for Translations.io integration. * Exports functions for parsing, formatting, and syncing translations. * Depends on csv-parse/sync. */ import { ComponentPath } from '../classes/componentpath'; import { ComponentPayload } from '../classes/componentpayload'; import { ProblemMessageObject } from '../classes/errors'; import { ProjectFileService } from '../classes/projectfileservice'; export declare const DATA_TRANSLATIONS_KEY = "translations"; export declare const TRANSLATION_HEADER_PATH = "path"; export declare const TRANSLATION_HEADER_SAME_AS = "sameAs"; export declare const TRANSLATION_UNIQUE = ""; /** * A record of language codes to translated strings. */ export type TranslationRecord = Readonly>; /** * A translation for one or more paths. * If multiple paths are given, they must have the same translations. * This is used to avoid duplicate translations in the output. */ export declare class Translation { paths: ComponentPath[]; private readonly _translations; get translations(): TranslationRecord; readonly stringified: string; constructor(labelsObject: TranslationRecord, path: ComponentPath | ComponentPath[]); /** * Checks if the two translations have the same content. * It is fine to compare only the stringified version, because the constructor always sorts the keys and removes empty values. * @param other * @returns */ isSame(other: Translation): boolean; /** * If the two translations are the same, merges the paths of the other translation into this one. * @param other * @returns */ mergeIfSame(other: Translation): boolean; /** * @param languagesHeader array of language codes to be used as header, e.g. ['en', 'de', 'fr', ...] * @returns array of CSV lines * first line contains the first path and the full translation * subsequent lines contain the other paths without the translation, because it is the same as the first one * the second column is the value for the "sameAsPrevious" */ toCsvLineRows(languagesHeader: string[]): string[]; } /** * A collection of translations for multiple paths. * This is used to collect all translations from component payloads and to apply them back to component payloads. * There is no batch apply to keep the function simple. For batch process, call the functions with a batch of payloads. */ export declare class Translations { translations: Translation[]; /** * Adds a new translation if it does not yet exist, otherwise merges the paths into the existing one. * @param translation * @returns */ addTranslation(translation: Translation): void; /** * Collects the translations from a component payload into the translations collection. This collects all labels objects from the component definition and from data.translations * @param payload ComponentPayload to collect translations from */ collectTranslationsFromPayload(payload: ComponentPayload): void; /** * Tries to apply a single translation record to a component payload at the given path. * @param payload * @param path * @param translation * @returns error if no success, warning if translation is empty, null if everything is fine */ applyTranslationRecordToPayload(payload: ComponentPayload | undefined, path: ComponentPath, translation: TranslationRecord): ProblemMessageObject | null; /** * Applies the translations to the given project file service. Returns an array of ProblemMessageObject, which is empty if no problems occurred. * @param projectFileService the project file service to get the component payloads from * @param exportChanges if true, the changed payloads are stored back to the project file service * @returns */ apply(projectFileService: ProjectFileService, exportChanges: boolean): ProblemMessageObject[]; /** * Applies the translations to the given payload. Returns an array of ProblemMessageObject, which is empty if no problems occurred. * @param payload the payload into which to apply the translations */ applyToPayload(payload: ComponentPayload): ProblemMessageObject[]; /** * @returns Array of all component ids that have translations in this collection, sorted alphabetically. */ getListOfComponentIds(): string[]; /** * Returns true if the given path is a valid translation path, i.e. it points to a defined labels object in a component definition. * @param path */ static validateTranslationPath(path: ComponentPath): boolean; /** * Parses a CSV string into a Translations object. If parsing fails, returns undefined and logs an error. * @param csv CSV string to parse * @returns Translations object or undefined if parsing fails */ static fromCsv(csv: string): Translations | undefined; /** * Goes through all translations and collects all languages used. * @returns Array of language codes, e.g. ['en', 'de', 'fr', ...], where 'en' is always first and 'de' second, the rest sorted alphabetically. */ collectLanguages(): string[]; /** Exports the translations as a CSV */ toCsv(): string; }