How translation routers work
maini18n-tasks uses routers to determine how and where translation keys are written to files. There are three types:
- Conservative router (Default): Keeps keys where they are found or infers the path from the base locale. If a key is entirely new, it falls back to
pattern_routerbehavior. - Pattern router: Organizes keys based on a list of key patterns. Matches are processed from top to bottom.
- Isolating router: Assumes each YAML file is independent. It writes translations to an alternate target file for each source file (only changing the
%{locale}part). This is useful for avoiding collisions in setups like ViewComponent sidecars, though it cannot detect missing keys from code usage due to lack of scope awareness.
To reorganize existing keys using a pattern router, use the normalize -p command.
# Example Pattern Router configuration
data:
router: pattern_router
write:
- ["{models,views}.*", 'config/locales/\1.%{locale}.yml']
- ["{:}.*", 'config/locales/\1.%{locale}.yml']
- "config/locales/%{locale}.yml"