aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-06-17 01:05:24 +0800
committer魏曹先生 <1992414357@qq.com>2026-06-17 01:05:24 +0800
commit1957ba706f62a82a9f60df1f28e23de5fa8bb319 (patch)
treefae07ade0aba30a1d0ad66344e4d1f61116f2074 /README.md
parentc9685671512b05ec9b4caba2b7079382120cce1c (diff)
Implement fallback chain resolution for translation keys
Diffstat (limited to 'README.md')
-rw-r--r--README.md25
1 files changed, 25 insertions, 0 deletions
diff --git a/README.md b/README.md
index e4ea242..628daed 100644
--- a/README.md
+++ b/README.md
@@ -71,6 +71,31 @@ You can also pass the return value of another translation as a parameter, since
let greeting = Global::greeting(Global::world());
```
+## 5. Fallback Chain (Optional)
+
+You can configure a **fallback chain** in your `Cargo.toml` under `[package.metadata.shakehand]`.
+
+When a language has no translation for a key, the system will automatically walk the chain
+ to find the nearest language that has one.
+
+```toml
+[package.metadata.shakehand]
+# For any language not explicitly listed, fall back to English
+fallback.other = "en"
+
+# Specific fallback rules
+fallback.zh_HK = "zh_CN" # Hong Kong Trad -> Simplified Chinese
+fallback.zh_TW = "zh_CN" # Taiwan Trad -> Simplified Chinese
+fallback.zh_CN = "en" # Simplified Chinese -> English
+fallback.it = "fr" # Italian -> French
+```
+
+The chain resolution is **at runtime via a generated `FallbackSolver`**:
+- Each language has a `try_fallback_once()` step defined in a compile-time generated match.
+- Translation functions loop through the chain until a language with the value is found.
+- `fallback.other` is the ultimate fallback (falls back to `locale!`'s `fallback` parameter if unset).
+- All languages in the chain are automatically added to the `Languages` enum, even if they
+ have no translations in the locale files.
# Contributing