Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
phrases: {},
locale: "foo",
allowMissing: true,
onMissingKey: (key, opts, locale) => {
console.log(key.length, Object.keys(opts), locale.length);
return "foo";
}
});
new Polyglot();
// $ExpectError
new Polyglot("foo");
Polyglot.transformPhrase("foo").length;
Polyglot.transformPhrase("foo", {}).length;
Polyglot.transformPhrase("foo", {}, "en-US").length;
instance.extend({ foo: "bar" });
// $ExpectError
instance.extend("foo");
instance.has("foo");
// $ExpectError
instance.has(1);
instance.t("foo").length;
instance.t("foo", {}).length;
// $ExpectError
locale: "foo",
allowMissing: true,
onMissingKey: (key, opts, locale) => {
console.log(key.length, Object.keys(opts), locale.length);
return "foo";
}
});
new Polyglot();
// $ExpectError
new Polyglot("foo");
Polyglot.transformPhrase("foo").length;
Polyglot.transformPhrase("foo", {}).length;
Polyglot.transformPhrase("foo", {}, "en-US").length;
instance.extend({ foo: "bar" });
// $ExpectError
instance.extend("foo");
instance.has("foo");
// $ExpectError
instance.has(1);
instance.t("foo").length;
instance.t("foo", {}).length;
// $ExpectError
instance.t(2);
function onMissingKey(key, opts, locale) {
if (locale !== defaultLang) {
console.warn('Missing translation for key: "' + key + '"');
}
return Polyglot.transformPhrase(key, opts, locale);
}
function onMissingKey(key, opts, locale) {
if (locale !== defaultLang) {
console.warn('Missing translation for key: "' + key + '"')
}
return Polyglot.transformPhrase(key, opts, locale)
}
const engTranslate = (string, data) =>
Polyglot.transformPhrase(string, data, 'en');