diff --git a/.dockerignore b/.dockerignore index 1735a828..67843d8f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -14,4 +14,5 @@ helm-charts .env .editorconfig .idea -coverage* \ No newline at end of file +coverage* +packages/webui/paraglide \ No newline at end of file diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4a068817..eee3760b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -34,6 +34,9 @@ jobs: sudo apt-get update sudo apt-get install -y ripgrep bubblewrap socat ffmpeg poppler-utils imagemagick + - name: Compile i18n + run: bun run i18n:compile + - name: Lint run: bun run lint @@ -83,6 +86,9 @@ jobs: - name: Install dependencies run: bun install + - name: Compile i18n + run: bun run i18n:compile + - name: Install Playwright browser (${{ matrix.project }}) run: bunx playwright install --with-deps ${{ matrix.project }} @@ -130,6 +136,9 @@ jobs: sudo apt-get update sudo apt-get install -y ripgrep bubblewrap socat ffmpeg poppler-utils imagemagick + - name: Compile i18n + run: bun run i18n:compile + - name: Install Playwright browser (${{ matrix.project }}) run: bunx playwright install --with-deps ${{ matrix.project }} diff --git a/.github/workflows/release-npm.yaml b/.github/workflows/release-npm.yaml index 12fa44bb..0b328d71 100644 --- a/.github/workflows/release-npm.yaml +++ b/.github/workflows/release-npm.yaml @@ -53,6 +53,9 @@ jobs: - name: Install dependencies run: bun install + - name: Compile i18n + run: bun run i18n:compile + - name: Lint run: bun run lint diff --git a/.gitignore b/.gitignore index f6327240..c7534efe 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,7 @@ code_quality.md /test-results/ /blob-report/ /playwright/.cache/ + +# Paraglide JS +packages/webui/paraglide + diff --git a/Dockerfile b/Dockerfile index afcc99a4..384aa227 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,9 @@ RUN ls -la packages/transcode/node_modules # Copy source code COPY . . +# Compile i18n +RUN bun run i18n:compile + # Build API and Worker RUN bun run build.ts diff --git a/README.md b/README.md index b19c1ebb..320e7380 100644 --- a/README.md +++ b/README.md @@ -314,11 +314,17 @@ To set up Shumai locally for development: ``` 2. Start the `pgvector` database container (as described in **Option 2, Step 1**). 3. Create a `.env` file at the root of the workspace using the configuration from **Option 2, Step 5**. -4. Apply the database schema migrations: +4. Generate i18n translation files: + ```bash + bun run i18n:compile + ``` + > [!TIP] + > During frontend development, you can run `bun run i18n:watch` in a separate terminal to automatically recompile translation files whenever you edit strings in `packages/webui/messages/`. +5. Apply the database schema migrations: ```bash bun run db:migrate ``` -5. Start the local development server: +6. Start the local development server: ```bash bun run dev ``` diff --git a/README_CN.md b/README_CN.md index 8a2cc034..66534478 100644 --- a/README_CN.md +++ b/README_CN.md @@ -357,17 +357,20 @@ bun install 2. 启动 `pgvector` 数据库容器(参考**方案二中的第一步**)。 3. 参照**方案二中的第五步**,在项目根目录下创建一个 `.env` 文件。 -4. 执行数据库结构迁移: +4. 生成多语言国际化(i18n)代码: +```bash +bun run i18n:compile +``` +> [!TIP] +> 在前端开发过程中,可以在单独的终端窗口中运行 `bun run i18n:watch`,在修改 `packages/webui/messages/` 下的翻译文案时自动重新编译。 + +5. 执行数据库结构迁移: ```bash bun run db:migrate - ``` - - -5. 启动本地开发服务器: +6. 启动本地开发服务器: ```bash bun run dev - ``` diff --git a/bun.lock b/bun.lock index 1cf4280f..2b9e1ea5 100644 --- a/bun.lock +++ b/bun.lock @@ -6,7 +6,7 @@ "name": "shumai", "devDependencies": { "@eslint/js": "10.0.1", - "@inlang/paraglide-js": "2.20.0", + "@inlang/paraglide-js": "2.25.0", "@playwright/test": "1.61.1", "@testcontainers/postgresql": "12.1.0", "@testing-library/dom": "10.4.1", @@ -648,11 +648,11 @@ "@img/sharp-win32-x64": ["@img/sharp-win32-x64@0.35.4", "", { "os": "win32", "cpu": "x64" }, "sha512-XtmnYhBcrORsJ4XJngyzr/EWP0hRZLAZRFaApdKuviyqF78+ylxh2y06ZmtULAMOnObJ3ucpN0AcwSWnMowTRg=="], - "@inlang/paraglide-js": ["@inlang/paraglide-js@2.20.0", "", { "dependencies": { "@inlang/recommend-sherlock": "^0.2.1", "@inlang/sdk": "^2.10.0", "commander": "11.1.0", "consola": "3.4.0", "json5": "2.2.3", "unplugin": "^2.1.2", "urlpattern-polyfill": "^10.0.0" }, "peerDependencies": { "typescript": ">=5.6" }, "optionalPeers": ["typescript"], "bin": { "paraglide-js": "bin/run.js" } }, "sha512-vI8PdPVZSnpYnpagjvm+nWSa3nMDRJKVM/2eLAtUHFrNcZZadxVdmP79r4W95+dkMLDFGEyzSSY9sFxvjdkkyQ=="], + "@inlang/paraglide-js": ["@inlang/paraglide-js@2.25.0", "", { "dependencies": { "@inlang/recommend-sherlock": "^0.2.1", "@inlang/sdk": "^3.0.1", "commander": "11.1.0", "consola": "3.4.0", "jiti": "^2.7.0", "json5": "2.2.3", "unplugin": "^2.1.2", "urlpattern-polyfill": "^10.0.0", "valibot": "^1.4.2" }, "peerDependencies": { "typescript": ">=5.6", "vite": ">=5.0.0" }, "optionalPeers": ["typescript", "vite"], "bin": { "paraglide-js": "bin/run.js" } }, "sha512-a3Gw3md1S3WyJK1rFAP/FwDCsFKnu1b98rJ3k5bUl6nc3cmbglaSYpuK9qq9aLLlUlZhuCtB/Pb1LeKDUaLycg=="], "@inlang/recommend-sherlock": ["@inlang/recommend-sherlock@0.2.1", "", { "dependencies": { "comment-json": "^4.2.3" } }, "sha512-ckv8HvHy/iTqaVAEKrr+gnl+p3XFNwe5D2+6w6wJk2ORV2XkcRkKOJ/XsTUJbPSiyi4PI+p+T3bqbmNx/rDUlg=="], - "@inlang/sdk": ["@inlang/sdk@2.10.2", "", { "dependencies": { "@lix-js/sdk": "0.4.10", "@sinclair/typebox": "^0.31.17", "kysely": "^0.28.12", "sqlite-wasm-kysely": "0.3.0", "uuid": "^14.0.0" } }, "sha512-O1ki72SNK6LPagaGrvlioBb1mWKvump7cO7P85hfGZjdFTmDdn3icI0A6MvaBsB3P9KQHAjzyubnN1OslGufTw=="], + "@inlang/sdk": ["@inlang/sdk@3.0.2", "", { "dependencies": { "@lix-js/sdk": "0.12.3", "@sinclair/typebox": "^0.31.17", "kysely": "^0.28.12", "sqlite-wasm-kysely": "0.3.0", "uuid": "^14.0.0" } }, "sha512-qBAzkOLRQ42hZBl2/AZFZD+/JkdjBAvwxWphdTs9UbikMsuLathOBOIl+rC/mzaq48ylD3zE8Je2nrx7tbm0pw=="], "@isaacs/cliui": ["@isaacs/cliui@8.0.2", "", { "dependencies": { "string-width": "^5.1.2", "string-width-cjs": "npm:string-width@^4.2.0", "strip-ansi": "^7.0.1", "strip-ansi-cjs": "npm:strip-ansi@^6.0.1", "wrap-ansi": "^8.1.0", "wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0" } }, "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA=="], @@ -750,9 +750,15 @@ "@lexical/yjs": ["@lexical/yjs@0.49.0", "", { "dependencies": { "@lexical/internal": "0.49.0", "@lexical/selection": "0.49.0", "lexical": "0.49.0" }, "peerDependencies": { "typescript": ">=5.2", "yjs": ">=13.5.22" }, "optionalPeers": ["typescript"] }, "sha512-uqV3D0AOLqQ1f/Bo6ZtuDLoJYGlBm0RlucNYhNvfMAncEw0f/xHc1pTyXeWjdCI/iWgWR/MV6hgVi26TSPs+Vg=="], - "@lix-js/sdk": ["@lix-js/sdk@0.4.10", "", { "dependencies": { "@lix-js/server-protocol-schema": "0.1.1", "dedent": "1.5.1", "human-id": "^4.1.1", "js-sha256": "^0.11.0", "kysely": "^0.28.12", "sqlite-wasm-kysely": "0.3.0", "uuid": "^14.0.0" } }, "sha512-0dMInAJK/67guTG5rRZaCEhvzC5cCXENOjaePA5AqMXrCE97kaY7SRor9e2vnoGsFIiGqXKlT0MCIoZj36G0gg=="], + "@lix-js/sdk": ["@lix-js/sdk@0.12.3", "", { "dependencies": { "fflate": "^0.8.3" }, "optionalDependencies": { "@lix-js/sdk-darwin-arm64": "0.12.3", "@lix-js/sdk-linux-arm64": "0.12.3", "@lix-js/sdk-linux-x64": "0.12.3", "@lix-js/sdk-win32-x64": "0.12.3" } }, "sha512-T2194yoZsM2S9kyRmI8UtEJL0fgXYAkeY9jZ/PVyC0K78/wmBvrqOSt9SdvgYxM5qnZ57re3NLOjVlV+X5hWxQ=="], - "@lix-js/server-protocol-schema": ["@lix-js/server-protocol-schema@0.1.1", "", {}, "sha512-jBeALB6prAbtr5q4vTuxnRZZv1M2rKe8iNqRQhFJ4Tv7150unEa0vKyz0hs8Gl3fUGsWaNJBh3J8++fpbrpRBQ=="], + "@lix-js/sdk-darwin-arm64": ["@lix-js/sdk-darwin-arm64@0.12.3", "", { "os": "darwin", "cpu": "arm64" }, "sha512-YeMJyYGk+QwvQe8O4AAcBMgfNm68IjAGDvuvZHr1U1rIb3GC2kYFStajqf4mT4BGc+cN65/P/2kkqEo+Igu/sA=="], + + "@lix-js/sdk-linux-arm64": ["@lix-js/sdk-linux-arm64@0.12.3", "", { "os": "linux", "cpu": "arm64" }, "sha512-jtmfNg6jLW61l1QvsU3W184l3hGtYUyPGzZrQyekk0vsMF1hxsP++7ONEGNI19PE7ldwSnGCB8Q6OzRKX87abQ=="], + + "@lix-js/sdk-linux-x64": ["@lix-js/sdk-linux-x64@0.12.3", "", { "os": "linux", "cpu": "x64" }, "sha512-PiQL4h1FJXbxnZx/PgenI5grgpFtYlS/ZtPtTYh638YHVu+6J0cqGY/pLVqP8CKv1dWAKsZ2YgftLd+1j2+WKA=="], + + "@lix-js/sdk-win32-x64": ["@lix-js/sdk-win32-x64@0.12.3", "", { "os": "win32", "cpu": "x64" }, "sha512-hnxMI7kPS4ngXs0ZVnOve5CmtC4+vaNIyNDi/yWU0rSvxj7mqw/1RCegTrCB7LjxlX4DG+eg9HruXurk9NDjGg=="], "@mistralai/mistralai": ["@mistralai/mistralai@2.2.6", "", { "dependencies": { "@opentelemetry/semantic-conventions": "^1.40.0", "ws": "^8.18.0", "zod": "^3.25.0 || ^4.0.0", "zod-to-json-schema": "^3.25.0" }, "peerDependencies": { "@opentelemetry/api": "^1.9.0" }, "optionalPeers": ["@opentelemetry/api"] }, "sha512-W8pX7zHxjJvMIpw8JMxeJEleapXX0Q9NPszdNzqkM3MIEoIGPObdodujj+WHteXEvGfaP/AMwlNyRfEzSY6dQQ=="], @@ -1666,8 +1672,6 @@ "decode-named-character-reference": ["decode-named-character-reference@1.3.0", "", { "dependencies": { "character-entities": "^2.0.0" } }, "sha512-GtpQYB283KrPp6nRw50q3U9/VfOutZOe103qlN7BPP6Ad27xYnOIWv4lPzo8HCAL+mMZofJ9KEy30fq6MfaK6Q=="], - "dedent": ["dedent@1.5.1", "", { "peerDependencies": { "babel-plugin-macros": "^3.1.0" }, "optionalPeers": ["babel-plugin-macros"] }, "sha512-+LxW+KLWxu3HW3M2w2ympwtqPrqYRzU8fqi6Fhd18fBALe15blJPI/I4+UHveMVG6lJqB4JNd4UG0S5cnVHwIg=="], - "deep-is": ["deep-is@0.1.4", "", {}, "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ=="], "deepmerge-ts": ["deepmerge-ts@7.1.5", "", {}, "sha512-HOJkrhaYsweh+W+e74Yn7YStZOilkoPb6fycpwNLKzSPtruFs48nYis0zy5yJz1+ktUhHxoRDJ27RQAWLIJVJw=="], @@ -1872,7 +1876,7 @@ "fs-monkey": ["fs-monkey@1.1.0", "", {}, "sha512-QMUezzXWII9EV5aTFXW1UBVUO77wYPpjqIF8/AviUCThNeSYZykpoTixUeaNNBwmCev0AMDWMAni+f8Hxb1IFw=="], - "fsevents": ["fsevents@2.3.2", "", { "os": "darwin" }, "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA=="], + "fsevents": ["fsevents@2.3.3", "", { "os": "darwin" }, "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw=="], "function-bind": ["function-bind@1.1.2", "", {}, "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA=="], @@ -1966,8 +1970,6 @@ "https-proxy-agent": ["https-proxy-agent@7.0.6", "", { "dependencies": { "agent-base": "^7.1.2", "debug": "4" } }, "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw=="], - "human-id": ["human-id@4.2.1", "", { "bin": { "human-id": "dist/cli.js" } }, "sha512-zPGsiS+dWoTZtZ4AtpA9Y+BdSFSNWvnouNlWNoUFyAM6xHOHmdCvqO3k8AIbdamCOv4gUFUVNPf6rJFfc4UiJw=="], - "hyperdyperid": ["hyperdyperid@1.2.0", "", {}, "sha512-Y93lCzHYgGWdrJ66yIktxiaGULYc6oGiABxhcO5AufBeOyoIdZF7bIfLaOrbM0iGIOXQQgxxRrFEnb+Y6w1n4A=="], "iconv-lite": ["iconv-lite@0.7.3", "", { "dependencies": { "safer-buffer": ">= 2.1.2 < 3.0.0" } }, "sha512-IKXpvIzjnC9XTAUbVBcMfGS0EPaIXtW6v+zr+RRp+hqULEpo0owZax6wyRwPOJbWbzjYspQwusTsfVr0ifh4uQ=="], @@ -2082,8 +2084,6 @@ "joycon": ["joycon@3.1.1", "", {}, "sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw=="], - "js-sha256": ["js-sha256@0.11.1", "", {}, "sha512-o6WSo/LUvY2uC4j7mO50a2ms7E/EAdbP0swigLV+nzHKTTaYnaLIWJ02VdXrsJX0vGedDESQnLsOekr94ryfjg=="], - "js-tokens": ["js-tokens@4.0.0", "", {}, "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ=="], "jsesc": ["jsesc@3.1.0", "", { "bin": { "jsesc": "bin/jsesc" } }, "sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA=="], @@ -2904,8 +2904,6 @@ "@jsonjoy.com/util/@jsonjoy.com/buffers": ["@jsonjoy.com/buffers@1.2.1", "", { "peerDependencies": { "tslib": "2" } }, "sha512-12cdlDwX4RUM3QxmUbVJWqZ/mrK6dFQH4Zxq6+r1YXKXYBNgZXndx2qbCJwh3+WWkCSn67IjnlG3XYTvmvYtgA=="], - "@lix-js/sdk/uuid": ["uuid@14.0.2", "", { "bin": { "uuid": "dist-node/bin/uuid" } }, "sha512-xZe/16rV4aa+HGSOCiY2YeLT1OybRLrrkL/Rqaq7p7GMVXjFh+6wN4oMYgjFmnSnhY8t6Xpdl2l9qmnHYuMHwQ=="], - "@prisma/dev/std-env": ["std-env@3.10.0", "", {}, "sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg=="], "@prisma/engines/@prisma/get-platform": ["@prisma/get-platform@7.10.0", "", { "dependencies": { "@prisma/debug": "7.10.0" } }, "sha512-0bra1LFYi8xNw0yqV62bHJNQk4BKleOngZiqPWIQc7a3+9q6rqsnqJ15BuepP8943PFMvtmgnP52juZsyYkA6w=="], @@ -3012,6 +3010,8 @@ "pg-types/postgres-array": ["postgres-array@2.0.0", "", {}, "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA=="], + "playwright/fsevents": ["fsevents@2.3.2", "", { "os": "darwin" }, "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA=="], + "prisma-json-types-generator/semver": ["semver@7.8.5", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA=="], "prop-types/react-is": ["react-is@16.13.1", "", {}, "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ=="], @@ -3032,8 +3032,6 @@ "thread-stream/real-require": ["real-require@1.0.0", "", {}, "sha512-P4nbQYQfePJxRSmY+v/KINxVucm4NF3p3s7pJveMTtom52FR4YGltUQLB8idDXwDDWW+eYrWDFbuzUnjoWHF7g=="], - "vite/fsevents": ["fsevents@2.3.3", "", { "os": "darwin" }, "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw=="], - "wrap-ansi/ansi-styles": ["ansi-styles@4.3.0", "", { "dependencies": { "color-convert": "^2.0.1" } }, "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg=="], "wrap-ansi-cjs/ansi-styles": ["ansi-styles@4.3.0", "", { "dependencies": { "color-convert": "^2.0.1" } }, "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg=="], diff --git a/package.json b/package.json index 73b5158a..a111746a 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ ], "scripts": { "dev": "bun run --hot apps/web/src/index.ts", - "i18n:compile": "paraglide-js compile --project ./packages/webui/project.inlang --outdir ./packages/webui/paraglide --emit-ts-declarations --no-emit-git-ignore", - "i18n:watch": "paraglide-js compile --project ./packages/webui/project.inlang --outdir ./packages/webui/paraglide --watch --emit-ts-declarations --no-emit-git-ignore", + "i18n:compile": "paraglide-js compile --project ./packages/webui/project.inlang --outdir ./packages/webui/paraglide --emit-ts-declarations", + "i18n:watch": "paraglide-js compile --project ./packages/webui/project.inlang --outdir ./packages/webui/paraglide --watch --emit-ts-declarations", "typecheck": "tsc --noEmit", "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "test": "bun --bun vitest run", @@ -30,8 +30,8 @@ "db:generate": "cd packages/db && bunx prisma generate", "worker:agent": "bun apps/agent/src/index.ts", "worker:transcode": "bun apps/transcode/src/index.ts", - "build": "bun run build.ts", - "build-npm": "bun scripts/build-npm.ts", + "build": "bun run i18n:compile && bun run build.ts", + "build-npm": "bun run i18n:compile && bun scripts/build-npm.ts", "prepublishOnly": "bun run build-npm && bun run lint && bun run typecheck", "publish": "bun run prepublishOnly && bun run scripts/publish.ts", "publish:dry": "bun run prepublishOnly && bun run scripts/publish.ts --dry-run", @@ -42,7 +42,7 @@ }, "devDependencies": { "@eslint/js": "10.0.1", - "@inlang/paraglide-js": "2.20.0", + "@inlang/paraglide-js": "2.25.0", "@playwright/test": "1.61.1", "@testcontainers/postgresql": "12.1.0", "@testing-library/dom": "10.4.1", diff --git a/packages/webui/paraglide/.prettierignore b/packages/webui/paraglide/.prettierignore deleted file mode 100644 index 7e18fe45..00000000 --- a/packages/webui/paraglide/.prettierignore +++ /dev/null @@ -1,3 +0,0 @@ -# ignore everything because the directory is auto-generated by inlang paraglide-js -# for more info visit https://paraglidejs.com -* diff --git a/packages/webui/paraglide/README.md b/packages/webui/paraglide/README.md deleted file mode 100644 index c9706762..00000000 --- a/packages/webui/paraglide/README.md +++ /dev/null @@ -1,162 +0,0 @@ -# Paraglide JS Compiled Output - -> Auto-generated i18n message functions. Import `messages.js` to use translated strings. - -Compiled from: `/Users/yiling/Projects/shumai/packages/webui/project.inlang` - - -## What is this folder? - -This folder contains compiled [Paraglide JS](https://github.com/opral/paraglide-js) output. Paraglide JS compiles your translation messages into tree-shakeable JavaScript functions. - -## At a glance - -Purpose: -- This folder stores compiled i18n message functions. -- Source translations live outside this folder in your inlang project. - -Safe to import: -- `messages.js` — all message functions -- `runtime.js` — locale utilities -- `server.js` — server-side middleware - -Do not edit: -- All files in this folder are auto-generated. -- Changes will be overwritten on next compilation. - -``` -paraglide/ -├── messages.js # Message exports (import this) -├── messages/ # Individual message functions -├── runtime.js # Locale detection & configuration -├── registry.js # Formatting utilities (plural, number, datetime, relativetime) -├── server.js # Server-side middleware -└── .gitignore # Marks folder as generated -``` - -## Usage - -```js -import * as m from "./paraglide/messages.js"; - -// Messages are functions that return localized strings -m.hello_world(); // "Hello, World!" (in current locale) -m.greeting({ name: "Sam" }); // "Hello, Sam!" - -// Override locale per-call -m.hello_world({}, { locale: "de" }); // "Hallo, Welt!" -m.greeting({ name: "Sam" }, { locale: "de" }); // "Hallo, Sam!" -``` - -## Runtime API - -```js -import { getLocale, getTextDirection, setLocale, locales, baseLocale } from "./paraglide/runtime.js"; - -getLocale(); // Current locale, e.g., "en" -getTextDirection(); // "ltr" | "rtl" for current locale -setLocale("de"); // Set locale -locales; // Available locales, e.g., ["en", "de", "fr"] -baseLocale; // Default locale, e.g., "en" -``` - -## Strategy - -The strategy determines how the current locale is detected and persisted: - -- **Cookie**: Stores locale preference in a cookie. -- **URL**: Derives locale from URL patterns (e.g., `/en/about`, `en.example.com`). -- **GlobalVariable**: Uses a global variable (client-side only). -- **BaseLocale**: Always returns the base locale. - -Strategies can be combined. The order defines precedence: - -```js -await compile({ - project: "./project.inlang", - outdir: "./src/paraglide", - strategy: ["url", "cookie", "baseLocale"], -}); -``` - -See the [strategy documentation](https://paraglidejs.com/strategy) for details. - -## Markup (Rich Text) - -Messages can contain markup tags for bold, links, and other inline elements. Translators control where tags appear; developers control how they render. - -Important: -- Tag names are app-defined. There is no built-in list of HTML tags. -- `{#b}...{/b}` does not automatically render as `...`. -- Renderers/snippets are looked up by the same tag name used in the message. - -### Message syntax - -```json -{ - "cta": "{#link to=|/docs| rel=$relationship @track}Read the docs{/link}", - "welcome": "{#b}Hi {name}{/b}{#icon/}" -} -``` - -- `{#tagName}` opens a tag, `{/tagName}` closes it. -- `{#tagName/}` creates a standalone tag. -- Options: `to=|/docs|` or `rel=$relationship` (accessed via `options.*`). -- Attributes: `@track` or `@variant=|hero|` (accessed via `attributes.*`). - -This is the default inlang message syntax. Paraglide's message format is plugin-based — you can use [ICU MessageFormat 1](https://inlang.com/m/p7c8m1d2/plugin-inlang-icu-messageformat-1), [i18next](https://inlang.com/m/3i8bor92/plugin-inlang-i18next), or other [plugins](https://inlang.com/c/plugins) instead. - -### Rendering markup - -Calling the message function still returns **plain text** (markup stripped): - -```js -m.cta({ relationship: "noopener" }); // "Read the docs" -``` - -To render markup, use the framework adapter or the low-level `parts()` API: - -```js -const parts = m.cta.parts({ relationship: "noopener" }); -// [ -// { type: "markup-start", name: "link", options: { to: "/docs", rel: "noopener" }, attributes: { track: true } }, -// { type: "text", value: "Read the docs" }, -// { type: "markup-end", name: "link" } -// ] -``` - -Framework adapters provide a `` component that accepts markup renderers: - -- `@inlang/paraglide-js-react` -- `@inlang/paraglide-js-vue` -- `@inlang/paraglide-js-svelte` -- `@inlang/paraglide-js-solid` - -```jsx -import { ParaglideMessage } from "@inlang/paraglide-js-react"; // or -vue, -svelte, -solid - - {children}, - icon: () =>