• Add Brazilian Portuguese (pt-BR) translation file • Add European Portuguese (pt-PT) translation file • Implement BCP 47 locale normalization system • Create fallback chain for language variants • Add default variant mapping for Portuguese • Update help text to show variant examples • Add comprehensive test suite for variants • Create documentation for i18n variant architecture
3.8 KiB
Language Variants Support in Fabric
Current Implementation
As of this update, Fabric supports Portuguese language variants:
pt-BR- Brazilian Portuguesept-PT- European Portuguesept- defaults topt-BRfor backward compatibility
Architecture
The i18n system supports language variants through:
- BCP 47 Format: All locales are normalized to BCP 47 format (language-REGION)
- Fallback Chain: Regional variants fall back to base language, then to configured defaults
- Default Variant Mapping: Languages without base files can specify default regional variants
- Flexible Input: Accepts both underscore (pt_BR) and hyphen (pt-BR) formats
Recommended Future Variants
Based on user demographics and linguistic differences, these variants would provide the most value:
High Priority
-
Chinese Variants
zh-CN- Simplified Chinese (Mainland China)zh-TW- Traditional Chinese (Taiwan)zh-HK- Traditional Chinese (Hong Kong)- Default:
zh→zh-CN - Rationale: Significant script and vocabulary differences
-
Spanish Variants
es-ES- European Spanish (Spain)es-MX- Mexican Spanishes-AR- Argentinian Spanish- Default:
es→es-ES - Rationale: Notable vocabulary and conjugation differences
-
English Variants
en-US- American Englishen-GB- British Englishen-AU- Australian English- Default:
en→en-US - Rationale: Spelling differences (color/colour, organize/organise)
-
French Variants
fr-FR- France Frenchfr-CA- Canadian French- Default:
fr→fr-FR - Rationale: Some vocabulary and expression differences
-
Arabic Variants
ar-SA- Saudi Arabic (Modern Standard)ar-EG- Egyptian Arabic- Default:
ar→ar-SA - Rationale: Significant dialectal differences
-
German Variants
de-DE- Germany Germande-AT- Austrian Germande-CH- Swiss German- Default:
de→de-DE - Rationale: Minor differences, mostly vocabulary
Implementation Guidelines
When adding new language variants:
-
Determine the Base: Decide which variant should be the default
-
Create Variant Files: Copy base file and adjust for regional differences
-
Update Default Map: Add to
defaultLanguageVariantsif needed -
Focus on Key Differences:
- Technical terminology
- Common UI terms (file/ficheiro, save/guardar)
- Date/time formats
- Currency references
- Formal/informal address conventions
-
Test Thoroughly: Ensure fallback chain works correctly
Adding a New Variant
To add a new language variant:
-
Copy the base language file:
cp locales/es.json locales/es-MX.json -
Adjust translations for regional differences
-
If this is the first variant for a language, update
i18n.go:var defaultLanguageVariants = map[string]string{ "pt": "pt-BR", "es": "es-MX", // Add if Mexican Spanish should be default } -
Add tests for the new variant
-
Update documentation
Language Variant Naming Convention
Follow BCP 47 standards:
- Language code: lowercase (pt, es, en)
- Region code: uppercase (BR, PT, US)
- Separator: hyphen (pt-BR, not pt_BR)
Input normalization handles various formats, but files and internal references should use BCP 47.
Testing Variants
Test each variant with:
# Direct specification
fabric --help -g=pt-BR
fabric --help -g=pt-PT
# Environment variable
LANG=pt_BR.UTF-8 fabric --help
# Fallback behavior
fabric --help -g=pt # Should use pt-BR
Maintenance Considerations
When updating translations:
- Update all variants of a language together
- Ensure key parity across all variants
- Test fallback behavior after changes
- Consider using translation memory tools for consistency