Skip to content

Commit 0a7a998

Browse files
author
Andrin Meier
committed
at runtime WPF localization with resx files using the "WPF Localization Using RESX Files" library (partially resolves #1014)
1 parent 8ba01d0 commit 0a7a998

30 files changed

+3491
-27
lines changed

Infralution.Localization.Wpf/CultureManager.cs

Lines changed: 402 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Window x:Class="Infralution.Localization.Wpf.CultureSelectWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:p="clr-namespace:Infralution.Localization.Wpf" Title="Select Culture" Height="90" Width="338" MinHeight="90" MinWidth="174" Topmost="True" Icon="{p:Resx ResxName=Infralution.Localization.Wpf.Properties.Resources, Key=UICultureIcon}" ResizeMode="NoResize" MaxWidth="Infinity" MaxHeight="90">
2+
<Grid>
3+
<ComboBox Margin="12,12,12,0" Name="_cultureCombo" Height="27" VerticalAlignment="Top" SelectionChanged="_cultureCombo_SelectionChanged" DisplayMemberPath="DisplayName" />
4+
</Grid>
5+
</Window>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Windows;
6+
using System.Windows.Controls;
7+
using System.Windows.Data;
8+
using System.Windows.Documents;
9+
using System.Windows.Input;
10+
using System.Windows.Media;
11+
using System.Windows.Media.Imaging;
12+
using System.Windows.Shapes;
13+
using System.Globalization;
14+
namespace Infralution.Localization.Wpf
15+
{
16+
/// <summary>
17+
/// Window that allows the user to select the culture to use at design time
18+
/// </summary>
19+
public partial class CultureSelectWindow : Window
20+
{
21+
22+
/// <summary>
23+
/// Handle sorting Culture Info
24+
/// </summary>
25+
private class CultureInfoComparer : Comparer<CultureInfo>
26+
{
27+
public override int Compare(CultureInfo x, CultureInfo y)
28+
{
29+
return x.DisplayName.CompareTo(y.DisplayName);
30+
}
31+
}
32+
33+
/// <summary>
34+
/// Create a new instance of the window
35+
/// </summary>
36+
public CultureSelectWindow()
37+
{
38+
InitializeComponent();
39+
List<CultureInfo> cultures = new List<CultureInfo>(CultureInfo.GetCultures(CultureTypes.SpecificCultures));
40+
cultures.Sort(new CultureInfoComparer());
41+
_cultureCombo.ItemsSource = cultures;
42+
_cultureCombo.SelectedItem = CultureManager.UICulture;
43+
}
44+
45+
46+
/// <summary>
47+
/// Set the CultureManager.UICulture
48+
/// </summary>
49+
/// <param name="sender"></param>
50+
/// <param name="e"></param>
51+
private void _cultureCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
52+
{
53+
CultureManager.UICulture = _cultureCombo.SelectedItem as CultureInfo;
54+
}
55+
}
56+
}
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>9.0.30729</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{E3D700D5-BDFB-4777-8E9C-53E8F943AC58}</ProjectGuid>
9+
<OutputType>library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>Infralution.Localization.Wpf</RootNamespace>
12+
<AssemblyName>Infralution.Localization.Wpf</AssemblyName>
13+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
16+
<WarningLevel>4</WarningLevel>
17+
<SignAssembly>true</SignAssembly>
18+
<AssemblyOriginatorKeyFile>StrongName.snk</AssemblyOriginatorKeyFile>
19+
<FileUpgradeFlags>
20+
</FileUpgradeFlags>
21+
<UpgradeBackupLocation>
22+
</UpgradeBackupLocation>
23+
<OldToolsVersion>3.5</OldToolsVersion>
24+
<TargetFrameworkProfile />
25+
<PublishUrl>publish\</PublishUrl>
26+
<Install>true</Install>
27+
<InstallFrom>Disk</InstallFrom>
28+
<UpdateEnabled>false</UpdateEnabled>
29+
<UpdateMode>Foreground</UpdateMode>
30+
<UpdateInterval>7</UpdateInterval>
31+
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
32+
<UpdatePeriodically>false</UpdatePeriodically>
33+
<UpdateRequired>false</UpdateRequired>
34+
<MapFileExtensions>true</MapFileExtensions>
35+
<ApplicationRevision>0</ApplicationRevision>
36+
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
37+
<IsWebBootstrapper>false</IsWebBootstrapper>
38+
<UseApplicationTrust>false</UseApplicationTrust>
39+
<BootstrapperEnabled>true</BootstrapperEnabled>
40+
</PropertyGroup>
41+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
42+
<DebugSymbols>true</DebugSymbols>
43+
<DebugType>full</DebugType>
44+
<Optimize>false</Optimize>
45+
<OutputPath>bin\Debug\</OutputPath>
46+
<DefineConstants>DEBUG;TRACE</DefineConstants>
47+
<ErrorReport>prompt</ErrorReport>
48+
<WarningLevel>4</WarningLevel>
49+
<DocumentationFile>bin\Debug\Infralution.Localization.Wpf.XML</DocumentationFile>
50+
<Prefer32Bit>false</Prefer32Bit>
51+
</PropertyGroup>
52+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
53+
<DebugType>pdbonly</DebugType>
54+
<Optimize>true</Optimize>
55+
<OutputPath>bin\Release\</OutputPath>
56+
<DefineConstants>TRACE</DefineConstants>
57+
<ErrorReport>prompt</ErrorReport>
58+
<WarningLevel>4</WarningLevel>
59+
<DocumentationFile>bin\Release\Infralution.Localization.Wpf.XML</DocumentationFile>
60+
<Prefer32Bit>false</Prefer32Bit>
61+
</PropertyGroup>
62+
<ItemGroup>
63+
<Reference Include="System" />
64+
<Reference Include="System.Core">
65+
<RequiredTargetFramework>3.5</RequiredTargetFramework>
66+
</Reference>
67+
<Reference Include="System.Data" />
68+
<Reference Include="System.Drawing" />
69+
<Reference Include="System.Management" />
70+
<Reference Include="System.Windows.Forms" />
71+
<Reference Include="System.Xaml" />
72+
<Reference Include="System.Xml" />
73+
<Reference Include="UIAutomationProvider">
74+
<RequiredTargetFramework>3.0</RequiredTargetFramework>
75+
</Reference>
76+
<Reference Include="WindowsBase">
77+
<RequiredTargetFramework>3.0</RequiredTargetFramework>
78+
</Reference>
79+
<Reference Include="PresentationCore">
80+
<RequiredTargetFramework>3.0</RequiredTargetFramework>
81+
</Reference>
82+
<Reference Include="PresentationFramework">
83+
<RequiredTargetFramework>3.0</RequiredTargetFramework>
84+
</Reference>
85+
</ItemGroup>
86+
<ItemGroup>
87+
<Compile Include="ResourceEnumConverter.cs" />
88+
<Compile Include="UICultureExtension.cs" />
89+
<Compile Include="MarkupExtensionManager.cs" />
90+
<Compile Include="ManagedMarkupExtension.cs" />
91+
<Compile Include="Properties\AssemblyInfo.cs">
92+
<SubType>Code</SubType>
93+
</Compile>
94+
<Compile Include="Properties\Resources.Designer.cs">
95+
<AutoGen>True</AutoGen>
96+
<DesignTime>True</DesignTime>
97+
<DependentUpon>Resources.resx</DependentUpon>
98+
</Compile>
99+
<Compile Include="Properties\Settings.Designer.cs">
100+
<AutoGen>True</AutoGen>
101+
<DependentUpon>Settings.settings</DependentUpon>
102+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
103+
</Compile>
104+
<Compile Include="ResxExtension.cs" />
105+
<Compile Include="CultureManager.cs" />
106+
<Compile Include="CultureSelectWindow.xaml.cs">
107+
<DependentUpon>CultureSelectWindow.xaml</DependentUpon>
108+
</Compile>
109+
<EmbeddedResource Include="Properties\Resources.resx">
110+
<Generator>ResXFileCodeGenerator</Generator>
111+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
112+
<SubType>Designer</SubType>
113+
</EmbeddedResource>
114+
<None Include="Properties\Settings.settings">
115+
<Generator>SettingsSingleFileGenerator</Generator>
116+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
117+
</None>
118+
<AppDesigner Include="Properties\" />
119+
<EmbeddedResource Include="Properties\Resources.fr.resx">
120+
<SubType>Designer</SubType>
121+
<DependentUpon>Resources.resx</DependentUpon>
122+
</EmbeddedResource>
123+
<EmbeddedResource Include="Properties\Resources.de.resx">
124+
<SubType>Designer</SubType>
125+
<DependentUpon>Resources.resx</DependentUpon>
126+
</EmbeddedResource>
127+
<EmbeddedResource Include="Properties\Resources.it.resx">
128+
<SubType>Designer</SubType>
129+
<DependentUpon>Resources.resx</DependentUpon>
130+
</EmbeddedResource>
131+
</ItemGroup>
132+
<ItemGroup>
133+
<Page Include="CultureSelectWindow.xaml">
134+
<SubType>Designer</SubType>
135+
<Generator>MSBuild:Compile</Generator>
136+
</Page>
137+
</ItemGroup>
138+
<ItemGroup>
139+
<None Include="Resources\UICultureIcon.ico" />
140+
<None Include="StrongName.snk" />
141+
</ItemGroup>
142+
<ItemGroup>
143+
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
144+
<Visible>False</Visible>
145+
<ProductName>.NET Framework 3.5 SP1</ProductName>
146+
<Install>true</Install>
147+
</BootstrapperPackage>
148+
</ItemGroup>
149+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
150+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
151+
Other similar extension points exist, see Microsoft.Common.targets.
152+
<Target Name="BeforeBuild">
153+
</Target>
154+
<Target Name="AfterBuild">
155+
</Target>
156+
-->
157+
</Project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 10.00
3+
# Visual Studio 2008
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infralution.Localization.Wpf", "Infralution.Localization.Wpf.csproj", "{E3D700D5-BDFB-4777-8E9C-53E8F943AC58}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|Any CPU = Debug|Any CPU
9+
Release|Any CPU = Release|Any CPU
10+
EndGlobalSection
11+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
12+
{E3D700D5-BDFB-4777-8E9C-53E8F943AC58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13+
{E3D700D5-BDFB-4777-8E9C-53E8F943AC58}.Debug|Any CPU.Build.0 = Debug|Any CPU
14+
{E3D700D5-BDFB-4777-8E9C-53E8F943AC58}.Release|Any CPU.ActiveCfg = Release|Any CPU
15+
{E3D700D5-BDFB-4777-8E9C-53E8F943AC58}.Release|Any CPU.Build.0 = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(SolutionProperties) = preSolution
18+
HideSolutionNode = FALSE
19+
EndGlobalSection
20+
EndGlobal

0 commit comments

Comments
 (0)