2.5 KiB
2.5 KiB
description, applyTo
| description | applyTo |
|---|---|
| Globalization & Localization requirements for user-facing strings, resource files, and culture-aware formatting | **/*.cs, **/*.xaml, **/*.resw |
Globalization & Localization
These rules apply to every feature and change involving user-facing text. They are not optional add-ons.
Rules
- All user-facing strings (UI text, error messages, tooltips) must come from
.reswresource files — never hard-code them in XAML or C#. - Resource file location:
Strings/en-us/Resources.resw(default locale). - Use
x:Uidin XAML to bind controls to resource keys:With a matching<TextBlock x:Uid="WelcomeMessage" />.reswentry:WelcomeMessage.Text= "Welcome!" - In code-behind / ViewModels, use the
ResourceLoader:var loader = new Microsoft.Windows.ApplicationModel.Resources.ResourceLoader(); string message = loader.GetString("ErrorFileNotFound"); - Format dates, numbers, and currencies using
CultureInfo.CurrentCultureorDateTimeFormatter— never assume a specific regional format. - Avoid concatenating translated strings — use format placeholders (
{0},{1}). - Design UI layouts to accommodate text expansion (~30-40% longer for German vs. English).
Anti-patterns
- Hard-coded strings in
.xamlor.csfiles (e.g.,Content="Save"). - Using
string.Formatwith hard-coded ordinal assumptions. - Fixed-width UI elements that clip translated text.
Validation
- Build & register the MSIX package — see Build, Run & Deploy in
.github/agents/Agents.md. - Check for hard-coded strings: search
Content="andText="in.xamlfiles — replace withx:Uid.
Verification Checklist
- All user-facing strings are in
.reswresource files
Must Read & Research
Agent Rule: Before any localization-related change, you must fetch and review these references using
fetch_webpage. Apply what you learn.
| # | Reference | When to consult |
|---|---|---|
| 1 | Globalize your WinUI app | Adding any new user-facing strings or culture-aware formatting |
| 2 | Resource Management System | Setting up or modifying .resw files and ResourceLoader usage |
| 3 | WinUI Localization with x:Uid | Binding XAML controls to localized resources via x:Uid |