mirror of
https://github.com/storytold/lightcraft.git
synced 2026-10-25 18:47:42 -06:00
The localization layer was hardcoded to English and Japanese: an enum with two
variants, an `is_japanese()` gate compiled into the format macro, and one
catalog pair. Adding a language meant editing the menus, the settings row, the
checkmark logic, the format macro and the font stack — each in a different place.
A language is now one entry in `i18n::language_table!`: BCP-47 code, endonym,
ISO 15924 script and catalog. The Language menu, the settings row, the shortcut
sheet and the control channel are all built from that table, and `build.rs`
picks up `locales/<code>-formats.json` by name, so a further language is a table
entry plus two catalogs (docs/localization.md).
Simplified Chinese (`zh-hans`) ships as the second translation: `zh-hans.json`
(1019 entries, key-set and placeholder-identical to `ja.json`) and
`zh-hans-formats.json` (102 entries). Its glyphs come from craft-fonts' Noto
Sans CJK SC, whose `Hans` faces the UI now installs *before* the Japanese ones
for a Chinese reader, so shared Han characters keep the language's forms
(`fonts::cjk_fallback`); the export watermark accepts every CJK face.
`tr_format!` keeps its compile-time check. It formats the English source at the
call site — a runtime template cannot be handed to `format!` — and names those
values so a translation can place them by name (`{n}`) or position (`{_1}`).
Every translation is still checked by `format!`, so a translation with an
unknown placeholder fails the build. The Japanese catalog was rewritten from the
old `{:.0}` plural-discard trick to that by-name form; behaviour is unchanged.
Also: settings persist the BCP-47 code (never the Rust variant name),
`LIGHTCRAFT_LANGUAGE` accepts system-style tags (`zh_CN`, `ja_JP.UTF-8`),
`xtask parity` reads the second command table, and the glyph tests cover every
catalog character plus the interface symbols (`▸`/`▾` turned out to have no
glyph in any installed font and are gone from the Chinese text).
Chinese and Japanese both need `CRAFT_FONTS_DIR` as before; the web build still
embeds only the Japanese face (Noto Sans CJK SC alone would push the wasm past
Cloudflare's 25 MiB per-file cap), documented in docs/localization-zh-hans.md.
Co-Authored-By: DeepSeek V3.2 <noreply@deepseek.com>
2.4 KiB
2.4 KiB
LightCraft 日本語表示
LightCraft は日本語・簡体字中国語・英語(English)の表示に対応しています。
言語設定は ui.json の language に保存します。
- 「編集 → 言語」または「設定 → 一般 → 言語」で切り替えます。選択は次回起動にも引き継ぎます。
- メニュー、写真編集、マスク、切り抜き、設定、読み込み、書き出し、主な処理状況を翻訳しています。
- 通常表示と太字の双方に、SIL OFLのBIZ UDPGothicを使います。日本語フォントはこのリポジトリではなく
storytold/craft-fonts にあり、任意のビルド入力
CRAFT_FONTS_DIR=../craft-fontsを指定したビルド(公式リリースはすべて)に組み込まれます。 指定しない場合も動作しますが、日本語の文字は表示されません。 - 翻訳は表示層で行います。操作コマンドのID、写真のファイル名、入力したメタデータを変更しません。
- 翻訳されていない技術的なエラー、追加情報、リリースノートは英語で表示します。
- 中国語表示は
localization-zh-hans.mdを参照してください。 - 別の言語の追加方法は
localization.mdを参照してください。
翻訳の保守
静的な表示文言は crates/ui-egui/locales/ja.json、可変値を含む表示文言は
crates/ui-egui/locales/ja-formats.json にあります。英文をキーにして翻訳を管理します。
可変文言は、呼び出し側の英語の書式を format! がそのまま検査し、その値を翻訳側が
名前({n}、{total})または位置(_1、_2 …)で参照します。英語の単複数語尾のように
中国語・日本語で不要な値は、単に参照しないだけです({:.0} のような空の引数は不要)。
両言語の訳文はビルド時に format! の検査を受けるため、存在しない名前を書くとコンパイルエラーになります。
LIGHTCRAFT_LANGUAGE=ja lightcraft-cli snapshot ... で日本語の画面を描画できます。
表示・フォント・言語の切り替え・設定の保存・コマンドIDの保持は
cargo test -p lightcraft-ui-egui i18n::tests で検証します(グリフの検査は CRAFT_FONTS_DIR 指定時のみ実行)。