Skip to content

Commit

Permalink
fix: add default apiUrl + allown null namespace (#3151)
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan662 committed Feb 7, 2023
1 parent 25d92ac commit ce754a1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/Controller/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/Controller/State/initState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TreeTranslationsData>);
Expand All @@ -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;

Expand Down Expand Up @@ -118,6 +119,7 @@ const defaultValues: TolgeeOptionsInternal = {
observerOptions: defaultObserverOptions,
observerType: 'invisible',
onFormatError: DEFAULT_FORMAT_ERROR,
apiUrl: DEFAULT_API_URL,
};

export const combineOptions = <T extends TolgeeOptions>(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type TranslateParams<T = DefaultParamType> = {
};

export type TranslateOptions = {
ns?: NsType;
ns?: NsType | null;
noWrap?: boolean;
orEmpty?: boolean;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/observers/invisible/InvisibleWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ce754a1

Please sign in to comment.