@tolgee/core
Advanced tools
Comparing version 5.6.1-prerelease.998593cd.0 to 5.7.0-prerelease.134377fa.0
@@ -17,3 +17,3 @@ import { CacheDescriptor, NsFallback, TolgeeOptions, TFnType, KeyAndNamespacesInternal } from '../types'; | ||
isLoaded: (ns?: NsFallback) => boolean; | ||
t: TFnType<import("../types").DefaultParamType, string>; | ||
t: TFnType<import("../types").DefaultParamType, string, import("../types").TranslationKey>; | ||
isDev: () => boolean; | ||
@@ -35,57 +35,5 @@ run: () => Promise<void | undefined>; | ||
}[]; | ||
addPlugin: (tolgeeInstance: Readonly<{ | ||
on: import("../types").TolgeeOn<keyof import("../types").EventType>; | ||
onNsUpdate: (handler: import("../types").Listener<undefined>) => import("../types").SubscriptionSelective; | ||
setEmmiterActive: (active: boolean) => void; | ||
getLanguage: () => string | undefined; | ||
getPendingLanguage: () => string | undefined; | ||
changeLanguage: (language: string) => Promise<void>; | ||
changeTranslation: (descriptor: CacheDescriptor, key: string, value: string) => { | ||
revert: () => void; | ||
}; | ||
addActiveNs: (ns: NsFallback, forget?: boolean) => Promise<void>; | ||
removeActiveNs: (ns: NsFallback) => void; | ||
loadRecords: (descriptors: CacheDescriptor[]) => Promise<import("../types").TranslationsFlat[]>; | ||
loadRecord: (descriptor: CacheDescriptor) => Promise<import("../types").TranslationsFlat>; | ||
addStaticData: (data: import("./State/initState").TolgeeStaticData | undefined) => void; | ||
getRecord: (descriptor: CacheDescriptor) => import("../types").TranslationsFlat | undefined; | ||
getAllRecords: () => { | ||
data: import("../types").TranslationsFlat; | ||
language: string; | ||
namespace: string; | ||
}[]; | ||
isLoaded: (ns?: NsFallback) => boolean; | ||
isInitialLoading: () => boolean; | ||
isLoading: (ns?: NsFallback) => boolean; | ||
isFetching: (ns?: NsFallback) => boolean; | ||
isRunning: () => boolean; | ||
run: () => Promise<void | undefined>; | ||
stop: () => void; | ||
t: TFnType<import("../types").DefaultParamType, string>; | ||
highlight: import("../types").HighlightInterface; | ||
getInitialOptions: () => { | ||
apiUrl?: string | undefined; | ||
apiKey?: string | undefined; | ||
projectId?: string | number | undefined; | ||
language?: string | undefined; | ||
defaultLanguage?: string | undefined; | ||
availableLanguages?: string[] | undefined; | ||
fallbackLanguage?: import("../types").FallbackLanguageOption; | ||
ns?: string[] | undefined; | ||
fallbackNs?: import("../types").FallbackGeneral; | ||
defaultNs: string; | ||
staticData?: import("./State/initState").TolgeeStaticData | undefined; | ||
observerType: "invisible" | "text"; | ||
observerOptions: import("./State/observerOptions").ObserverOptionsInternal; | ||
onFormatError: import("../types").OnFormatError; | ||
}; | ||
isDev: () => boolean; | ||
wrap: (params: import("../types").WrapperWrapProps) => string | undefined; | ||
unwrap: (text: string) => import("../types").Unwrapped; | ||
overrideCredentials(credentials: import("../types").DevCredentials): void; | ||
addPlugin(plugin: import("../types").TolgeePlugin | undefined): void; | ||
updateOptions(options?: TolgeeOptions | undefined): void; | ||
}>, plugin: import("../types").TolgeePlugin) => void; | ||
addPlugin: (tolgeeInstance: import("../TolgeeCore").TolgeeInstance, plugin: import("../types").TolgeePlugin) => void; | ||
formatTranslation: ({ formatEnabled, ...props }: { | ||
key: string; | ||
key: import("../types").TranslationKey; | ||
defaultValue?: string | undefined; | ||
@@ -92,0 +40,0 @@ params?: import("../types").TranslateParams<import("../types").DefaultParamType> | undefined; |
@@ -5,3 +5,3 @@ import { BackendDevMiddleware, BackendGetRecord, TranslatePropsInternal, HighlightInterface, LanguageDetectorMiddleware, LanguageStorageMiddleware, ChangeTranslationInterface, WrapperWrapProps, Unwrapped, KeyAndNamespacesInternal, TolgeePlugin, TolgeeInstance, TolgeeOptionsInternal } from '../../types'; | ||
formatTranslation: ({ formatEnabled, ...props }: { | ||
key: string; | ||
key: import("../../types").TranslationKey; | ||
defaultValue?: string | undefined; | ||
@@ -8,0 +8,0 @@ params?: import("../../types").TranslateParams<import("../../types").DefaultParamType> | undefined; |
@@ -1,2 +0,2 @@ | ||
import { TolgeeOptions, TolgeePlugin, DevCredentials } from './types'; | ||
import { TolgeeOptions, TolgeePlugin, DevCredentials, TFnType, DefaultParamType, TranslationKey } from './types'; | ||
declare const createTolgee: (options: TolgeeOptions) => Readonly<{ | ||
@@ -122,3 +122,3 @@ /** | ||
*/ | ||
t: import("./types").TFnType<import("./types").DefaultParamType, string>; | ||
t: TFnType<DefaultParamType, string, TranslationKey>; | ||
/** | ||
@@ -136,5 +136,3 @@ * Highlight keys that match selection. | ||
language?: string | undefined; | ||
defaultLanguage?: string | undefined; /** | ||
* Turn off/on events emitting. Is on by default. | ||
*/ | ||
defaultLanguage?: string | undefined; | ||
availableLanguages?: string[] | undefined; | ||
@@ -183,3 +181,5 @@ fallbackLanguage?: import("./types").FallbackLanguageOption; | ||
}>; | ||
export declare type TolgeeInstance = ReturnType<typeof createTolgee>; | ||
export declare type TolgeeInstance = Omit<ReturnType<typeof createTolgee>, 't'> & { | ||
t: TFnType<DefaultParamType, string, TranslationKey>; | ||
}; | ||
export declare type TolgeeChainer = { | ||
@@ -186,0 +186,0 @@ /** |
export declare type FallbackGeneral = undefined | false | string | string[]; | ||
export declare type NsType = string; | ||
export declare type KeyType = string; | ||
export declare type TranslationKey = string & Record<never, never>; | ||
export declare type NsFallback = undefined | NsType | NsType[]; | ||
@@ -16,4 +16,4 @@ export declare type FallbackLanguageObject = Record<string, FallbackGeneral>; | ||
}; | ||
export declare type TranslateProps<T = DefaultParamType> = { | ||
key: KeyType; | ||
export declare type TranslateProps<T = DefaultParamType, K extends string = TranslationKey> = { | ||
key: K; | ||
defaultValue?: string; | ||
@@ -29,8 +29,8 @@ params?: TranslateParams<T>; | ||
}; | ||
export declare type TFnType<T = DefaultParamType, R = string> = { | ||
(key: string, defaultValue?: string, options?: CombinedOptions<T>): R; | ||
(key: string, options?: CombinedOptions<T>): R; | ||
(props: TranslateProps<T>): R; | ||
export declare type TFnType<T = DefaultParamType, R = string, K extends string = TranslationKey> = { | ||
(key: K, defaultValue?: string, options?: CombinedOptions<T>): R; | ||
(key: K, options?: CombinedOptions<T>): R; | ||
(props: TranslateProps<T, K>): R; | ||
}; | ||
export declare type KeyAndNamespacesInternal = Pick<TranslatePropsInternal, 'key' | 'ns'>; | ||
export {}; |
{ | ||
"name": "@tolgee/core", | ||
"version": "5.6.1-prerelease.998593cd.0", | ||
"version": "5.7.0-prerelease.134377fa.0", | ||
"description": "Library providing ability to translate messages directly in context of developed application.", | ||
@@ -70,3 +70,3 @@ "main": "./dist/tolgee.cjs.js", | ||
"sideEffects": false, | ||
"gitHead": "6e3a8f7570a206a452540ca02190f22eab0d542a" | ||
"gitHead": "3a0ca2ce76eb4126b21779e133bb5484ef596dbe" | ||
} |
import { Controller } from './Controller/Controller'; | ||
import { combineOptions } from './Controller/State/initState'; | ||
import { TolgeeOptions, TolgeePlugin, DevCredentials } from './types'; | ||
import { | ||
TolgeeOptions, | ||
TolgeePlugin, | ||
DevCredentials, | ||
TFnType, | ||
DefaultParamType, | ||
TranslationKey, | ||
} from './types'; | ||
@@ -217,3 +224,6 @@ const createTolgee = (options: TolgeeOptions) => { | ||
export type TolgeeInstance = ReturnType<typeof createTolgee>; | ||
export type TolgeeInstance = Omit<ReturnType<typeof createTolgee>, 't'> & { | ||
// enabling generics (when inferred they are lost) | ||
t: TFnType<DefaultParamType, string, TranslationKey>; | ||
}; | ||
@@ -220,0 +230,0 @@ export type TolgeeChainer = { |
@@ -5,3 +5,5 @@ export type FallbackGeneral = undefined | false | string | string[]; | ||
export type KeyType = string; | ||
// This prevents typescript to optimize this to 'string' | ||
// this type needs to be overritable everywhere | ||
export type TranslationKey = string & Record<never, never>; | ||
@@ -26,4 +28,7 @@ export type NsFallback = undefined | NsType | NsType[]; | ||
export type TranslateProps<T = DefaultParamType> = { | ||
key: KeyType; | ||
export type TranslateProps< | ||
T = DefaultParamType, | ||
K extends string = TranslationKey | ||
> = { | ||
key: K; | ||
defaultValue?: string; | ||
@@ -43,6 +48,10 @@ params?: TranslateParams<T>; | ||
export type TFnType<T = DefaultParamType, R = string> = { | ||
(key: string, defaultValue?: string, options?: CombinedOptions<T>): R; | ||
(key: string, options?: CombinedOptions<T>): R; | ||
(props: TranslateProps<T>): R; | ||
export type TFnType< | ||
T = DefaultParamType, | ||
R = string, | ||
K extends string = TranslationKey | ||
> = { | ||
(key: K, defaultValue?: string, options?: CombinedOptions<T>): R; | ||
(key: K, options?: CombinedOptions<T>): R; | ||
(props: TranslateProps<T, K>): R; | ||
}; | ||
@@ -49,0 +58,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
913524
12672