Skip to content

Commit

Permalink
Merge pull request #1040 from autoboosh/localization
Browse files Browse the repository at this point in the history
add runtime WPF localization with resx files using the "WPF Localizati…
  • Loading branch information
retailcoder committed Feb 10, 2016
2 parents 6c60cfc + 9fb74f1 commit 0588974
Show file tree
Hide file tree
Showing 14 changed files with 1,072 additions and 27 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,9 @@ For more information, please see the EULAs in the [./Resources/Microsoft/ direct

* [Visual Studio 2013 Image Library EULA](https://github.com/retailcoder/Rubberduck/blob/master/RetailCoder.VBE/Resources/Microsoft/Visual%20Studio%202013%20Image%20Library%20EULA.rtf)
* [Visual Studio 2012 Image Library EULA](https://github.com/retailcoder/Rubberduck/blob/master/RetailCoder.VBE/Resources/Microsoft/Visual%20Studio%202012%20Image%20Library%20EULA.rtf)

###[WPF Localization Using RESX Files](http://www.codeproject.com/Articles/35159/WPF-Localization-Using-RESX-Files)

This library makes localizing WPF applications at runtime using resx files a breeze. Thank you [Grant Frisken](http://www.codeproject.com/script/Membership/View.aspx?mid=1079060)!

> Licensed under [The Code Project Open License](http://www.codeproject.com/info/cpol10.aspx).
3 changes: 2 additions & 1 deletion RetailCoder.VBE/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Rubberduck.UI.Command.MenuItems;
using Rubberduck.UI.ParserErrors;
using Rubberduck.VBEditor.Extensions;
using Infralution.Localization.Wpf;

namespace Rubberduck
{
Expand Down Expand Up @@ -189,7 +190,7 @@ private void LoadConfig()
var currentCulture = RubberduckUI.Culture;
try
{
RubberduckUI.Culture = CultureInfo.GetCultureInfo(_config.UserSettings.LanguageSetting.Code);
CultureManager.UICulture = CultureInfo.GetCultureInfo(_config.UserSettings.LanguageSetting.Code);
_appMenus.Localize();
}
catch (CultureNotFoundException exception)
Expand Down
17 changes: 17 additions & 0 deletions RetailCoder.VBE/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using Ninject.Extensions.Factory;
using Rubberduck.Root;
using Rubberduck.UI;
using System.Reflection;
using System.IO;

namespace Rubberduck
{
Expand Down Expand Up @@ -36,6 +38,9 @@ public void OnConnection(object Application, ext_ConnectMode ConnectMode, object
{
try
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += LoadFromSameFolder;

_kernel.Load(new RubberduckModule(_kernel, (VBE)Application, (AddIn)AddInInst));
_kernel.Load(new UI.SourceControl.SourceControlBindings());
_kernel.Load(new CommandBarsModule(_kernel));
Expand All @@ -49,6 +54,18 @@ public void OnConnection(object Application, ext_ConnectMode ConnectMode, object
}
}

Assembly LoadFromSameFolder(object sender, ResolveEventArgs args)
{
string folderPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string assemblyPath = Path.Combine(folderPath, new AssemblyName(args.Name).Name + ".dll");
if (!File.Exists(assemblyPath))
{
return null;
}
Assembly assembly = Assembly.LoadFrom(assemblyPath);
return assembly;
}

public void OnStartupComplete(ref Array custom)
{
}
Expand Down
3 changes: 3 additions & 0 deletions RetailCoder.VBE/Rubberduck.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@
<Reference Include="extensibility, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Infralution.Localization.Wpf">
<HintPath>..\libs\Infralution.Localization.Wpf.dll</HintPath>
</Reference>
<Reference Include="Ninject.Extensions.Conventions">
<HintPath>..\packages\ninject.extensions.conventions.3.2.0.0\lib\net45-full\Ninject.Extensions.Conventions.dll</HintPath>
</Reference>
Expand Down
6 changes: 4 additions & 2 deletions RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:componentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase"
xmlns:codeExplorer="clr-namespace:Rubberduck.Navigation.CodeExplorer"
ResxExtension.DefaultResxName="Rubberduck.UI.RubberduckUI"
Language="{UICulture}"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance codeExplorer:CodeExplorerViewModel}">
<UserControl.Resources>
Expand Down Expand Up @@ -185,11 +187,11 @@
<Button Style="{StaticResource LinkButton}" Margin="4"
Visibility="{Binding CanExecuteRefactorRename, Converter={StaticResource BoolToVisibility}}"
Command="{Binding RefactorRenameCommand}"
Content="{x:Static resx:RubberduckUI.RefactorMenu_Rename}" />
Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=RefactorMenu_Rename}" />
<Button Style="{StaticResource LinkButton}" Margin="4"
Visibility="{Binding CanExecuteFindAllReferences, Converter={StaticResource BoolToVisibility}}"
Command="{Binding FindAllReferencesCommand}"
Content="{x:Static resx:RubberduckUI.ContextMenu_FindAllReferences}" />-->
Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=ContextMenu_FindAllReferences}" />-->
</WrapPanel>
</Grid>
</Border>
Expand Down
10 changes: 6 additions & 4 deletions RetailCoder.VBE/UI/CodeInspections/InspectionResultsControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:codeInspections="clr-namespace:Rubberduck.UI.CodeInspections"
xmlns:componentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase"
ResxExtension.DefaultResxName="Rubberduck.UI.RubberduckUI"
Language="{UICulture}"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance codeInspections:InspectionResultsViewModel}">
<UserControl.Resources>
Expand Down Expand Up @@ -204,7 +206,7 @@
<Separator />
<Menu>
<MenuItem VerticalAlignment="Center"
Header="{x:Static resx:RubberduckUI.Fix}"
Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=Fix}"
ItemsSource="{Binding SelectedItem.QuickFixes}">
<MenuItem.Icon>
<Image Height="16" Source="../../Resources/tick.png" />
Expand Down Expand Up @@ -263,15 +265,15 @@
<Button Style="{StaticResource LinkButton}" Margin="4"
Visibility="{Binding CanExecuteQuickFixInModule, Converter={StaticResource BoolToVisibility}}"
Command="{Binding QuickFixInModuleCommand}"
Content="{x:Static resx:RubberduckUI.QuickFix_ThisModule}" />
Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=QuickFix_ThisModule}" />
<Button Style="{StaticResource LinkButton}" Margin="4"
Visibility="{Binding CanExecuteQuickFixInProject, Converter={StaticResource BoolToVisibility}}"
Command="{Binding QuickFixInProjectCommand}"
Content="{x:Static resx:RubberduckUI.QuickFix_ThisProject}" />
Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=QuickFix_ThisProject}" />
<Button Style="{StaticResource LinkButton}" Margin="4"
Visibility="{Binding CanDisableInspection, Converter={StaticResource BoolToVisibility}}"
Command="{Binding DisableInspectionCommand}"
Content="{x:Static resx:RubberduckUI.DisableThisInspection}" />
Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=DisableThisInspection}" />
</WrapPanel>
</StackPanel>
</Border>
Expand Down
15 changes: 8 additions & 7 deletions RetailCoder.VBE/UI/ToDoItems/ToDoExplorerControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
xmlns:toDoItems="clr-namespace:Rubberduck.UI.ToDoItems"
xmlns:controls="clr-namespace:Rubberduck.Controls"
xmlns:themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero2" x:Class="Rubberduck.UI.ToDoItems.ToDoExplorerControl"
Language="{UICulture}"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance {x:Type toDoItems:ToDoExplorerViewModel}, IsDesignTimeCreatable=False}">
<UserControl.Resources>
Expand Down Expand Up @@ -240,11 +241,11 @@
<DockPanel LastChildFill="True">
<ToolBarTray DockPanel.Dock="Top" IsLocked="True">
<ToolBar Style="{DynamicResource ToolBarWithOverflowOnlyShowingWhenNeededStyle}">
<Button ToolTip="{x:Static resx:RubberduckUI.Refresh}" Command="{Binding RefreshCommand, Mode=OneWay}" BorderThickness="0" Background="Transparent">
<Button ToolTip="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=Refresh}" Command="{Binding RefreshCommand, Mode=OneWay}" BorderThickness="0" Background="Transparent">
<Image Source="{StaticResource RefreshImage}" />
</Button>
<Separator />
<Button ToolTip="{x:Static resx:RubberduckUI.Remove}" Command="{Binding Remove}" BorderThickness="0" Background="Transparent">
<Button ToolTip="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=Remove}" Command="{Binding Remove}" BorderThickness="0" Background="Transparent">
<Image Source="{StaticResource DeleteImage}" />
</Button>
</ToolBar>
Expand All @@ -263,11 +264,11 @@
</Style>
</controls:GroupingGrid.CellStyle>
<controls:GroupingGrid.Columns>
<DataGridTextColumn Header="{x:Static resx:RubberduckUI.Priority}" Binding="{Binding Priority}" />
<DataGridTextColumn Header="{x:Static resx:RubberduckUI.TodoExplorer_Description}" Binding="{Binding Description}" Width="*"/>
<DataGridTextColumn Header="{x:Static resx:RubberduckUI.ProjectName}" Binding="{Binding ProjectName}" />
<DataGridTextColumn Header="{x:Static resx:RubberduckUI.ModuleName}" Binding="{Binding ModuleName}" />
<DataGridTextColumn Header="{x:Static resx:RubberduckUI.TodoExplorer_LineNumber}" Binding="{Binding LineNumber}" />
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=Priority}" Binding="{Binding Priority}" />
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=TodoExplorer_Description}" Binding="{Binding Description}" Width="*"/>
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=ProjectName}" Binding="{Binding ProjectName}" />
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=ModuleName}" Binding="{Binding ModuleName}" />
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=TodoExplorer_LineNumber}" Binding="{Binding LineNumber}" />
</controls:GroupingGrid.Columns>
</controls:GroupingGrid>
</DockPanel>
Expand Down
23 changes: 12 additions & 11 deletions RetailCoder.VBE/UI/UnitTesting/TestExplorerControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
xmlns:unitTesting="clr-namespace:Rubberduck.UnitTesting"
xmlns:resx="clr-namespace:Rubberduck.UI"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
Language="{UICulture}"
mc:Ignorable="d"
d:DesignHeight="255" d:DesignWidth="255"
MinWidth="255" MinHeight="255" d:DataContext="{d:DesignInstance local:TestExplorerViewModel}">
Expand Down Expand Up @@ -119,52 +120,52 @@
<Separator />

