UNPKG

@crowdin/ota-client

Version:

JavaScript library for Crowdin OTA Content Delivery

219 lines (216 loc) 6.7 kB
/** * This module contains the types used in the Crowdin OTA Client. * * @module Types */ interface ClientConfig { /** * Specify your own http client. Default uses fetch */ httpClient?: HttpClient; /** * Disable cache of distribution manifest. Default is false */ disableManifestCache?: boolean; /** * Default language code to be used if language was not passed as an input argument of the method */ languageCode?: string; /** * Disable translation strings cache. Default is false */ disableStringsCache?: boolean; /** * Disable Crowdin languages cache. Default is false */ disableLanguagesCache?: boolean; /** * Disable deep merge and use shallow merge to merge translation strings from json file */ disableJsonDeepMerge?: boolean; /** * The name of your Crowdin Enterprise organization * If provided, this will fetch languages from the Enterprise API instead of the Crowdin API v2. The name must be a valid Enterprise organization name. */ enterpriseOrganizationDomain?: string; } interface HttpClient { /** * Executes HTTP GET request * * @param url http url */ get<T>(url: string): Promise<T>; } interface Manifest { files: string[]; languages: string[]; timestamp: number; language_mapping: LanguageMappings | never[]; custom_languages: CustomLanguages | never[]; content: { [languageCode: string]: string[]; }; mapping: string[]; } interface LanguageMappings { [languageCode: string]: LanguageMapping; } interface CustomLanguages { [languageCode: string]: CustomLanguageRaw; } interface LanguageMapping { [placeholder: string]: string; } interface Translations { [languageCode: string]: LanguageTranslations[]; } interface LanguageTranslations { file: string; content: string | any | null; } interface LanguageStrings { [languageCode: string]: any; } interface CustomLanguageRaw { name: string; two_letters_code: string; three_letters_code: string; locale: string; locale_with_underscore: string; android_code: string; osx_code: string; osx_locale: string; } /** * @category OtaClient */ declare class OtaClient { private distributionHash; /** @internal */ static readonly BASE_URL = "https://distributions.crowdin.net"; private readonly httpClient; private manifestHolder?; private disableManifestCache; private stringsCache; private disableStringsCache; private disableJsonDeepMerge; private locale?; /** * @param distributionHash Hash of released Crowdin project distribution * @param config Client config */ constructor(distributionHash: string, config?: ClientConfig); /** * Get the distribution hash. * * @category Helper Methods */ getHash(): string; /** * Define the global language for the client instance. * Default language code to be used if language was not passed as an input argument of the method. * * @category Helper Methods * @param languageCode {@link https://support.crowdin.com/developer/language-codes/ Language Code} */ setCurrentLocale(languageCode?: string): void; /** * Get the current locale of the client instance. * * @category Helper Methods */ getCurrentLocale(): string | undefined; /** * Get distribution's manifest timestamp. * * @category Helper Methods */ getManifestTimestamp(): Promise<number>; /** * List distribution's files content. * * @category Content Management Methods * * @returns An object mapping {@link https://support.crowdin.com/developer/language-codes/ Language Code} to arrays of strings: `{[languageCode: string]: string[]}` */ getContent(): Promise<Manifest['content']>; /** * List distribution's files content for a specific language. * * @category Content Management Methods * * @param languageCode {@link https://support.crowdin.com/developer/language-codes/ Language Code} */ getLanguageContent(languageCode?: string): Promise<string[]>; /** * List Crowdin project {@link https://support.crowdin.com/developer/language-codes/ language codes}. * * @category Helper Methods */ listLanguages(): Promise<string[]>; /** * Get all translations for all languages. * * @category Content Management Methods * * @returns All translations per each language code */ getTranslations(): Promise<Translations>; /** * Get translations for a specific language. * * @category Content Management Methods * * @param languageCode {@link https://support.crowdin.com/developer/language-codes/ Language Code} * @returns Translations for each file in the distribution for a given language (content) */ getLanguageTranslations(languageCode?: string): Promise<LanguageTranslations[]>; /** * Get translations for a specific file. * * @category Content Management Methods * * @param file file content path * @returns Translations for a specific file (content) */ getFileTranslations(file: string): Promise<string | any | null>; /** * Get all translation strings for all languages. * * @category Strings Management Methods * * @returns Translation strings from json-based files for all languages */ getStrings(): Promise<LanguageStrings>; /** * Get translation strings for a specific language. * * @category Strings Management Methods * * @param languageCode {@link https://support.crowdin.com/developer/language-codes/ Language Code} * @returns Translation strings from json-based files for a given language */ getStringsByLocale(languageCode?: string): Promise<any>; /** * Get translation string for a specific key. * * @category Strings Management Methods * * @param key path to the translation string in json file * @param languageCode {@link https://support.crowdin.com/developer/language-codes/ Language Code} * @returns Translation string for language for given key */ getStringByKey(key: string[] | string, languageCode?: string): Promise<string | any>; /** * Clear the translation strings cache. * * @category Helper Methods */ clearStringsCache(): void; private getStringsByFilesAndLocale; private get manifest(); private getLanguageCode; private getJsonFiles; } export { OtaClient as default };