diff --git a/types/Lang.ts b/types/Lang.ts index 251272d6..768a162a 100644 --- a/types/Lang.ts +++ b/types/Lang.ts @@ -8,3 +8,7 @@ export type GenericLanguageObject = { export type LanguageObject = typeof lang; export type LangKey = Leaves; + +export type InterpolationData = { + [identifier: string]: string | number; +}; diff --git a/types/LogCallbacks.ts b/types/LogCallbacks.ts index 2f8cd37f..71437990 100644 --- a/types/LogCallbacks.ts +++ b/types/LogCallbacks.ts @@ -1,5 +1,7 @@ +import { InterpolationData } from './Lang'; + export type LogCallbacks = { - [key in T]?: () => void; + [key in T]?: (interpolationData?: InterpolationData) => void; }; export type LogCallbacksArg = { diff --git a/utils/lang.ts b/utils/lang.ts index e601d654..dfb1812e 100644 --- a/utils/lang.ts +++ b/utils/lang.ts @@ -1,5 +1,10 @@ import en from '../lang/en.json'; -import { LanguageObject, GenericLanguageObject, LangKey } from '../types/Lang'; +import { + LanguageObject, + GenericLanguageObject, + LangKey, + InterpolationData, +} from '../types/Lang'; const LANGUAGES: { [language: string]: LanguageObject } = { en, @@ -69,10 +74,6 @@ function generateReplaceFn( }; } -type InterpolationData = { - [identifier: string]: string | number; -}; - export function interpolate( stringValue: string, interpolationData: InterpolationData diff --git a/utils/logger.ts b/utils/logger.ts index 48f58320..2da3b3ee 100644 --- a/utils/logger.ts +++ b/utils/logger.ts @@ -1,19 +1,19 @@ import { i18n } from './lang'; import { logger } from '../lib/logging/logger'; import { LogCallbacks } from '../types/LogCallbacks'; -import { LangKey } from '../types/Lang'; +import { InterpolationData, LangKey } from '../types/Lang'; export function log( key: T, callbacks?: LogCallbacks, debugKey?: LangKey, - debugInterpolation?: { [key: string]: string | number } + interpolationData?: InterpolationData ): void { if (callbacks && callbacks[key]) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - callbacks[key]!(); + callbacks[key]!(interpolationData); } else if (debugKey) { - debug(debugKey, debugInterpolation); + debug(debugKey, interpolationData); } } @@ -25,13 +25,13 @@ export function makeTypedLogger( return ( key: ValidateCallbackKeys, debugKey?: LangKey, - debugInterpolation?: { [key: string]: string | number } - ) => log(key, callbacks, debugKey, debugInterpolation); + interpolationData?: InterpolationData + ) => log(key, callbacks, debugKey, interpolationData); } export function debug( identifier: LangKey, - interpolation?: { [key: string]: string | number } + interpolationData?: InterpolationData ): void { - logger.debug(i18n(identifier, interpolation)); + logger.debug(i18n(identifier, interpolationData)); }