Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const t2: i18next.TranslationFunction<{ value: string }> = (
key: string|string[],
options?: i18next.TranslationOptions,
) => ({ value: 'asd' })
const t3: i18next.TranslationFunction = (
key: string | string[],
options?: i18next.TranslationOptions,
) => ''
const t4: i18next.TranslationFunction = (
key: KeyList | KeyList[],
options?: i18next.TranslationOptions,
) => ''
i18next.exists('friend');
i18next.exists(['friend', 'tree']);
i18next.exists('friend', { myVar: 'someValue' });
i18next.exists(['friend', 'tree'], { myVar: 'someValue' });
i18next.t("friend", { myVar: "someValue" });
i18next.t(["friend", "tree"], { myVar: "someValue" });
i18next.t("friend", { myVar: "someValue" });
i18next.t(["friend", "tree"], { myVar: "someValue" });
// NOTION: disable no-unnecessary-generics for generic pattern test.
/* tslint:disable:no-unnecessary-generics */
interface ExWithT extends i18next.WithT {
t(keys: Keys|Keys[], options?: i18next.TranslationOptions): R;
t(keys: Keys|Keys[], options?: i18next.TranslationOptions): R;
t(keys: Keys|Keys[]): R;
}
type OtherKeyList = "private" | "public";
key: string|string[],
options?: i18next.TranslationOptions,
) => ({ value: 'asd' })
const t3: i18next.TranslationFunction = (
key: string | string[],
options?: i18next.TranslationOptions,
) => ''
const t4: i18next.TranslationFunction = (
key: KeyList | KeyList[],
options?: i18next.TranslationOptions,
) => ''
i18next.exists('friend');
i18next.exists(['friend', 'tree']);
i18next.exists('friend', { myVar: 'someValue' });
i18next.exists(['friend', 'tree'], { myVar: 'someValue' });
i18next.t("friend", { myVar: "someValue" });
i18next.t(["friend", "tree"], { myVar: "someValue" });
i18next.t("friend", { myVar: "someValue" });
i18next.t(["friend", "tree"], { myVar: "someValue" });
// NOTION: disable no-unnecessary-generics for generic pattern test.
/* tslint:disable:no-unnecessary-generics */
interface ExWithT extends i18next.WithT {
t(keys: Keys|Keys[], options?: i18next.TranslationOptions): R;
t(keys: Keys|Keys[], options?: i18next.TranslationOptions): R;
t(keys: Keys|Keys[]): R;
}
type OtherKeyList = "private" | "public";
const handleZero = (messages, options) => {
// When the language is no english, fallback to the 'one' string,
// because the "t" translation function will pick the correct plural that way
var fallback = i18next.language === 'en' || !i18next.exists(messages.one, options)
? messages.many
: messages.one
return t(messages.zero || fallback, options)
}
instance.interceptors.response.use(undefined, async function (err) {
const { response, config } = err
const errorStrategy = config.errorStrategy as ErrorStrategy
const method = (config.method as string).toLowerCase()
let errCode: string
let content: string
if (err.message === 'Network Error') {
errCode = 'error.network'
} else {
errCode = response?.data?.code
}
if (errCode !== ERR_CODE_OTHER && i18next.exists(errCode)) {
content = i18next.t(errCode)
} else {
content =
response?.data?.message || err.message || i18next.t(ERR_CODE_OTHER)
}
err.message = content
if (errCode === 'error.api.unauthorized') {
// Handle unauthorized error in a unified way
if (!routing.isLocationMatch('/') && !routing.isSignInPage()) {
message.error({ content, key: errCode })
}
auth.clearAuthToken()
singleSpa.navigateToUrl('#' + routing.signInRoute)
err.handled = true
} else if (errorStrategy === ErrorStrategy.Default) {
const translate = () => {
if (i18next.exists(namespacedKey, options)) {
subscriber.next(i18next.t(namespacedKey, options));
} else {
if (whitespaceUntilLoaded) {
subscriber.next(this.NON_BREAKING_SPACE);
}
i18next.loadNamespaces(chunkName, () => {
if (!i18next.exists(namespacedKey, options)) {
this.reportMissingKey(key, chunkName);
subscriber.next(this.getFallbackValue(namespacedKey));
} else {
subscriber.next(i18next.t(namespacedKey, options));
}
});
}
};
translate.has = (key) => key && i18next.exists(key);
export const __ = (key, ...rest) => {
return (exists(key) && t(key, ...rest)) || key;
};
i18next.loadNamespaces(chunkName, () => {
if (!i18next.exists(namespacedKey, options)) {
this.reportMissingKey(key, chunkName);
subscriber.next(this.getFallbackValue(namespacedKey));
} else {
subscriber.next(i18next.t(namespacedKey, options));
}
});
}
i18n.tf = (key, fallbackKey) => (i18n.exists(key) ? i18n.t(key) : i18n.ifExists(fallbackKey));
function t(key, vars) {
if (isNaN(key) && i18n.exists(key)) {
return vars ? i18n.t(key, vars) : i18n.t(key);
}
return key;
}