Skip to content

Commit

Permalink
(chocolateyGH-533) Added ability to notify when language is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmiringWorm committed Jan 17, 2019
1 parent 274a277 commit d044fd0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Source/ChocolateyGui/ChocolateyGui.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -310,6 +310,7 @@
<Compile Include="Utilities\Extensions\MvvmExtensions.cs" />
<Compile Include="Utilities\IDataGridColumnComparer.cs" />
<Compile Include="Utilities\ResourceReader.cs" />
<Compile Include="Utilities\TranslationSource.cs" />
<Compile Include="ViewModels\AboutViewModel.cs" />
<Compile Include="ViewModels\ISourceViewModelBase.cs" />
<Compile Include="Utilities\Converters\BooleanToVisibility.cs" />
Expand Down
40 changes: 40 additions & 0 deletions Source/ChocolateyGui/Utilities/TranslationSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright company="Chocolatey" file="TranslationSource.cs">
// Copyright 2014 - Present Rob Reynolds, the maintainers of Chocolatey, and RealDimensions Software, LLC
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System.Globalization;
using System.Resources;
using ChocolateyGui.Base;
using ChocolateyGui.Properties;

namespace ChocolateyGui.Utilities
{
public sealed class TranslationSource : ObservableBase
{
private readonly ResourceManager resourceManager = Resources.ResourceManager;
private CultureInfo currentCulture = null;

public static TranslationSource Instance { get; } = new TranslationSource();

public CultureInfo CurrentCulture
{
get
{
return currentCulture;
}

set
{
if (currentCulture != value)
{
currentCulture = value;
NotifyPropertyChanged(string.Empty); // We call with an empty string on purpose to force an update for all resource strings.
}
}
}

public string this[string key] => resourceManager.GetString(key, CurrentCulture);
}
}

0 comments on commit d044fd0

Please sign in to comment.