486 lines
9.3 KiB
Plaintext
486 lines
9.3 KiB
Plaintext
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
|
|
exports[`correctly process indexed placeholders in few t calls 1`] = `
|
|
import { useLingui } from "@lingui/react/macro";
|
|
function Home() {
|
|
const { t } = useLingui();
|
|
const user = { name: "John " };
|
|
return (
|
|
<main>
|
|
<button onClick={() => console.log(t\`Hello \${user.name}\`)}>Hello</button>
|
|
|
|
<button onClick={() => console.log(t\`Bye \${user.name}\`)}>Bye</button>
|
|
</main>
|
|
);
|
|
}
|
|
|
|
↓ ↓ ↓ ↓ ↓ ↓
|
|
|
|
import { useLingui as _useLingui } from "@lingui/react";
|
|
function Home() {
|
|
const { _: _t } = _useLingui();
|
|
const user = {
|
|
name: "John ",
|
|
};
|
|
return (
|
|
<main>
|
|
<button
|
|
onClick={() =>
|
|
console.log(
|
|
_t(
|
|
/*i18n*/
|
|
{
|
|
id: "Y7riaK",
|
|
message: "Hello {0}",
|
|
values: {
|
|
0: user.name,
|
|
},
|
|
}
|
|
)
|
|
)
|
|
}
|
|
>
|
|
Hello
|
|
</button>
|
|
|
|
<button
|
|
onClick={() =>
|
|
console.log(
|
|
_t(
|
|
/*i18n*/
|
|
{
|
|
id: "vqOLZ6",
|
|
message: "Bye {0}",
|
|
values: {
|
|
0: user.name,
|
|
},
|
|
}
|
|
)
|
|
)
|
|
}
|
|
>
|
|
Bye
|
|
</button>
|
|
</main>
|
|
);
|
|
}
|
|
|
|
`;
|
|
|
|
exports[`does not crash when no params 1`] = `
|
|
import { useLingui } from "@lingui/react/macro";
|
|
function MyComponent() {
|
|
const { t } = useLingui();
|
|
const a = t();
|
|
}
|
|
|
|
↓ ↓ ↓ ↓ ↓ ↓
|
|
|
|
import { useLingui as _useLingui } from "@lingui/react";
|
|
function MyComponent() {
|
|
const { _: _t } = _useLingui();
|
|
const a = _t();
|
|
}
|
|
|
|
`;
|
|
|
|
exports[`inserted statement should not clash with existing variables 1`] = `
|
|
import { useLingui } from "@lingui/react/macro";
|
|
function MyComponent() {
|
|
const _t = "i'm here";
|
|
const { t: _ } = useLingui();
|
|
const a = _\`Text\`;
|
|
}
|
|
|
|
↓ ↓ ↓ ↓ ↓ ↓
|
|
|
|
import { useLingui as _useLingui } from "@lingui/react";
|
|
function MyComponent() {
|
|
const _t = "i'm here";
|
|
const { _: _t2 } = _useLingui();
|
|
const a = _t2(
|
|
/*i18n*/
|
|
{
|
|
id: "xeiujy",
|
|
message: "Text",
|
|
}
|
|
);
|
|
}
|
|
|
|
`;
|
|
|
|
exports[`should not break on function currying 1`] = `
|
|
import { useLingui } from "@lingui/core/macro";
|
|
const result = curryingFoo()();
|
|
console.log("curryingFoo", result);
|
|
|
|
↓ ↓ ↓ ↓ ↓ ↓
|
|
|
|
const result = curryingFoo()();
|
|
console.log("curryingFoo", result);
|
|
|
|
`;
|
|
|
|
exports[`should process macro with matching name in correct scopes 1`] = `
|
|
import { useLingui } from "@lingui/react/macro";
|
|
function MyComponent() {
|
|
const { t } = useLingui();
|
|
const a = t\`Text\`;
|
|
|
|
{
|
|
// here is child scope with own "t" binding, shouldn't be processed
|
|
const t = () => {};
|
|
t\`Text\`;
|
|
}
|
|
{
|
|
// here is child scope which should be processed, since 't' relates to outer scope
|
|
t\`Text\`;
|
|
}
|
|
}
|
|
|
|
↓ ↓ ↓ ↓ ↓ ↓
|
|
|
|
import { useLingui as _useLingui } from "@lingui/react";
|
|
function MyComponent() {
|
|
const { _: _t } = _useLingui();
|
|
const a = _t(
|
|
/*i18n*/
|
|
{
|
|
id: "xeiujy",
|
|
message: "Text",
|
|
}
|
|
);
|
|
{
|
|
// here is child scope with own "t" binding, shouldn't be processed
|
|
const t = () => {};
|
|
t\`Text\`;
|
|
}
|
|
{
|
|
// here is child scope which should be processed, since 't' relates to outer scope
|
|
_t(
|
|
/*i18n*/
|
|
{
|
|
id: "xeiujy",
|
|
message: "Text",
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
`;
|
|
|
|
exports[`support a variable 1`] = `
|
|
import { useLingui } from "@lingui/react/macro";
|
|
function MyComponent() {
|
|
const { t } = useLingui();
|
|
const a = t(msg);
|
|
}
|
|
|
|
↓ ↓ ↓ ↓ ↓ ↓
|
|
|
|
import { useLingui as _useLingui } from "@lingui/react";
|
|
function MyComponent() {
|
|
const { _: _t } = _useLingui();
|
|
const a = _t(msg);
|
|
}
|
|
|
|
`;
|
|
|
|
exports[`support configuring runtime module import using LinguiConfig.runtimeConfigModule 1`] = `
|
|
import { useLingui } from "@lingui/react/macro";
|
|
function MyComponent() {
|
|
const { t } = useLingui();
|
|
const a = t\`Text\`;
|
|
}
|
|
|
|
↓ ↓ ↓ ↓ ↓ ↓
|
|
|
|
import { myUselingui as _useLingui } from "@my/lingui-react";
|
|
function MyComponent() {
|
|
const { _: _t } = _useLingui();
|
|
const a = _t(
|
|
/*i18n*/
|
|
{
|
|
id: "xeiujy",
|
|
message: "Text",
|
|
}
|
|
);
|
|
}
|
|
|
|
`;
|
|
|
|
exports[`support i18n export 1`] = `
|
|
import { useLingui } from "@lingui/react/macro";
|
|
function MyComponent() {
|
|
const { i18n } = useLingui();
|
|
|
|
console.log(i18n);
|
|
}
|
|
|
|
↓ ↓ ↓ ↓ ↓ ↓
|
|
|
|
import { useLingui as _useLingui } from "@lingui/react";
|
|
function MyComponent() {
|
|
const { i18n } = _useLingui();
|
|
console.log(i18n);
|
|
}
|
|
|
|
`;
|
|
|
|
exports[`support message descriptor 1`] = `
|
|
import { useLingui } from "@lingui/react/macro";
|
|
function MyComponent() {
|
|
const { t } = useLingui();
|
|
const a = t({ message: "Hello", context: "my custom" });
|
|
}
|
|
|
|
↓ ↓ ↓ ↓ ↓ ↓
|
|
|
|
import { useLingui as _useLingui } from "@lingui/react";
|
|
function MyComponent() {
|
|
const { _: _t } = _useLingui();
|
|
const a = _t(
|
|
/*i18n*/
|
|
{
|
|
id: "BYqAaU",
|
|
message: "Hello",
|
|
context: "my custom",
|
|
}
|
|
);
|
|
}
|
|
|
|
`;
|
|
|
|
exports[`support nested macro 1`] = `
|
|
import { useLingui } from "@lingui/react/macro";
|
|
import { plural } from "@lingui/core/macro";
|
|
|
|
function MyComponent() {
|
|
const { t } = useLingui();
|
|
const a = t\`Text \${plural(users.length, {
|
|
offset: 1,
|
|
0: "No books",
|
|
1: "1 book",
|
|
other: "# books",
|
|
})}\`;
|
|
}
|
|
|
|
↓ ↓ ↓ ↓ ↓ ↓
|
|
|
|
import { useLingui as _useLingui } from "@lingui/react";
|
|
function MyComponent() {
|
|
const { _: _t } = _useLingui();
|
|
const a = _t(
|
|
/*i18n*/
|
|
{
|
|
id: "hJRCh6",
|
|
message:
|
|
"Text {0, plural, offset:1 =0 {No books} =1 {1 book} other {# books}}",
|
|
values: {
|
|
0: users.length,
|
|
},
|
|
}
|
|
);
|
|
}
|
|
|
|
`;
|
|
|
|
exports[`support passing t variable as dependency 1`] = `
|
|
import { useLingui } from "@lingui/react/macro";
|
|
function MyComponent() {
|
|
const { t } = useLingui();
|
|
const a = useMemo(() => t\`Text\`, [t]);
|
|
}
|
|
|
|
↓ ↓ ↓ ↓ ↓ ↓
|
|
|
|
import { useLingui as _useLingui } from "@lingui/react";
|
|
function MyComponent() {
|
|
const { _: _t } = _useLingui();
|
|
const a = useMemo(
|
|
() =>
|
|
_t(
|
|
/*i18n*/
|
|
{
|
|
id: "xeiujy",
|
|
message: "Text",
|
|
}
|
|
),
|
|
[_t]
|
|
);
|
|
}
|
|
|
|
`;
|
|
|
|
exports[`support renamed destructuring 1`] = `
|
|
import { useLingui } from "@lingui/react/macro";
|
|
function MyComponent() {
|
|
const { t: _ } = useLingui();
|
|
const a = _\`Text\`;
|
|
}
|
|
|
|
↓ ↓ ↓ ↓ ↓ ↓
|
|
|
|
import { useLingui as _useLingui } from "@lingui/react";
|
|
function MyComponent() {
|
|
const { _: _t } = _useLingui();
|
|
const a = _t(
|
|
/*i18n*/
|
|
{
|
|
id: "xeiujy",
|
|
message: "Text",
|
|
}
|
|
);
|
|
}
|
|
|
|
`;
|
|
|
|
exports[`tagged template literal style 1`] = `
|
|
import { useLingui } from "@lingui/react/macro";
|
|
function MyComponent() {
|
|
const { t } = useLingui();
|
|
const a = t\`Text\`;
|
|
}
|
|
|
|
↓ ↓ ↓ ↓ ↓ ↓
|
|
|
|
import { useLingui as _useLingui } from "@lingui/react";
|
|
function MyComponent() {
|
|
const { _: _t } = _useLingui();
|
|
const a = _t(
|
|
/*i18n*/
|
|
{
|
|
id: "xeiujy",
|
|
message: "Text",
|
|
}
|
|
);
|
|
}
|
|
|
|
`;
|
|
|
|
exports[`transform to standard useLingui statement 1`] = `
|
|
import { useLingui } from "@lingui/react/macro";
|
|
function MyComponent() {
|
|
const { i18n, t } = useLingui();
|
|
|
|
console.log(i18n);
|
|
const a = t\`Text\`;
|
|
}
|
|
|
|
↓ ↓ ↓ ↓ ↓ ↓
|
|
|
|
import { useLingui as _useLingui } from "@lingui/react";
|
|
function MyComponent() {
|
|
const { i18n, _: _t } = _useLingui();
|
|
console.log(i18n);
|
|
const a = _t(
|
|
/*i18n*/
|
|
{
|
|
id: "xeiujy",
|
|
message: "Text",
|
|
}
|
|
);
|
|
}
|
|
|
|
`;
|
|
|
|
exports[`work with existing useLingui statement 1`] = `
|
|
import { useLingui as useLinguiMacro } from "@lingui/react/macro";
|
|
import { useLingui } from "@lingui/react";
|
|
|
|
function MyComponent() {
|
|
const { _ } = useLingui();
|
|
|
|
console.log(_);
|
|
const { t } = useLinguiMacro();
|
|
const a = t\`Text\`;
|
|
}
|
|
|
|
↓ ↓ ↓ ↓ ↓ ↓
|
|
|
|
import { useLingui as _useLingui } from "@lingui/react";
|
|
import { useLingui } from "@lingui/react";
|
|
function MyComponent() {
|
|
const { _ } = useLingui();
|
|
console.log(_);
|
|
const { _: _t } = _useLingui();
|
|
const a = _t(
|
|
/*i18n*/
|
|
{
|
|
id: "xeiujy",
|
|
message: "Text",
|
|
}
|
|
);
|
|
}
|
|
|
|
`;
|
|
|
|
exports[`work with multiple react components 1`] = `
|
|
import { useLingui } from "@lingui/react/macro";
|
|
function MyComponent() {
|
|
const { t } = useLingui();
|
|
const a = t\`Text\`;
|
|
}
|
|
|
|
function MyComponent2() {
|
|
const { t } = useLingui();
|
|
const b = t\`Text\`;
|
|
}
|
|
|
|
↓ ↓ ↓ ↓ ↓ ↓
|
|
|
|
import { useLingui as _useLingui } from "@lingui/react";
|
|
function MyComponent() {
|
|
const { _: _t } = _useLingui();
|
|
const a = _t(
|
|
/*i18n*/
|
|
{
|
|
id: "xeiujy",
|
|
message: "Text",
|
|
}
|
|
);
|
|
}
|
|
function MyComponent2() {
|
|
const { _: _t2 } = _useLingui();
|
|
const b = _t2(
|
|
/*i18n*/
|
|
{
|
|
id: "xeiujy",
|
|
message: "Text",
|
|
}
|
|
);
|
|
}
|
|
|
|
`;
|
|
|
|
exports[`work with renamed existing useLingui statement 1`] = `
|
|
import { useLingui as useLinguiRenamed } from "@lingui/react";
|
|
import { useLingui as useLinguiMacro } from "@lingui/react/macro";
|
|
|
|
function MyComponent() {
|
|
const { _ } = useLinguiRenamed();
|
|
|
|
console.log(_);
|
|
const { t } = useLinguiMacro();
|
|
const a = t\`Text\`;
|
|
}
|
|
|
|
↓ ↓ ↓ ↓ ↓ ↓
|
|
|
|
import { useLingui as useLinguiRenamed } from "@lingui/react";
|
|
import { useLingui as _useLingui } from "@lingui/react";
|
|
function MyComponent() {
|
|
const { _ } = useLinguiRenamed();
|
|
console.log(_);
|
|
const { _: _t } = _useLingui();
|
|
const a = _t(
|
|
/*i18n*/
|
|
{
|
|
id: "xeiujy",
|
|
message: "Text",
|
|
}
|
|
);
|
|
}
|
|
|
|
`;
|