UNPKG

@crowdin/app-project-module

Version:

Module that generates for you all common endpoints for serving standalone Crowdin App

178 lines (177 loc) 6.78 kB
/// <reference types="node" /> /// <reference types="node" /> import Crowdin, { LanguagesModel, SourceStringsModel } from '@crowdin/crowdin-api-client'; import { CrowdinContextInfo, ModuleKey, SignaturePatterns } from '../../types'; export interface FileProcessLogic extends ModuleKey { /** * Folder where larger file will be temporary stored (default "{@link dbFolder}/custom-file-format") */ filesFolder?: string; /** * Contains fileName and/or fileContent regular expressions used to detect file type when uploading a new source file via UI (or via API without specified type parameter). If the file matches regular expressions, it's labeled as a custom format file. */ signaturePatterns?: SignaturePatterns; /** * Override to store huge responses (by default they will be stored in fs) */ storeFile?: (content: Buffer) => Promise<string>; } export interface CustomFileFormatLogic extends FileProcessLogic { /** * The type parameter value for a custom file format. Used for a custom format file upload via API. */ type: string; /** * This parameter is used to combine the content of multiple languages into one request when uploading and downloading translations in your Crowdin project. */ multilingual?: boolean; /** * Flag to automatically upload translations */ autoUploadTranslations?: boolean; /** * Enable strings export */ stringsExport?: boolean; /** * File extensions (used for strings export) */ extensions?: string[]; /** * Enable custom srx */ customSrxSupported?: boolean; /** * Enable multi language strings export */ multilingualExport?: boolean; /** * Used for initial source file upload, source file update, and translation upload */ parseFile?: (fileContent: Buffer, req: Omit<ProcessFileRequest, 'jobType' | 'file'>, client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<ParseFileResponse>; /** * Used for translation download */ buildFile?: (fileContent: Buffer, req: Omit<ProcessFileRequest, 'jobType' | 'file'>, strings: ProcessFileString[], client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<BuildFileResponse>; /** * Used for strings export */ exportStrings?: (req: Omit<ProcessFileRequest, 'jobType'>, strings: ProcessFileString[], client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<BuildFileResponse>; } export type FileImportExportLogic = FilePreImportLogic | FilePostImportLogic | FilePreExportLogic | FilePostExportLogic; export type FileImportExportContent = ProcessFileString[] | Buffer | undefined; export type TranslationAlignmentContent = TranslationAlignmentString[] | Buffer | undefined; export interface FileTranslationAlignmentContent { sourceStrings: TranslationAlignmentContent; translations: TranslationAlignmentContent; } export interface BaseFileProcessLogic<T> { fileProcess: (req: ProcessFileRequest, content: FileImportExportContent, client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<T>; } export interface TranslationAlignmentProcessLogin<T> { fileProcess: (req: ProcessTranslationAlignmentRequest, content: FileTranslationAlignmentContent, client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<T>; } export interface FilePreImportLogic extends FileProcessLogic, BaseFileProcessLogic<ContentFileResponse> { /** * Set to `true` to enable asset processing in the application. */ processAssets?: boolean; } export interface FilePostImportLogic extends FileProcessLogic, BaseFileProcessLogic<StringsFileResponse> { } export interface FilePreExportLogic extends FileProcessLogic, BaseFileProcessLogic<StringsFileResponse> { } export interface FilePostExportLogic extends FileProcessLogic, BaseFileProcessLogic<ContentFileResponse> { /** * Set to `true` to enable asset processing in the application. */ processAssets?: boolean; } export interface TranslationsAlignmentLogic extends FileProcessLogic, TranslationAlignmentProcessLogin<TranslationAlignmentResponse> { } export interface ProcessTranslationAlignmentRequest { jobType: ProcessFileJobType; file: ProcessFileRecord; sourceLanguage: LanguagesModel.Language; targetLanguages: LanguagesModel.Language[]; sourceStrings: TranslationAlignmentString[]; sourceStringsUrl: string; translationStrings: TranslationAlignmentString[]; translationStringsUrl: string; getRawContent?: (encoding: BufferEncoding) => Promise<string | Buffer>; } export interface ProcessFileRequest { jobType: ProcessFileJobType; file: ProcessFileRecord; sourceLanguage: LanguagesModel.Language; targetLanguages: LanguagesModel.Language[]; strings: ProcessFileString[]; stringsUrl: string; getRawContent?: (encoding: BufferEncoding) => Promise<string | Buffer>; } export interface ProcessFileRecord { content?: string; contentUrl?: string; path?: string; id?: number; name?: string; type?: string; } export declare enum ProcessFileJobType { PARSE_FILE = "parse-file", BUILD_FILE = "build-file", PRE_IMPORT = "pre-import-file", POST_IMPORT = "post-import-file", PRE_EXPORT = "pre-export-file", POST_EXPORT = "post-export-file", TRANSLATIONS_ALIGNMENT = "translations-alignment-file" } export interface ParseFileResponse { previewFile?: Buffer; strings?: ProcessFileString[]; error?: string; } export interface BuildFileResponse { contentFile: Buffer; error?: string; fileName?: string; fileType?: string; } export interface StringsFileResponse extends ParseFileResponse { notModified?: boolean; } export interface ContentFileResponse extends BuildFileResponse { notModified?: boolean; } export interface TranslationAlignmentResponse { strings?: TranslationAlignmentResult[]; error?: string; } export interface TranslationAlignmentResult { sourceStringId: number; text: string | SourceStringsModel.PluralText; } export interface ProcessFileString { previewId?: number; id: number; identifier: string; context?: string; customData?: string; maxLength?: number; isHidden?: boolean; hasPlurals?: boolean; labels?: string[]; text: string | SourceStringsModel.PluralText; translations?: StringTranslations; uniqId?: string; } export interface TranslationAlignmentString { id: number | null; text: string | SourceStringsModel.PluralText; context: string; } export interface StringTranslations { [language: string]: { text: string | SourceStringsModel.PluralText; }; }