<Menu>
<MenuItem VerticalAlignment="Center" Header="{x:Static resx:RubberduckUI.Run}">
<MenuItem VerticalAlignment="Center" Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=RubberduckUI.Run}">
<MenuItem.Icon>
<Image Height="16" Source="../../Resources/control.png" />
</MenuItem.Icon>
<MenuItem Command="{Binding RunAllTestsCommand}" Header="{x:Static resx:RubberduckUI.TestExplorer_RunAllTests}">
<MenuItem Command="{Binding RunAllTestsCommand}" Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=TestExplorer_RunAllTests}">
<MenuItem.Icon>
<Image Height="16" Source="../../Resources/flask--arrow.png" />
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem Command="{Binding RunNotExecutedTestsCommand}" Header="{x:Static resx:RubberduckUI.TestExplorer_RunNotRunTests}" >
<MenuItem Command="{Binding RunNotExecutedTestsCommand}" Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=TestExplorer_RunNotRunTests}" >
<MenuItem.Icon>
<Image Height="16" Source="../../Resources/question-white.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Command="{Binding RunPassedTestsCommand}" Header="{x:Static resx:RubberduckUI.TestExplorer_RunPassedTests}" >
<MenuItem Command="{Binding RunPassedTestsCommand}" Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=TestExplorer_RunPassedTests}" >
<MenuItem.Icon>
<Image Height="16" Source="../../Resources/tick-circle.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Command="{Binding RunFailedTestsCommand}" Header="{x:Static resx:RubberduckUI.TestExplorer_RunFailedTests}">
<MenuItem Command="{Binding RunFailedTestsCommand}" Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=TestExplorer_RunFailedTests}">
<MenuItem.Icon>
<Image Height="16" Source="../../Resources/cross-circle.png" />
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem Command="{Binding RepeatLastRunCommand}" Header="{x:Static resx:RubberduckUI.TestExplorer_RunLastRunTests}">
<MenuItem Command="{Binding RepeatLastRunCommand}" Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=TestExplorer_RunLastRunTests}">
<MenuItem.Icon>
<Image Height="16" Source="../../Resources/arrow-repeat.png" />
</MenuItem.Icon>
</MenuItem>

