Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

1.9 KB
Raw Blame
import { describe, expect, it } from "vitest";
import az from "../locales/docs/az";
import en from "../locales/docs/en";
import es from "../locales/docs/es";
import id from "../locales/docs/id";
import it_ from "../locales/docs/it";
import ja from "../locales/docs/ja";
import ko from "../locales/docs/ko";
import ptBR from "../locales/docs/pt-BR";
import ru from "../locales/docs/ru";
import tr from "../locales/docs/tr";
import th from "../locales/docs/th";
import zhCN from "../locales/docs/zh-CN";
import zhTW from "../locales/docs/zh-TW";

// These import the per-locale DOCS modules, NOT ../locales/<name>.
//
// Every non-English locale file is `export default withEnglishFallback({...})`,
// which deep-merges `en` UNDER the locale at module level. Importing those
// default exports yields the ALREADY-MERGED object, so every locale appears to
// have every key and this test would pass while translations were missing —
// the fallback would silently defeat the test written to catch it.
const locales: Array<[string, Record<string, unknown>]> = [
  ["az", az],
  ["es", es],
  ["id", id],
  ["it", it_],
  ["ja", ja],
  ["ko", ko],
  ["pt-BR", ptBR],
  ["ru", ru],
  ["tr", tr],
  ["th", th],
  ["zh-CN", zhCN],
  ["zh-TW", zhTW],
];

function leafKeys(value: unknown, prefix = ""): string[] {
  if (value === null || typeof value !== "object" || Array.isArray(value)) {
    return [prefix];
  }
  return Object.entries(value as Record<string, unknown>).flatMap(([key, child]) => leafKeys(child, prefix ? `${prefix}.${key}` : key));
}

describe("docs i18n namespace parity", () => {
  const expected = leafKeys(en as Record<string, unknown>).sort();

  it("english declares the docs namespace", () => {
    expect(expected.length, "locales/docs/en.ts must declare keys").toBeGreaterThan(0);
  });

  it.each(locales)("%s declares exactly the same docs keys as en", (_name, locale) => {
    expect(leafKeys(locale).sort()).toEqual(expected);
  });
});