-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(macro): add useLingui macro (#1859)
Co-authored-by: ddyo <danrosenshain@gmail.com>
- Loading branch information
1 parent
44cd960
commit 916732f
Showing
20 changed files
with
883 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 51 additions & 36 deletions
87
packages/conf/src/migrations/normalizeRuntimeConfigModule.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,77 @@ | ||
import { normalizeRuntimeConfigModule } from "./normalizeRuntimeConfigModule" | ||
|
||
describe("normalizeRuntimeConfigModule", () => { | ||
it("only i18n specified", () => { | ||
const actual = normalizeRuntimeConfigModule({ | ||
runtimeConfigModule: ["../my-i18n", "myI18n"], | ||
}) | ||
test("all defaults", () => { | ||
const actual = normalizeRuntimeConfigModule({ runtimeConfigModule: {} }) | ||
|
||
expect(actual.runtimeConfigModule).toStrictEqual({ | ||
TransImportModule: "@lingui/react", | ||
TransImportName: "Trans", | ||
i18nImportModule: "../my-i18n", | ||
i18nImportName: "myI18n", | ||
}) | ||
expect(actual.runtimeConfigModule).toMatchInlineSnapshot(` | ||
{ | ||
TransImportModule: @lingui/react, | ||
TransImportName: Trans, | ||
i18nImportModule: @lingui/core, | ||
i18nImportName: i18n, | ||
useLinguiImportModule: @lingui/react, | ||
useLinguiImportName: useLingui, | ||
} | ||
`) | ||
}) | ||
|
||
it("Trans and i18n specified", () => { | ||
test("i18n specified as legacy shorthand", () => { | ||
const actual = normalizeRuntimeConfigModule({ | ||
runtimeConfigModule: { | ||
i18n: ["./custom-i18n", "myI18n"], | ||
Trans: ["./custom-trans", "myTrans"], | ||
}, | ||
runtimeConfigModule: ["../my-i18n", "myI18n"], | ||
}) | ||
|
||
expect(actual.runtimeConfigModule).toStrictEqual({ | ||
TransImportModule: "./custom-trans", | ||
TransImportName: "myTrans", | ||
i18nImportModule: "./custom-i18n", | ||
i18nImportName: "myI18n", | ||
}) | ||
expect(actual.runtimeConfigModule).toMatchInlineSnapshot(` | ||
{ | ||
TransImportModule: @lingui/react, | ||
TransImportName: Trans, | ||
i18nImportModule: ../my-i18n, | ||
i18nImportName: myI18n, | ||
useLinguiImportModule: @lingui/react, | ||
useLinguiImportName: useLingui, | ||
} | ||
`) | ||
}) | ||
|
||
it("i18n specified as object", () => { | ||
it("All runtime modules specified", () => { | ||
const actual = normalizeRuntimeConfigModule({ | ||
runtimeConfigModule: { | ||
i18n: ["./custom-i18n", "myI18n"], | ||
Trans: ["./custom-trans", "myTrans"], | ||
useLingui: ["./custom-use-lingui", "myLingui"], | ||
}, | ||
}) | ||
|
||
expect(actual.runtimeConfigModule).toStrictEqual({ | ||
TransImportModule: "@lingui/react", | ||
TransImportName: "Trans", | ||
i18nImportModule: "./custom-i18n", | ||
i18nImportName: "myI18n", | ||
}) | ||
expect(actual.runtimeConfigModule).toMatchInlineSnapshot(` | ||
{ | ||
TransImportModule: ./custom-trans, | ||
TransImportName: myTrans, | ||
i18nImportModule: ./custom-i18n, | ||
i18nImportName: myI18n, | ||
useLinguiImportModule: ./custom-use-lingui, | ||
useLinguiImportName: myLingui, | ||
} | ||
`) | ||
}) | ||
|
||
it("Trans specified as object", () => { | ||
it("only module is specified", () => { | ||
const actual = normalizeRuntimeConfigModule({ | ||
runtimeConfigModule: { | ||
Trans: ["./custom-trans", "myTrans"], | ||
i18n: ["./custom-i18n"], | ||
Trans: ["./custom-trans"], | ||
useLingui: ["./custom-use-lingui"], | ||
}, | ||
}) | ||
|
||
expect(actual.runtimeConfigModule).toStrictEqual({ | ||
TransImportModule: "./custom-trans", | ||
TransImportName: "myTrans", | ||
i18nImportModule: "@lingui/core", | ||
i18nImportName: "i18n", | ||
}) | ||
expect(actual.runtimeConfigModule).toMatchInlineSnapshot(` | ||
{ | ||
TransImportModule: ./custom-trans, | ||
TransImportName: Trans, | ||
i18nImportModule: ./custom-i18n, | ||
i18nImportName: i18n, | ||
useLinguiImportModule: ./custom-use-lingui, | ||
useLinguiImportName: useLingui, | ||
} | ||
`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.