From 4810ee081ff24470ced3860bceb45ad89da8df3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20Gran=C3=A1t?= Date: Tue, 7 Feb 2023 13:24:40 +0100 Subject: [PATCH] fix: add default apiUrl + allown null namespace --- packages/core/src/Controller/Controller.ts | 4 ++-- packages/core/src/Controller/State/initState.ts | 4 +++- packages/core/src/types/general.ts | 2 +- packages/web/src/observers/invisible/InvisibleWrapper.ts | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/core/src/Controller/Controller.ts b/packages/core/src/Controller/Controller.ts index 755ff75b5d..b71dc65e3c 100644 --- a/packages/core/src/Controller/Controller.ts +++ b/packages/core/src/Controller/Controller.ts @@ -191,12 +191,12 @@ export const Controller = ({ options }: StateServiceProps) => { function getTranslationNs({ key, ns }: KeyAndNamespacesInternal) { const languages = state.getFallbackLangs(); - const namespaces = getDefaultAndFallbackNs(ns); + const namespaces = getDefaultAndFallbackNs(ns || undefined); return cache.getTranslationNs(namespaces, languages, key); } function getTranslation({ key, ns }: KeyAndNamespacesInternal) { - const namespaces = getDefaultAndFallbackNs(ns); + const namespaces = getDefaultAndFallbackNs(ns || undefined); const languages = state.getFallbackLangs(); return cache.getTranslationFallback(namespaces, languages, key); } diff --git a/packages/core/src/Controller/State/initState.ts b/packages/core/src/Controller/State/initState.ts index f4d4695a9a..c7dd5396cf 100644 --- a/packages/core/src/Controller/State/initState.ts +++ b/packages/core/src/Controller/State/initState.ts @@ -12,6 +12,7 @@ import { } from './observerOptions'; export const DEFAULT_FORMAT_ERROR = 'invalid'; +export const DEFAULT_API_URL = 'https://app.tolgee.io'; export type TolgeeStaticData = { [key: string]: TreeTranslationsData | (() => Promise); @@ -24,7 +25,7 @@ export type TolgeeOptionsInternal = { language?: string; /** - * Tolgee instance url (e.g. https://app.tolgee.io) + * Tolgee instance url (default: https://app.tolgee.io) */ apiUrl?: string; @@ -118,6 +119,7 @@ const defaultValues: TolgeeOptionsInternal = { observerOptions: defaultObserverOptions, observerType: 'invisible', onFormatError: DEFAULT_FORMAT_ERROR, + apiUrl: DEFAULT_API_URL, }; export const combineOptions = ( diff --git a/packages/core/src/types/general.ts b/packages/core/src/types/general.ts index b90096904d..d07e028836 100644 --- a/packages/core/src/types/general.ts +++ b/packages/core/src/types/general.ts @@ -17,7 +17,7 @@ export type TranslateParams = { }; export type TranslateOptions = { - ns?: NsType; + ns?: NsType | null; noWrap?: boolean; orEmpty?: boolean; }; diff --git a/packages/web/src/observers/invisible/InvisibleWrapper.ts b/packages/web/src/observers/invisible/InvisibleWrapper.ts index bfe75527cf..b80a5adab3 100644 --- a/packages/web/src/observers/invisible/InvisibleWrapper.ts +++ b/packages/web/src/observers/invisible/InvisibleWrapper.ts @@ -51,7 +51,7 @@ export const InvisibleWrapper = (): WrapperMiddleware => { const encodeValue = (data: TranslatePropsInternal) => { const value: EncodeValue = { k: data.key, - n: data.ns, + n: data.ns || undefined, d: data.defaultValue, }; return JSON.stringify(value);