</MenuItem>
<MenuItem VerticalAlignment="Center" Header="{x:Static resx:RubberduckUI.Add}">
<MenuItem VerticalAlignment="Center" Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=Add}">
<MenuItem.Icon>
<Image Height="16" Source="../../Resources/flask--plus.png" />
</MenuItem.Icon>
<MenuItem Command="{Binding AddTestModuleCommand}" Header="{x:Static resx:RubberduckUI.TestExplorer_AddTestModule}">
<MenuItem Command="{Binding AddTestModuleCommand}" Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=TestExplorer_AddTestModule}">
</MenuItem>
<Separator />
<MenuItem Command="{Binding AddTestMethodCommand}" Header="{x:Static resx:RubberduckUI.TestExplorer_AddTestMethod}">
<MenuItem Command="{Binding AddTestMethodCommand}" Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=TestExplorer_AddTestMethod}">
<MenuItem.Icon>
<Image Height="16" Source="../../Resources/flask.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Command="{Binding AddErrorTestMethodCommand}" Header="{x:Static resx:RubberduckUI.TestExplorer_AddExpectedErrorTestMethod}">
<MenuItem Command="{Binding AddErrorTestMethodCommand}" Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=TestExplorer_AddExpectedErrorTestMethod}">
<MenuItem.Icon>
<Image Height="16" Source="../../Resources/flask--exclamation.png" />
</MenuItem.Icon>
Expand Down Expand Up @@ -209,7 +210,7 @@
<TreeView.ContextMenu>
<ContextMenu>
<MenuItem VerticalAlignment="Center"
Header="{x:Static resx:RubberduckUI.Run}"
Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=Run}"
Command="{Binding RunSelectedTestCommand}"
IsEnabled="{Binding Model.IsReady, Mode=OneWay}">
<MenuItem.Icon>
Expand Down
4 changes: 2 additions & 2 deletions Rubberduck.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.40629.0
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rubberduck", "RetailCoder.VBE\Rubberduck.csproj", "{20589DE8-432E-4359-9232-69EB070B7185}"
ProjectSection(ProjectDependencies) = postProject
Expand Down

0 comments on commit 0588974

Please sign in to comment.