UNPKG

@crowdin/ota-client

Version:

JavaScript library for Crowdin OTA Content Delivery

123 lines (122 loc) 3.79 kB
import { ClientConfig, LanguageStrings, LanguageTranslations, Manifest, Translations } from './model'; /** * @category OtaClient */ export default 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 */ 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 * * @param languageCode {@link https://developer.crowdin.com/language-codes Language Code} * @category Helper */ setCurrentLocale(languageCode?: string): void; /** * Get the current locale * * @category Helper */ getCurrentLocale(): string | undefined; /** * Get manifest timestamp of distribution * * @category Helper */ getManifestTimestamp(): Promise<number>; /** * List distribution's files content * * @category Content Management */ getContent(): Promise<Manifest['content']>; /** * List distribution's files content for a specific language * * @param languageCode {@link https://developer.crowdin.com/language-codes Language Code} * * @category Content Management */ getLanguageContent(languageCode?: string): Promise<string[]>; /** * List Crowdin project language codes * * @category Helper */ listLanguages(): Promise<string[]>; /** * Returns all translations per each language code * * @category Content Management */ getTranslations(): Promise<Translations>; /** * Returns translations for each file in the distribution for a given language * * @param languageCode {@link https://developer.crowdin.com/language-codes Language Code} * * @category Content Management */ getLanguageTranslations(languageCode?: string): Promise<LanguageTranslations[]>; /** * Returns translations for a specific file (content) * * @param file file content path * * @category Content Management */ getFileTranslations(file: string): Promise<string | any | null>; /** * Returns translation strings from json-based files for all languages * * @category Strings Management */ getStrings(): Promise<LanguageStrings>; /** * Returns translation strings from json-based files for a given language * * @param languageCode {@link https://developer.crowdin.com/language-codes Language Code} * * @category Strings Management */ getStringsByLocale(languageCode?: string): Promise<any>; /** * Returns translation string for language for given key * * @param key path to the translation string in json file * @param languageCode {@link https://developer.crowdin.com/language-codes Language Code} * * @category Strings Management */ getStringByKey(key: string[] | string, languageCode?: string): Promise<string | any>; /** * Clear the translation string cache * * @category Helper */ clearStringsCache(): void; private getStringsByFilesAndLocale; private get manifest(); private getLanguageCode; private getJsonFiles; }