localizing-wpf-applications
Localizes WPF applications using resource files, x:Uid, and BAML localization. Use when building multi-language applications or supporting right-to-left layouts.
What this skill does
# WPF Localization Patterns
Implementing multi-language support in WPF applications.
## 1. Localization Overview
```
Localization Approaches
├── Resource Files (.resx)
│ ├── Simple string lookup
│ └── Strongly-typed access
├── BAML Localization
│ ├── x:Uid attributes
│ └── LocBaml tool
└── Runtime Features
├── FlowDirection (RTL support)
├── Culture-aware formatting
└── Dynamic language switching
```
---
## 2. Resource File Approach
### 2.1 Creating Resource Files
```
Project Structure:
├── Properties/
│ └── Resources.resx (default/fallback)
├── Resources/
│ ├── Strings.resx (default English)
│ ├── Strings.ko-KR.resx (Korean)
│ ├── Strings.ja-JP.resx (Japanese)
│ └── Strings.de-DE.resx (German)
```
### 2.2 Resource File Content
**Strings.resx (English - default):**
```xml
<data name="AppTitle" xml:space="preserve">
<value>My Application</value>
</data>
<data name="WelcomeMessage" xml:space="preserve">
<value>Welcome, {0}!</value>
</data>
<data name="SaveButton" xml:space="preserve">
<value>Save</value>
</data>
<data name="CancelButton" xml:space="preserve">
<value>Cancel</value>
</data>
```
**Strings.ko-KR.resx (Korean):**
```xml
<data name="AppTitle" xml:space="preserve">
<value>My Application (Korean translation)</value>
</data>
<data name="WelcomeMessage" xml:space="preserve">
<value>Welcome, {0}! (Korean translation)</value>
</data>
<data name="SaveButton" xml:space="preserve">
<value>Save (Korean translation)</value>
</data>
<data name="CancelButton" xml:space="preserve">
<value>Cancel (Korean translation)</value>
</data>
```
### 2.3 Using Resources in XAML
```xml
<Window xmlns:p="clr-namespace:MyApp.Resources">
<Window.Title>
<Binding Source="{x:Static p:Strings.AppTitle}"/>
</Window.Title>
<StackPanel>
<TextBlock Text="{x:Static p:Strings.WelcomeMessage}"/>
<Button Content="{x:Static p:Strings.SaveButton}"/>
<Button Content="{x:Static p:Strings.CancelButton}"/>
</StackPanel>
</Window>
```
### 2.4 Using Resources in Code
```csharp
using MyApp.Resources;
// Direct access
var title = Strings.AppTitle;
// Formatted string
var welcome = string.Format(Strings.WelcomeMessage, userName);
// Access by key (for dynamic keys)
var value = Strings.ResourceManager.GetString("SaveButton");
```
---
## 3. Setting Culture
### 3.1 At Application Startup
```csharp
namespace MyApp;
using System.Globalization;
using System.Threading;
using System.Windows;
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
// Set culture from user settings or system
var cultureName = GetSavedCulture() ?? CultureInfo.CurrentCulture.Name;
SetCulture(cultureName);
}
public static void SetCulture(string cultureName)
{
var culture = new CultureInfo(cultureName);
// Set for current thread
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
// Set for new threads (.NET 4.6+)
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
}
private string? GetSavedCulture()
{
return Properties.Settings.Default.Culture;
}
}
```
### 3.2 Dynamic Language Switching
```csharp
namespace MyApp.Services;
using System.Globalization;
using System.Threading;
using System.Windows;
public sealed class LocalizationService
{
public event EventHandler? CultureChanged;
public CultureInfo CurrentCulture => Thread.CurrentThread.CurrentUICulture;
public void ChangeCulture(string cultureName)
{
var culture = new CultureInfo(cultureName);
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
// Save preference
Properties.Settings.Default.Culture = cultureName;
Properties.Settings.Default.Save();
// Notify subscribers
CultureChanged?.Invoke(this, EventArgs.Empty);
// Restart required for full XAML update
RestartApplication();
}
private void RestartApplication()
{
var result = MessageBox.Show(
"Application needs to restart to apply language change. Restart now?",
"Language Changed",
MessageBoxButton.YesNo);
if (result == MessageBoxResult.Yes)
{
System.Diagnostics.Process.Start(Application.ResourceAssembly.Location);
Application.Current.Shutdown();
}
}
}
```
---
## 4. Related Skills
| Skill | Description |
|-------|-------------|
| `/localizing-wpf-with-baml` | BAML localization with x:Uid and LocBaml tool |
| `/implementing-wpf-rtl-support` | RTL layout support for Arabic, Hebrew |
| `/formatting-culture-aware-data` | Date, number, currency formatting + converters |
---
## 5. Language Selection UI
```xml
<ComboBox x:Name="LanguageSelector"
SelectionChanged="LanguageSelector_SelectionChanged">
<ComboBoxItem Tag="en-US" Content="English"/>
<ComboBoxItem Tag="ko-KR" Content="Korean"/>
<ComboBoxItem Tag="ja-JP" Content="Japanese"/>
<ComboBoxItem Tag="de-DE" Content="German"/>
</ComboBox>
```
```csharp
private void LanguageSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (LanguageSelector.SelectedItem is ComboBoxItem item)
{
var cultureName = item.Tag?.ToString();
if (!string.IsNullOrEmpty(cultureName))
{
_localizationService.ChangeCulture(cultureName);
}
}
}
```
---
## 6. References
- [WPF Globalization and Localization Overview - Microsoft Docs](https://learn.microsoft.com/en-us/dotnet/desktop/wpf/advanced/wpf-globalization-and-localization-overview)
- [Localizing XAML - Microsoft Docs](https://learn.microsoft.com/en-us/dotnet/desktop/wpf/advanced/how-to-localize-an-application)
- [CultureInfo Class - Microsoft Docs](https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo)
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.