Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add default apiUrl + allown null namespace #3151

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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