import type { CatalogFormatter, CatalogType } from "@lingui/conf"; import { defineConfig } from "@lingui/conf"; import { formatter } from "@lingui/format-po"; // File references without line numbers, so catalogs change only when messages change. const po = formatter({ lineNumbers: false }); const collator = new Intl.Collator("en-US"); // Lingui orders entries by source text but leaves ties (explicit ids, equal text) in the order the // files were found, which differs between file systems. Break ties by id so output is stable. function sortCatalog(catalog: CatalogType): CatalogType { return Object.fromEntries( Object.entries(catalog).sort( ([aId, a], [bId, b]) => collator.compare(a.message ?? aId, b.message ?? bId) || collator.compare(a.context ?? "", b.context ?? "") || (aId < bId ? -1 : aId > bId ? 1 : 0), ), ); } const stablePo: CatalogFormatter = { ...po, serialize: (catalog, ctx) => po.serialize(sortCatalog(catalog), ctx), }; export default defineConfig({ sourceLocale: "en", locales: ["en", "de", "ko", "tr", "hi", "pt-BR", "zh-CN", "es", "ru"], catalogs: [ { path: "/src/locales/{locale}/messages", include: ["src"], exclude: ["**/locales/**", "**/*.test.*"], }, ], format: stablePo, compileNamespace: "es", });