feat(i18n): standardize bilingual catalogs and tooling
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
import { lexicalMessages } from "../messages"
|
||||
import { messages as en } from "./en"
|
||||
import { messages as enUS } from "./en-US"
|
||||
import { messages as zhHans } from "./zh-Hans"
|
||||
|
||||
describe("Lexical locale catalogs", () => {
|
||||
it("ships every built-in message in every locale", () => {
|
||||
const messageIds = Object.values(lexicalMessages)
|
||||
.map((descriptor) => descriptor.id)
|
||||
.sort()
|
||||
const messageIds = Object.values(lexicalMessages).map(
|
||||
(descriptor) => descriptor.id
|
||||
)
|
||||
messageIds.sort()
|
||||
|
||||
for (const messages of [en, zhHans]) {
|
||||
for (const messages of [enUS, zhHans]) {
|
||||
// Object.keys returns a fresh array.
|
||||
// oxlint-disable-next-line unicorn/no-array-sort
|
||||
expect(Object.keys(messages).sort()).toEqual(messageIds)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { lexicalMessages } from "../messages"
|
||||
|
||||
export const lexicalCatalogLocales = ["en", "zh-Hans"] as const
|
||||
export const lexicalCatalogLocales = ["en-US", "zh-Hans"] as const
|
||||
|
||||
type LexicalMessageId =
|
||||
(typeof lexicalMessages)[keyof typeof lexicalMessages]["id"]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { LexicalMessageCatalog } from "./catalogs"
|
||||
|
||||
export const locale = "en"
|
||||
export const locale = "en-US"
|
||||
export const languageTag = "en-US"
|
||||
|
||||
export const messages = {
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
findLexicalActions,
|
||||
} from "./action-declarations"
|
||||
import { LexicalActionsProvider } from "./actions-context"
|
||||
import { messages as englishMessages } from "./locales/en"
|
||||
import { messages as englishMessages } from "./locales/en-US"
|
||||
|
||||
const pluginKeys = new WeakMap<ComponentType, string>()
|
||||
let nextPluginKey = 0
|
||||
@@ -46,7 +46,7 @@ function LexicalI18nBoundary({ children }: { children: ReactNode }) {
|
||||
if (hasI18nProvider) return children
|
||||
|
||||
return (
|
||||
<I18nProvider catalogs={{ en: englishMessages }} locale="en">
|
||||
<I18nProvider catalogs={{ "en-US": englishMessages }} locale="en-US">
|
||||
{children}
|
||||
</I18nProvider>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user