source code checkin

This commit is contained in:
Brett Hewitson 2021-01-07 16:23:23 +10:00
parent 5f8fb2c825
commit 7e57b72e35
675 changed files with 168433 additions and 0 deletions

View file

@ -0,0 +1,120 @@
// See license at end of the file
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Windows;
namespace WPFSharp.Globalizer
{
public class AvailableLanguages : List<string>, INotifyPropertyChanged
{
public static AvailableLanguages Instance { get; set; }
public static void CreateInstance()
{
Instance = new AvailableLanguages();
}
private AvailableLanguages()
{
GlobalizedApplication.Instance.GlobalizationManager.ResourceDictionaryChangedEvent += GlobalizationManager_ResourceDictionaryChangedEvent;
}
private void GlobalizationManager_ResourceDictionaryChangedEvent(object sender, ResourceDictionaryChangedEventArgs e)
{
NotifyPropertyChanged("SelectedLanguage");
}
public string SelectedLanguage
{
get { return CultureInfo.CurrentCulture.IetfLanguageTag; }
}
public void AddListFromSubDirectories(string inPath)
{
if (Directory.Exists(inPath))
{
string[] dirs = Directory.GetDirectories(inPath);
foreach (var dir in dirs)
{
Add(Path.GetFileName(dir));
}
}
}
new public void Add(string inString)
{
base.Add(inString);
try
{
var ci = new CultureInfo(inString);
CultureInfoMap.Add(ci.IetfLanguageTag, ci.DisplayName);
}
catch (ArgumentException)
{
MessageBox.Show("Invalid language: " + inString);
throw;
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string inPropertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
var e = new PropertyChangedEventArgs(inPropertyName);
handler(this, e);
}
}
public Dictionary<string, string> CultureInfoMap { get; } = new Dictionary<string, string>();
}
}
#region License
/*
WPFSharp.Globalizer - A project deisgned to make localization and styling
easier by decoupling both process from the build.
Copyright (c) 2015, Jared Barneck (Rhyous)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Use of the source code or binaries that in any way competes with WPFSharp.Globalizer
or competes with distribution, whether open source or commercial, is
prohibited unless permission is specifically granted under a separate
license by Jared Barneck (Rhyous).
4. Forking for personal or internal, or non-competing commercial use is allowed.
Distributing compiled releases as part of your non-competing project is
allowed.
5. Public copies, or forks, of source is allowed, but from such, public
distribution of compiled releases is forbidden.
6. Source code enhancements or additions are the property of the author until
the source code is contributed to this project. By contributing the source
code to this project, the author immediately grants all rights to the
contributed source code to Jared Barneck (Rhyous).
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

View file

@ -0,0 +1,114 @@
// See license at end of the file
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
namespace WPFSharp.Globalizer
{
public class AvailableStyles : List<string>, INotifyPropertyChanged
{
public static AvailableStyles Instance { get; set; }
public static void CreateInstance()
{
Instance = new AvailableStyles();
}
private AvailableStyles()
{
SelectedStyle = StyleManager.FallBackStyle;
GlobalizedApplication.Instance.StyleManager.ResourceDictionaryChangedEvent += GlobalizationManager_ResourceDictionaryChangedEvent;
}
private void GlobalizationManager_ResourceDictionaryChangedEvent(object sender, ResourceDictionaryChangedEventArgs e)
{
NotifyPropertyChanged("SelectedStyle");
}
public string SelectedStyle
{
get; internal set;
}
public void AddListFromSubDirectories(string inPath)
{
if (Directory.Exists(inPath))
{
string[] dirs = Directory.GetDirectories(inPath);
foreach (var dir in dirs)
{
Add(Path.GetFileName(dir));
}
}
}
public void AddListFromFiles(string inPath)
{
if (Directory.Exists(inPath))
{
string[] files = Directory.GetFiles(inPath);
foreach (var file in files)
{
// Todo: Verify file is valid Style
Add(Path.GetFileNameWithoutExtension(file));
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string inPropertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
var e = new PropertyChangedEventArgs(inPropertyName);
handler(this, e);
}
}
}
}
#region License
/*
WPFSharp.Globalizer - A project deisgned to make localization and styling
easier by decoupling both process from the build.
Copyright (c) 2015, Jared Barneck (Rhyous)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Use of the source code or binaries that in any way competes with WPFSharp.Globalizer
or competes with distribution, whether open source or commercial, is
prohibited unless permission is specifically granted under a separate
license by Jared Barneck (Rhyous).
4. Forking for personal or internal, or non-competing commercial use is allowed.
Distributing compiled releases as part of your non-competing project is
allowed.
5. Public copies, or forks, of source is allowed, but from such, public
distribution of compiled releases is forbidden.
6. Source code enhancements or additions are the property of the author until
the source code is contributed to this project. By contributing the source
code to this project, the author immediately grants all rights to the
contributed source code to Jared Barneck (Rhyous).
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

View file

@ -0,0 +1,87 @@
// See license at end of the file
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using WPFSharp.Globalizer.Converters;
namespace WPFSharp.Globalizer.Controls
{
public class LanguageSelectionComboBox : ComboBox
{
public LanguageSelectionComboBox()
{
var itemSourceBinding = new Binding
{
Source = AvailableLanguages.Instance,
BindsDirectlyToSource = true
};
SetBinding(ItemsSourceProperty, itemSourceBinding);
ItemTemplate = new DataTemplate();
var binding = new Binding { Converter = new LanguageNameConverter() };
var textElement = new FrameworkElementFactory(typeof(TextBlock));
textElement.SetBinding(TextBlock.TextProperty, binding);
ItemTemplate.VisualTree = textElement;
SelectionChanged += LanguageSelectionComboBox_SelectionChanged;
var selectedItemBinding = new Binding("SelectedLanguage")
{
Source = AvailableLanguages.Instance,
Mode = BindingMode.OneWay
};
SetBinding(SelectedItemProperty, selectedItemBinding);
}
void LanguageSelectionComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var lang = e.AddedItems[0] as string;
if (!string.IsNullOrWhiteSpace(lang))
GlobalizedApplication.Instance.GlobalizationManager.SwitchLanguage(lang);
}
}
}
#region License
/*
WPFSharp.Globalizer - A project deisgned to make localization and styling
easier by decoupling both process from the build.
Copyright (c) 2015, Jared Barneck (Rhyous)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Use of the source code or binaries that in any way competes with WPFSharp.Globalizer
or competes with distribution, whether open source or commercial, is
prohibited unless permission is specifically granted under a separate
license by Jared Barneck (Rhyous).
4. Forking for personal or internal, or non-competing commercial use is allowed.
Distributing compiled releases as part of your non-competing project is
allowed.
5. Public copies, or forks, of source is allowed, but from such, public
distribution of compiled releases is forbidden.
6. Source code enhancements or additions are the property of the author until
the source code is contributed to this project. By contributing the source
code to this project, the author immediately grants all rights to the
contributed source code to Jared Barneck (Rhyous).
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

View file

@ -0,0 +1,93 @@
// See license at end of the file
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using WPFSharp.Globalizer.Converters;
namespace WPFSharp.Globalizer.Controls
{
public class LanguageSelectionMenuItemList : MenuItem
{
public LanguageSelectionMenuItemList()
{
ItemsSource = AvailableLanguages.Instance;
var checkableMenuItemStyle = new Style { TargetType = typeof(MenuItem) };
var headerBinding = new Binding { Converter = new LanguageNameConverter() };
var headerSetter = new Setter(HeaderProperty, headerBinding);
checkableMenuItemStyle.Setters.Add(headerSetter);
var isCheckableSetter = new Setter(IsCheckableProperty, true);
checkableMenuItemStyle.Setters.Add(isCheckableSetter);
ICommand command = new RelayCommand(SelectLanguage);
var commandSetter = new Setter(CommandProperty, command);
checkableMenuItemStyle.Setters.Add(commandSetter);
var commandParamBinding = new Binding();
var commandParamSetter = new Setter(CommandParameterProperty, commandParamBinding);
checkableMenuItemStyle.Setters.Add(commandParamSetter);
var isCheckedMultiBinding = new MultiBinding { Converter = new MultiValueStringsMatchConverter(), Mode = BindingMode.OneWay };
isCheckedMultiBinding.Bindings.Add(new Binding { Mode = BindingMode.OneWay });
isCheckedMultiBinding.Bindings.Add(new Binding("SelectedLanguage") { Source = AvailableLanguages.Instance, Mode = BindingMode.OneWay });
var isCheckedSetter = new Setter(IsCheckedProperty, isCheckedMultiBinding);
checkableMenuItemStyle.Setters.Add(isCheckedSetter);
Resources.Add(typeof(MenuItem), checkableMenuItemStyle);
}
public void SelectLanguage(object inLanguage)
{
var lang = inLanguage as string;
if (!string.IsNullOrWhiteSpace(lang))
GlobalizedApplication.Instance.GlobalizationManager.SwitchLanguage(lang);
}
}
}
#region License
/*
WPFSharp.Globalizer - A project deisgned to make localization and styling
easier by decoupling both process from the build.
Copyright (c) 2015, Jared Barneck (Rhyous)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Use of the source code or binaries that in any way competes with WPFSharp.Globalizer
or competes with distribution, whether open source or commercial, is
prohibited unless permission is specifically granted under a separate
license by Jared Barneck (Rhyous).
4. Forking for personal or internal, or non-competing commercial use is allowed.
Distributing compiled releases as part of your non-competing project is
allowed.
5. Public copies, or forks, of source is allowed, but from such, public
distribution of compiled releases is forbidden.
6. Source code enhancements or additions are the property of the author until
the source code is contributed to this project. By contributing the source
code to this project, the author immediately grants all rights to the
contributed source code to Jared Barneck (Rhyous).
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

View file

@ -0,0 +1,119 @@
// See license at end of the file
using System;
using System.Diagnostics;
using System.Windows.Input;
namespace WPFSharp.Globalizer.Controls
{
internal class RelayCommand : ICommand
{
#region Member variables
readonly Action<object> _Execute;
readonly Predicate<object> _CanExecute;
#endregion Member variables
#region Constructors
/// <summary>
/// Constructor for RelayCommand that only takes a method to run.
/// No CanExecute method is passed, so CanExecute will always be true.
/// </summary>
/// <param name="inMethodToExecute">The method to execute. Could be a lambda.</param>
public RelayCommand(Action<object> inMethodToExecute)
: this(inMethodToExecute, null)
{
}
/// <summary>
/// Constructor for RelayCommand that takes both a method to run
/// and a bool method to determine if it CanExecute.
/// </summary>
/// <param name="inMethodToExecute">The execution logic.</param>
/// <param name="inCanExecute">The execution status logic.</param>
public RelayCommand(Action<object> inMethodToExecute, Predicate<object> inCanExecute)
{
if (inMethodToExecute == null)
throw new ArgumentNullException("inMethodToExecute");
_Execute = inMethodToExecute;
_CanExecute = inCanExecute;
}
#endregion Constructors
#region ICommand Members
[DebuggerStepThrough]
public bool CanExecute(object inParameter)
{
return _CanExecute == null || _CanExecute(inParameter);
}
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
/// <summary>
/// Run the method bound to the RelayCommand with the parameters
/// passed in.
/// </summary>
/// <param name="inParameter"></param>
public void Execute(object inParameter)
{
_Execute(inParameter);
}
/// <summary>
/// Re-evaluate CanExecute to enable or disable button.
/// </summary>
public void EvaluateCanExecute()
{
CommandManager.InvalidateRequerySuggested();
}
#endregion ICommand Members
}
}
#region License
/*
WPFSharp.Globalizer - A project deisgned to make localization and styling
easier by decoupling both process from the build.
Copyright (c) 2015, Jared Barneck (Rhyous)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Use of the source code or binaries that in any way competes with WPFSharp.Globalizer
or competes with distribution, whether open source or commercial, is
prohibited unless permission is specifically granted under a separate
license by Jared Barneck (Rhyous).
4. Forking for personal or internal, or non-competing commercial use is allowed.
Distributing compiled releases as part of your non-competing project is
allowed.
5. Public copies, or forks, of source is allowed, but from such, public
distribution of compiled releases is forbidden.
6. Source code enhancements or additions are the property of the author until
the source code is contributed to this project. By contributing the source
code to this project, the author immediately grants all rights to the
contributed source code to Jared Barneck (Rhyous).
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

View file

@ -0,0 +1,34 @@
using System.Windows.Controls;
using System.Windows.Data;
namespace WPFSharp.Globalizer.Controls
{
public partial class StyleSelectionComboBox : ComboBox
{
public StyleSelectionComboBox()
{
var itemSourceBinding = new Binding
{
Source = AvailableStyles.Instance,
BindsDirectlyToSource = true,
};
SetBinding(ItemsSourceProperty, itemSourceBinding);
SelectionChanged += StyleSelectionComboBox_SelectionChanged;
var selectedItemBinding = new Binding("SelectedStyle")
{
Source = AvailableStyles.Instance,
Mode = BindingMode.OneWay
};
SetBinding(SelectedItemProperty, selectedItemBinding);
}
void StyleSelectionComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var style = e.AddedItems[0].ToString();
if (!string.IsNullOrWhiteSpace(style))
GlobalizedApplication.Instance.StyleManager.SwitchStyle(style);
}
}
}

View file

@ -0,0 +1,93 @@
// See license at end of the file
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using WPFSharp.Globalizer.Converters;
namespace WPFSharp.Globalizer.Controls
{
public class StyleSelectionMenuItemList : MenuItem
{
public StyleSelectionMenuItemList()
{
ItemsSource = AvailableStyles.Instance;
var checkableMenuItemStyle = new Style { TargetType = typeof(MenuItem) };
var headerBinding = new Binding();
var headerSetter = new Setter(HeaderProperty, headerBinding);
checkableMenuItemStyle.Setters.Add(headerSetter);
var isCheckableSetter = new Setter(IsCheckableProperty, true);
checkableMenuItemStyle.Setters.Add(isCheckableSetter);
ICommand command = new RelayCommand(SelectStyle);
var commandSetter = new Setter(CommandProperty, command);
checkableMenuItemStyle.Setters.Add(commandSetter);
var commandParamBinding = new Binding();
var commandParamSetter = new Setter(CommandParameterProperty, commandParamBinding);
checkableMenuItemStyle.Setters.Add(commandParamSetter);
var isCheckedMultiBinding = new MultiBinding { Converter = new MultiValueStringsMatchConverter(), Mode = BindingMode.OneWay };
isCheckedMultiBinding.Bindings.Add(new Binding { Mode = BindingMode.OneWay });
isCheckedMultiBinding.Bindings.Add(new Binding("SelectedStyle") { Source = AvailableStyles.Instance, Mode = BindingMode.OneWay });
var isCheckedSetter = new Setter(IsCheckedProperty, isCheckedMultiBinding);
checkableMenuItemStyle.Setters.Add(isCheckedSetter);
Resources.Add(typeof(MenuItem), checkableMenuItemStyle);
}
public void SelectStyle(object inStyle)
{
var style = inStyle as string;
if (!string.IsNullOrWhiteSpace(style))
GlobalizedApplication.Instance.StyleManager.SwitchStyle(style);
}
}
}
#region License
/*
WPFSharp.Globalizer - A project deisgned to make localization and styling
easier by decoupling both process from the build.
Copyright (c) 2015, Jared Barneck (Rhyous)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Use of the source code or binaries that in any way competes with WPFSharp.Globalizer
or competes with distribution, whether open source or commercial, is
prohibited unless permission is specifically granted under a separate
license by Jared Barneck (Rhyous).
4. Forking for personal or internal, or non-competing commercial use is allowed.
Distributing compiled releases as part of your non-competing project is
allowed.
5. Public copies, or forks, of source is allowed, but from such, public
distribution of compiled releases is forbidden.
6. Source code enhancements or additions are the property of the author until
the source code is contributed to this project. By contributing the source
code to this project, the author immediately grants all rights to the
contributed source code to Jared Barneck (Rhyous).
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

View file

@ -0,0 +1,81 @@
// See license at the end of the file
using System;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
namespace WPFSharp.Globalizer.Converters
{
class LanguageNameConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var lang = value as string;
if (string.IsNullOrWhiteSpace(lang))
return null;
var ci = new CultureInfo(lang);
var locConverter = new LocalizationConverter();
return locConverter.Convert(lang, typeof(string), ci.DisplayName, CultureInfo.CurrentCulture);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
var lang = value as string;
if (string.IsNullOrWhiteSpace(lang))
return null;
var keyvalue = AvailableLanguages.Instance.CultureInfoMap.FirstOrDefault(x => x.Value == lang);
return keyvalue.Key;
}
#endregion
}
}
#region License
/*
WPFSharp.Globalizer - A project deisgned to make localization and styling
easier by decoupling both process from the build.
Copyright (c) 2015, Jared Barneck (Rhyous)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Use of the source code or binaries that in any way competes with WPFSharp.Globalizer
or competes with distribution, whether open source or commercial, is
prohibited unless permission is specifically granted under a separate
license by Jared Barneck (Rhyous).
4. Forking for personal or internal, or non-competing commercial use is allowed.
Distributing compiled releases as part of your non-competing project is
allowed.
5. Public copies, or forks, of source is allowed, but from such, public
distribution of compiled releases is forbidden.
6. Source code enhancements or additions are the property of the author until
the source code is contributed to this project. By contributing the source
code to this project, the author immediately grants all rights to the
contributed source code to Jared Barneck (Rhyous).
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

View file

@ -0,0 +1,73 @@
// See license at end of the file
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
namespace WPFSharp.Globalizer.Converters
{
class LanguageNameListConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var converter = new LanguageNameConverter();
var list = value as List<string>;
if (list == null)
return null;
return list.Select(lang => converter.Convert(lang, typeof(string), null, culture).ToString()).ToList();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
}
#region License
/*
WPFSharp.Globalizer - A project deisgned to make localization and styling
easier by decoupling both process from the build.
Copyright (c) 2015, Jared Barneck (Rhyous)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Use of the source code or binaries that in any way competes with WPFSharp.Globalizer
or competes with distribution, whether open source or commercial, is
prohibited unless permission is specifically granted under a separate
license by Jared Barneck (Rhyous).
4. Forking for personal or internal, or non-competing commercial use is allowed.
Distributing compiled releases as part of your non-competing project is
allowed.
5. Public copies, or forks, of source is allowed, but from such, public
distribution of compiled releases is forbidden.
6. Source code enhancements or additions are the property of the author until
the source code is contributed to this project. By contributing the source
code to this project, the author immediately grants all rights to the
contributed source code to Jared Barneck (Rhyous).
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

View file

@ -0,0 +1,70 @@
// See license at end of the file
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Markup;
namespace WPFSharp.Globalizer.Converters
{
public class LocalizationConverter : MarkupExtension, IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return GlobalizedApplication.Instance.TryFindResource(value) ?? parameter;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return _LocalizationConverter ?? (_LocalizationConverter = new LocalizationConverter());
} private static LocalizationConverter _LocalizationConverter;
}
}
#region License
/*
WPFSharp.Globalizer - A project deisgned to make localization and styling
easier by decoupling both process from the build.
Copyright (c) 2015, Jared Barneck (Rhyous)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Use of the source code or binaries that in any way competes with WPFSharp.Globalizer
or competes with distribution, whether open source or commercial, is
prohibited unless permission is specifically granted under a separate
license by Jared Barneck (Rhyous).
4. Forking for personal or internal, or non-competing commercial use is allowed.
Distributing compiled releases as part of your non-competing project is
allowed.
5. Public copies, or forks, of source is allowed, but from such, public
distribution of compiled releases is forbidden.
6. Source code enhancements or additions are the property of the author until
the source code is contributed to this project. By contributing the source
code to this project, the author immediately grants all rights to the
contributed source code to Jared Barneck (Rhyous).
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

View file

@ -0,0 +1,74 @@
// See license at end of file
using System;
using System.Globalization;
using System.Windows.Data;
namespace WPFSharp.Globalizer.Converters
{
class MultiValueStringsMatchConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values == null || values.Length == 1)
return false;
string first = null;
if (values[0] != null)
first = values[0].ToString();
foreach (string value in values)
{
if (value != first)
return false;
}
return true;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
#region License
/*
WPFSharp.Globalizer - A project deisgned to make localization and styling
easier by decoupling both process from the build.
Copyright (c) 2015, Jared Barneck (Rhyous)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Use of the source code or binaries that in any way competes with WPFSharp.Globalizer
or competes with distribution, whether open source or commercial, is
prohibited unless permission is specifically granted under a separate
license by Jared Barneck (Rhyous).
4. Forking for personal or internal, or non-competing commercial use is allowed.
Distributing compiled releases as part of your non-competing project is
allowed.
5. Public copies, or forks, of source is allowed, but from such, public
distribution of compiled releases is forbidden.
6. Source code enhancements or additions are the property of the author until
the source code is contributed to this project. By contributing the source
code to this project, the author immediately grants all rights to the
contributed source code to Jared Barneck (Rhyous).
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

View file

@ -0,0 +1,69 @@
// See license at bottom of file
using System;
using System.Windows;
namespace WPFSharp.Globalizer
{
public abstract class EnhancedResourceDictionary : ResourceDictionary
{
private static int _Id;
public EnhancedResourceDictionary()
{
Name = string.Empty;
Id = _Id++;
}
#region Properties
public virtual int Id { get; set; }
public virtual string Name { get; set; }
new virtual public string Source { get; set; }
#endregion
}
}
#region License
/*
WPFSharp.Globalizer - A project deisgned to make localization and styling
easier by decoupling both process from the build.
Copyright (c) 2015, Jared Barneck (Rhyous)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Use of the source code or binaries that in any way competes with WPFSharp.Globalizer
or competes with distribution, whether open source or commercial, is
prohibited unless permission is specifically granted under a separate
license by Jared Barneck (Rhyous).
4. Forking for personal or internal, or non-competing commercial use is allowed.
Distributing compiled releases as part of your non-competing project is
allowed.
5. Public copies, or forks, of source is allowed, but from such, public
distribution of compiled releases is forbidden.
6. Source code enhancements or additions are the property of the author until
the source code is contributed to this project. By contributing the source
code to this project, the author immediately grants all rights to the
contributed source code to Jared Barneck (Rhyous).
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

View file

@ -0,0 +1,26 @@
using System;
using System.Runtime.Serialization;
using System.Security;
namespace WPFSharp.Globalizer.Exceptions
{
[Serializable]
public class StyleNotFoundException : ArgumentException, ISerializable
{
public StyleNotFoundException() : base() { }
public StyleNotFoundException(string message) : base(message) { }
public StyleNotFoundException(string message, Exception innerException) : base(message, innerException) { }
public StyleNotFoundException(string message, string invalidStyleName, Exception innerException) : base(message, innerException)
{
InvalidStyleName = invalidStyleName;
}
[SecuritySafeCritical]
protected StyleNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { }
public virtual string InvalidStyleName { get; private set; } = string.Empty;
}
}

View file

@ -0,0 +1,51 @@
// See license at end of the file
namespace WPFSharp.Globalizer
{
public class FallbackResourceDictionary : EnhancedResourceDictionary
{
}
}
#region License
/*
WPFSharp.Globalizer - A project deisgned to make localization and styling
easier by decoupling both process from the build.
Copyright (c) 2015, Jared Barneck (Rhyous)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Use of the source code or binaries that in any way competes with WPFSharp.Globalizer
or competes with distribution, whether open source or commercial, is
prohibited unless permission is specifically granted under a separate
license by Jared Barneck (Rhyous).
4. Forking for personal or internal, or non-competing commercial use is allowed.
Distributing compiled releases as part of your non-competing project is
allowed.
5. Public copies, or forks, of source is allowed, but from such, public
distribution of compiled releases is forbidden.
6. Source code enhancements or additions are the property of the author until
the source code is contributed to this project. By contributing the source
code to this project, the author immediately grants all rights to the
contributed source code to Jared Barneck (Rhyous).
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

View file

@ -0,0 +1,224 @@
// See license at bottom of file
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Markup;
namespace WPFSharp.Globalizer
{
public sealed class GlobalizationManager : ResourceDictionaryManagerBase
{
#region Members
internal const string FallBackLanguage = "en-US";
#endregion
#region Contructor
public GlobalizationManager(Collection<ResourceDictionary> inMergedDictionaries)
: base(inMergedDictionaries)
{
SubDirectory = "Globalization";
}
#endregion
#region Functions
/// <summary>
/// Dynamically load a Localization ResourceDictionary from a file
/// </summary>
public void SwitchLanguage(string inFiveCharLang, bool inForceSwitch = false)
{
if (CultureInfo.CurrentCulture.Name.Equals(inFiveCharLang) && !inForceSwitch)
return;
if (!AvailableLanguages.Instance.Contains(inFiveCharLang))
{
throw new CultureNotFoundException(string.Format("The language {0} is not available.", inFiveCharLang));
}
// Set the new language
var ci = new CultureInfo(inFiveCharLang);
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
FileNames = new List<string>();
string[] xamlFiles;
// check if the switch to language matches the fallback language
if (!inFiveCharLang.Equals(FallBackLanguage))
{
// switch to language is different, must load the fallback language first
xamlFiles = Directory.GetFiles(Path.Combine(DefaultPath, FallBackLanguage), $"{FallBackLanguage}.xaml");
if (xamlFiles.Length > 0)
FileNames.AddRange(xamlFiles);
}
// load the switch to language
xamlFiles = Directory.GetFiles(Path.Combine(DefaultPath, inFiveCharLang), $"{inFiveCharLang}.xaml");
if (xamlFiles.Length > 0)
FileNames.AddRange(xamlFiles);
// Remove previous ResourceDictionaries
RemoveResourceDictionaries();
// Add new Resource Dictionaries
LoadDictionariesFromFiles(FileNames);
var args = new ResourceDictionaryChangedEventArgs { ResourceDictionaryPaths = FileNames, ResourceDictionaryNames = FileNames.Select(f => Path.GetFileNameWithoutExtension(f)).ToList() };
NotifyResourceDictionaryChanged(args);
}
private void RemoveResourceDictionaries()
{
var dictionariesToRemove = new List<ResourceDictionary>();
foreach (ResourceDictionary rd in GlobalizedApplication.Instance.Resources.MergedDictionaries)
{
if (rd is GlobalizationResourceDictionary)
{
dictionariesToRemove.Add(rd);
}
}
foreach (EnhancedResourceDictionary erd in dictionariesToRemove)
{
GlobalizedApplication.Instance.Resources.MergedDictionaries.Remove(erd);
// Also remove any associated LinkedStyles
var globalizationResourceDictionary = erd as GlobalizationResourceDictionary;
if (globalizationResourceDictionary != null && globalizationResourceDictionary.LinkedStyle != null)
Remove((erd as GlobalizationResourceDictionary).LinkedStyle);
}
}
public override EnhancedResourceDictionary LoadFromFile(string inFile)
{
return LoadFromFile(inFile, true);
}
public EnhancedResourceDictionary LoadFromFile(string inFile, bool inRequireGlobalizationType = true)
{
string file = inFile;
// Determine if the path is absolute or relative
if (!Path.IsPathRooted(inFile))
{
file = Path.Combine(DefaultPath, CultureInfo.CurrentCulture.Name, inFile);
}
if (!File.Exists(file))
return null;
try
{
using (var fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
// Read in an EnhancedResourceDictionary File or preferably an GlobalizationResourceDictionary file
var rd = XamlReader.Load(fs) as EnhancedResourceDictionary;
if (rd == null)
return null;
if (inRequireGlobalizationType)
{
if (rd is GlobalizationResourceDictionary)
return rd;
return null;
}
return rd;
}
}
catch
{
return null;
}
}
public override void LoadDictionariesFromFiles(List<string> inList)
{
foreach (var filePath in inList)
{
// Only Globalization resource dictionaries should be added
// Ignore other types
var rd = LoadFromFile(filePath) as GlobalizationResourceDictionary;
if (rd == null)
continue;
MergedDictionaries.Add(rd);
if (rd.LinkedStyle == null)
continue;
var styleFile = rd.LinkedStyle + ".xaml";
if (rd.Source != null)
{
var path = Path.Combine(Path.GetDirectoryName(rd.Source), styleFile);
// Todo: Check for file and if not there, look in the Styles dir
var lrd = LoadFromFile(path, false);
if (lrd != null)
{
MergedDictionaries.Add(lrd);
}
return;
}
var srd = LoadFromFile(styleFile, false);
if (srd != null)
{
MergedDictionaries.Add(srd);
}
}
}
#endregion
}
}
#region License
/*
WPFSharp.Globalizer - A project deisgned to make localization and styling
easier by decoupling both process from the build.
Copyright (c) 2015, Jared Barneck (Rhyous)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Use of the source code or binaries that in any way competes with WPFSharp.Globalizer
or competes with distribution, whether open source or commercial, is
prohibited unless permission is specifically granted under a separate
license by Jared Barneck (Rhyous).
4. Forking for personal or internal, or non-competing commercial use is allowed.
Distributing compiled releases as part of your non-competing project is
allowed.
5. Public copies, or forks, of source is allowed, but from such, public
distribution of compiled releases is forbidden.
6. Source code enhancements or additions are the property of the author until
the source code is contributed to this project. By contributing the source
code to this project, the author immediately grants all rights to the
contributed source code to Jared Barneck (Rhyous).
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

View file

@ -0,0 +1,57 @@
// See license at end of the file
namespace WPFSharp.Globalizer
{
public class GlobalizationResourceDictionary : EnhancedResourceDictionary
{
/// <summary>
/// A Style to load. This allows changing the language to also
/// change the Style. This way colors and FlowDirection can be
/// changed the same time as a language change.
/// </summary>
public string LinkedStyle { get; set; }
}
}
#region License
/*
WPFSharp.Globalizer - A project deisgned to make localization and styling
easier by decoupling both process from the build.
Copyright (c) 2015, Jared Barneck (Rhyous)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Use of the source code or binaries that in any way competes with WPFSharp.Globalizer
or competes with distribution, whether open source or commercial, is
prohibited unless permission is specifically granted under a separate
license by Jared Barneck (Rhyous).
4. Forking for personal or internal, or non-competing commercial use is allowed.
Distributing compiled releases as part of your non-competing project is
allowed.
5. Public copies, or forks, of source is allowed, but from such, public
distribution of compiled releases is forbidden.
6. Source code enhancements or additions are the property of the author until
the source code is contributed to this project. By contributing the source
code to this project, the author immediately grants all rights to the
contributed source code to Jared Barneck (Rhyous).
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

View file

@ -0,0 +1,160 @@
// See license at bottom of file
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Threading;
using System.Windows;
namespace WPFSharp.Globalizer
{
public abstract class GlobalizedApplication : Application
{
public static GlobalizedApplication Instance;
public GlobalizationManager GlobalizationManager;
public StyleManager StyleManager;
public GlobalizedApplication()
{
// Make App a singleton
Instance = this;
}
protected override void OnStartup(StartupEventArgs e)
{
Init();
}
#region Properties
public virtual String Directory { get; } = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
public virtual EnhancedResourceDictionary FallbackResourceDictionary { get; private set; }
#endregion
#region Methods
public virtual void Init()
{
GlobalizationManager = new GlobalizationManager(Resources.MergedDictionaries);
StyleManager = new StyleManager(Resources.MergedDictionaries);
// Get current 5 character language and load the appropriate Globalization file
CreateAvailableLanguages();
try
{
GlobalizationManager.SwitchLanguage(Thread.CurrentThread.CurrentCulture.Name, true);
}
catch (Exception ex)
{
// Try the fallback
GlobalizationManager.SwitchLanguage(GlobalizationManager.FallBackLanguage, true);
Debug.WriteLine($"{nameof(GlobalizationManager.SwitchLanguage)} error.\r\n{ex.Message}");
}
// Load the default style
CreateAvailableStyles();
try
{
StyleManager.SwitchStyle(StyleManager.FallBackStyle, true);
}
catch (Exception ex)
{
Debug.WriteLine($"{nameof(StyleManager.SwitchStyle)} error.\r\n{ex.Message}");
}
// Create the FallbackResourceDictionary
FallbackResourceDictionary = new FallbackResourceDictionary() { Name = "Fallback" };
Resources.MergedDictionaries.Add(FallbackResourceDictionary);
}
public virtual object GetResource(string inKey)
{
if (string.IsNullOrWhiteSpace(inKey))
throw new ArgumentNullException(inKey, "parameter cannot be null.");
return (Instance.Resources.Contains(inKey)) ? Instance.Resources[inKey] : null;
}
public virtual string GetResourceString(string inKey)
{
if (string.IsNullOrWhiteSpace(inKey))
throw new ArgumentNullException(inKey, "parameter cannot be null.");
if ((Instance.Resources.Contains(inKey) && Instance.Resources[inKey] is string))
{
var resourceString = Instance.Resources[inKey].ToString();
resourceString = resourceString.Replace("\\r", "\r");
resourceString = resourceString.Replace("\\n", "\n");
return resourceString;
}
return null;
}
/// <summary>
/// // Create and populate the SupportedLanguages singleton
/// </summary>
protected virtual void CreateAvailableLanguages()
{
AvailableLanguages.CreateInstance();
AvailableLanguages.Instance.AddListFromSubDirectories(GlobalizationManager.DefaultPath);
}
/// <summary>
/// // Create and populate the SupportedLanguages singleton
/// </summary>
protected virtual void CreateAvailableStyles()
{
AvailableStyles.CreateInstance();
AvailableStyles.Instance.AddListFromFiles(StyleManager.DefaultPath);
}
#endregion
}
}
#region License
/*
WPFSharp.Globalizer - A project deisgned to make localization and styling
easier by decoupling both process from the build.
Copyright (c) 2015, Jared Barneck (Rhyous)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Use of the source code or binaries that in any way competes with WPFSharp.Globalizer
or competes with distribution, whether open source or commercial, is
prohibited unless permission is specifically granted under a separate
license by Jared Barneck (Rhyous).
4. Forking for personal or internal, or non-competing commercial use is allowed.
Distributing compiled releases as part of your non-competing project is
allowed.
5. Public copies, or forks, of source is allowed, but from such, public
distribution of compiled releases is forbidden.
6. Source code enhancements or additions are the property of the author until
the source code is contributed to this project. By contributing the source
code to this project, the author immediately grants all rights to the
contributed source code to Jared Barneck (Rhyous).
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

View file

@ -0,0 +1,135 @@
// See license at the bottom of the file
using System;
using System.Windows;
using System.Windows.Markup;
namespace WPFSharp.Globalizer
{
//[TypeConverter(typeof(GlobalizedDynamicResourceExtensionConverter))]
[MarkupExtensionReturnType(typeof(object))]
public class GlobalizedResourceExtension : DynamicResourceExtension
{
#region Constructors
/// <summary>
/// Default Contructor
/// </summary>
public GlobalizedResourceExtension()
{
FallbackValue = DependencyProperty.UnsetValue;
}
/// <summary>
/// Constructor that takes the resource key that this is a static reference to.
/// </summary>
public GlobalizedResourceExtension(object inResourceKey)
{
ResourceKey = inResourceKey;
FallbackValue = DependencyProperty.UnsetValue;
}
/// <summary>
/// Constructor that takes the resource key that this is a static reference to.
/// </summary>
public GlobalizedResourceExtension(object inResourceKey, object inFallBackValue)
{
ResourceKey = inResourceKey;
FallbackValue = inFallBackValue ?? DependencyProperty.UnsetValue;
}
#endregion
#region Properties
/// <summary>
/// A value to use if the DynamicResource is not found.
/// </summary>
public Object FallbackValue { get; set; }
/// <summary>
/// A name used to group ResourceDictionaries
/// </summary>
public string GroupName { get; set; }
/// <summary>
/// A specified Style resource dictionary.
/// If a resource dictionary is loaded, and this value is set, then the specified
/// style resource dictionary is loaded.
/// </summary>
public string LinkedStyle { get; set; }
#endregion
/// <summary>
/// Return an object that should be set on the targetObject's targetProperty
/// for this markup extension. For DynamicResourceExtension, this is the object found in
/// a resource dictionary in the current parent chain that is keyed by ResourceKey
/// </summary>
/// <returns>
/// The object to set on this property.
/// </returns>
public override object ProvideValue(IServiceProvider inServiceProvider)
{
if (ResourceKey == null || string.IsNullOrWhiteSpace(ResourceKey.ToString()))
throw new InvalidOperationException("ResourceKey cannot be null or empty.");
if (GlobalizedApplication.Instance == null)
return FallbackValue;
// Use FallbackValue if it exists by adding it to the FallbackResourceDictionary.
if (FallbackValue != null)
{
// Remove it in case it is already there
GlobalizedApplication.Instance.FallbackResourceDictionary.Remove(ResourceKey);
// Add it
GlobalizedApplication.Instance.FallbackResourceDictionary.Add(ResourceKey, FallbackValue);
}
return base.ProvideValue(inServiceProvider);
}
}
}
#region License
/*
WPFSharp.Globalizer - A project deisgned to make localization and styling
easier by decoupling both process from the build.
Copyright (c) 2015, Jared Barneck (Rhyous)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Use of the source code or binaries that in any way competes with WPFSharp.Globalizer
or competes with distribution, whether open source or commercial, is
prohibited unless permission is specifically granted under a separate
license by Jared Barneck (Rhyous).
4. Forking for personal or internal, or non-competing commercial use is allowed.
Distributing compiled releases as part of your non-competing project is
allowed.
5. Public copies, or forks, of source is allowed, but from such, public
distribution of compiled releases is forbidden.
6. Source code enhancements or additions are the property of the author until
the source code is contributed to this project. By contributing the source
code to this project, the author immediately grants all rights to the
contributed source code to Jared Barneck (Rhyous).
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

View file

@ -0,0 +1,98 @@
// See license at end of the file
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
namespace WPFSharp.Globalizer
{
public interface IManageResourceDictionaries
{
/// <summary>
/// An event that is fired when a ResourceDictionary is changed.
/// </summary>
event ResourceDictionaryChangedEventHandler ResourceDictionaryChangedEvent;
/// <summary>
/// The list of resource dictionary .xaml files
/// </summary>
Collection<ResourceDictionary> MergedDictionaries { get; set; }
/// <summary>
/// The list of resource dictionary .xaml files
/// </summary>
List<string> FileNames { get; set; }
/// <summary>
/// Dynamically load a ResourceDictionary from a file
/// </summary>
/// <param name="inFile">The file to read for loading the ResourceDictionary.</param>
EnhancedResourceDictionary LoadFromFile(string inFile);
/// <summary>
/// Dynamically load a ResourceDictionary from a list of file names
/// </summary>
void LoadDictionariesFromFiles(List<string> inList);
/// <summary>
/// Removes a ResourceDictionary.
/// </summary>
/// <param name="inResourceDictionaryName">A string representing the ResourceDictionary name.</param>
void Remove(string inResourceDictionaryName);
/// <summary>
/// Removes a ResourceDictionary.
/// </summary>
/// <param name="inResourceDictionaryName">A string representing the ResourceDictionary name.</param>
void RemoveAll();
/// <summary>
/// A method to fire the ResourceDictionaryChangedEvent
/// </summary>
void NotifyResourceDictionaryChanged(ResourceDictionaryChangedEventArgs inEventArgs);
}
}
#region License
/*
WPFSharp.Globalizer - A project deisgned to make localization and styling
easier by decoupling both process from the build.
Copyright (c) 2015, Jared Barneck (Rhyous)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Use of the source code or binaries that in any way competes with WPFSharp.Globalizer
or competes with distribution, whether open source or commercial, is
prohibited unless permission is specifically granted under a separate
license by Jared Barneck (Rhyous).
4. Forking for personal or internal, or non-competing commercial use is allowed.
Distributing compiled releases as part of your non-competing project is
allowed.
5. Public copies, or forks, of source is allowed, but from such, public
distribution of compiled releases is forbidden.
6. Source code enhancements or additions are the property of the author until
the source code is contributed to this project. By contributing the source
code to this project, the author immediately grants all rights to the
contributed source code to Jared Barneck (Rhyous).
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

View file

@ -0,0 +1,72 @@
// See license at end of the file
using System.Windows.Data;
using WPFSharp.Globalizer.Converters;
namespace WPFSharp.Globalizer
{
public class LocalizationBinding : Binding
{
public LocalizationBinding()
{
}
public LocalizationBinding(string path)
: base(path)
{
Converter = new LocalizationConverter();
}
new public object FallbackValue
{
get { return base.FallbackValue; }
set
{
base.FallbackValue = value;
ConverterParameter = value;
}
}
}
}
#region License
/*
WPFSharp.Globalizer - A project deisgned to make localization and styling
easier by decoupling both process from the build.
Copyright (c) 2015, Jared Barneck (Rhyous)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Use of the source code or binaries that in any way competes with WPFSharp.Globalizer
or competes with distribution, whether open source or commercial, is
prohibited unless permission is specifically granted under a separate
license by Jared Barneck (Rhyous).
4. Forking for personal or internal, or non-competing commercial use is allowed.
Distributing compiled releases as part of your non-competing project is
allowed.
5. Public copies, or forks, of source is allowed, but from such, public
distribution of compiled releases is forbidden.
6. Source code enhancements or additions are the property of the author until
the source code is contributed to this project. By contributing the source
code to this project, the author immediately grants all rights to the
contributed source code to Jared Barneck (Rhyous).
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

View file

@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("WPFSharp.Globalizer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Rhyous")]
[assembly: AssemblyProduct("WPFSharp.Globalizer")]
[assembly: AssemblyCopyright("Copyright © Rhyous 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("26260edf-a6b3-4c8a-bb0c-712ad759abe3")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.1")]
[assembly: AssemblyFileVersion("1.0.0.1")]

View file

@ -0,0 +1,68 @@
// See license at end of the file
using System;
using System.Collections.Generic;
namespace WPFSharp.Globalizer
{
public delegate void ResourceDictionaryChangedEventHandler(object source, ResourceDictionaryChangedEventArgs e);
public class ResourceDictionaryChangedEventArgs : EventArgs
{
public List<string> ResourceDictionaryNames
{
get { return _ResourceDictionaryNames ?? (_ResourceDictionaryNames = new List<string>()); }
set { _ResourceDictionaryNames = value; }
} private List<string> _ResourceDictionaryNames;
public List<string> ResourceDictionaryPaths
{
get { return _ResourceDictionaryPaths ?? (_ResourceDictionaryPaths = new List<string>()); }
set { _ResourceDictionaryPaths = value; }
} private List<string> _ResourceDictionaryPaths;
}
}
#region License
/*
WPFSharp.Globalizer - A project deisgned to make localization and styling
easier by decoupling both process from the build.
Copyright (c) 2015, Jared Barneck (Rhyous)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Use of the source code or binaries that in any way competes with WPFSharp.Globalizer
or competes with distribution, whether open source or commercial, is
prohibited unless permission is specifically granted under a separate
license by Jared Barneck (Rhyous).
4. Forking for personal or internal, or non-competing commercial use is allowed.
Distributing compiled releases as part of your non-competing project is
allowed.
5. Public copies, or forks, of source is allowed, but from such, public
distribution of compiled releases is forbidden.
6. Source code enhancements or additions are the property of the author until
the source code is contributed to this project. By contributing the source
code to this project, the author immediately grants all rights to the
contributed source code to Jared Barneck (Rhyous).
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

View file

@ -0,0 +1,130 @@
// See license at end of the file
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
namespace WPFSharp.Globalizer
{
public abstract class ResourceDictionaryManagerBase : IManageResourceDictionaries
{
#region IManageResourceDictionaries Events
public virtual event ResourceDictionaryChangedEventHandler ResourceDictionaryChangedEvent;
#endregion
#region Contructor
public ResourceDictionaryManagerBase(Collection<ResourceDictionary> inMergedDictionaries)
{
MergedDictionaries = inMergedDictionaries;
}
#endregion
#region Properties
public virtual string SubDirectory { get; set; }
public virtual string DefaultPath
{
get { return _defaultPath ?? (_defaultPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), SubDirectory)); }
}
private String _defaultPath;
public Collection<ResourceDictionary> MergedDictionaries { get; set; }
public virtual List<string> FileNames
{
get { return _FileNames ?? (_FileNames = new List<string>()); }
set { _FileNames = value; }
} private List<string> _FileNames;
#endregion
#region Methods
public void Remove(string inResourceDictionaryName)
{
EnhancedResourceDictionary erdToRemove = null;
foreach (EnhancedResourceDictionary erd in MergedDictionaries.OfType<EnhancedResourceDictionary>())
{
if (erd.Name == inResourceDictionaryName)
erdToRemove = erd;
}
if (erdToRemove != null)
MergedDictionaries.Remove(erdToRemove);
}
public void RemoveAll()
{
MergedDictionaries.Clear();
}
public virtual void NotifyResourceDictionaryChanged(ResourceDictionaryChangedEventArgs inEventArgs = null)
{
ResourceDictionaryChangedEvent?.Invoke(this, inEventArgs ?? new ResourceDictionaryChangedEventArgs());
}
public abstract EnhancedResourceDictionary LoadFromFile(string inFile);
public virtual void LoadDictionariesFromFiles(List<string> inList)
{
foreach (var filePath in inList)
{
MergedDictionaries.Add(LoadFromFile(filePath) as EnhancedResourceDictionary);
}
}
#endregion
}
}
#region License
/*
WPFSharp.Globalizer - A project deisgned to make localization and styling
easier by decoupling both process from the build.
Copyright (c) 2015, Jared Barneck (Rhyous)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Use of the source code or binaries that in any way competes with WPFSharp.Globalizer
or competes with distribution, whether open source or commercial, is
prohibited unless permission is specifically granted under a separate
license by Jared Barneck (Rhyous).
4. Forking for personal or internal, or non-competing commercial use is allowed.
Distributing compiled releases as part of your non-competing project is
allowed.
5. Public copies, or forks, of source is allowed, but from such, public
distribution of compiled releases is forbidden.
6. Source code enhancements or additions are the property of the author until
the source code is contributed to this project. By contributing the source
code to this project, the author immediately grants all rights to the
contributed source code to Jared Barneck (Rhyous).
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

View file

@ -0,0 +1,172 @@
// See license at bottom of file
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Markup;
using WPFSharp.Globalizer.Exceptions;
namespace WPFSharp.Globalizer
{
public sealed class StyleManager : ResourceDictionaryManagerBase
{
#region Members
internal static string FallBackStyle = "Default";
#endregion
#region Contructor
public StyleManager(Collection<ResourceDictionary> inMergedDictionaries)
: base(inMergedDictionaries)
{
SubDirectory = "Styles";
}
#endregion
#region Functions
/// <summary>
/// Dynamically load a Localization ResourceDictionary from a file
/// </summary>
public void SwitchStyle(string inStyleName, bool inForceSwitch = false)
{
if (AvailableStyles.Instance.SelectedStyle.Equals(inStyleName) && !inForceSwitch)
return;
if (!AvailableStyles.Instance.Contains(inStyleName))
{
throw new StyleNotFoundException(String.Format("The style {0} is not available.", inStyleName));
}
// Set the new style
AvailableStyles.Instance.SelectedStyle = inStyleName;
FileNames = new List<string>();
string[] xamlFiles;
// check if the switch to style matches the fallback style
if (!inStyleName.Equals(FallBackStyle))
{
// switch to style is different, must load the fallback style first
xamlFiles = Directory.GetFiles(DefaultPath, $"{FallBackStyle}.xaml");
if (xamlFiles.Length > 0)
FileNames.AddRange(xamlFiles);
}
// load the switch to style
xamlFiles = Directory.GetFiles(DefaultPath, $"{inStyleName}.xaml");
if (xamlFiles.Length > 0)
FileNames.AddRange(xamlFiles);
// Remove previous ResourceDictionaries
RemoveResourceDictionaries();
// Add new Resource Dictionaries
LoadDictionariesFromFiles(FileNames);
var args = new ResourceDictionaryChangedEventArgs { ResourceDictionaryPaths = FileNames, ResourceDictionaryNames = FileNames.Select(f => Path.GetFileNameWithoutExtension(f)).ToList() };
NotifyResourceDictionaryChanged(args);
}
private void RemoveResourceDictionaries()
{
var dictionariesToRemove = new List<ResourceDictionary>();
foreach (ResourceDictionary rd in GlobalizedApplication.Instance.Resources.MergedDictionaries)
{
// Make sure to only remove Styles, but don't remove styles owned by the language
if (rd is StyleResourceDictionary && !(rd as StyleResourceDictionary).IsLinkedToLanguage)
dictionariesToRemove.Add(rd);
}
foreach (var rd in dictionariesToRemove)
{
GlobalizedApplication.Instance.Resources.MergedDictionaries.Remove(rd);
}
}
public override EnhancedResourceDictionary LoadFromFile(string inFile)
{
string file = inFile;
// Determine if the path is absolute or relative
if (!Path.IsPathRooted(inFile))
{
file = Path.Combine(DefaultPath, inFile);
}
if (!File.Exists(file))
return null;
using (var fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
// Read in ResourceDictionary File or preferably an EnhancedResourceDictionary file
var rd = XamlReader.Load(fs) as StyleResourceDictionary;
if (rd == null)
return null;
//rd.Source = inFile;
return rd;
}
}
public override void LoadDictionariesFromFiles(List<string> inList)
{
foreach (var filePath in inList)
{
// Only Globalization resource dictionaries should be added
// Ignore other types
var rd = LoadFromFile(filePath) as StyleResourceDictionary;
if (rd == null)
continue;
MergedDictionaries.Add(rd);
}
}
#endregion
}
}
#region License
/*
WPFSharp.Globalizer - A project deisgned to make localization and styling
easier by decoupling both process from the build.
Copyright (c) 2015, Jared Barneck (Rhyous)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Use of the source code or binaries that in any way competes with WPFSharp.Globalizer
or competes with distribution, whether open source or commercial, is
prohibited unless permission is specifically granted under a separate
license by Jared Barneck (Rhyous).
4. Forking for personal or internal, or non-competing commercial use is allowed.
Distributing compiled releases as part of your non-competing project is
allowed.
5. Public copies, or forks, of source is allowed, but from such, public
distribution of compiled releases is forbidden.
6. Source code enhancements or additions are the property of the author until
the source code is contributed to this project. By contributing the source
code to this project, the author immediately grants all rights to the
contributed source code to Jared Barneck (Rhyous).
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

View file

@ -0,0 +1,52 @@
// See license at end of the file
namespace WPFSharp.Globalizer
{
public class StyleResourceDictionary : EnhancedResourceDictionary
{
public bool IsLinkedToLanguage;
}
}
#region License
/*
WPFSharp.Globalizer - A project deisgned to make localization and styling
easier by decoupling both process from the build.
Copyright (c) 2015, Jared Barneck (Rhyous)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Use of the source code or binaries that in any way competes with WPFSharp.Globalizer
or competes with distribution, whether open source or commercial, is
prohibited unless permission is specifically granted under a separate
license by Jared Barneck (Rhyous).
4. Forking for personal or internal, or non-competing commercial use is allowed.
Distributing compiled releases as part of your non-competing project is
allowed.
5. Public copies, or forks, of source is allowed, but from such, public
distribution of compiled releases is forbidden.
6. Source code enhancements or additions are the property of the author until
the source code is contributed to this project. By contributing the source
code to this project, the author immediately grants all rights to the
contributed source code to Jared Barneck (Rhyous).
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

Binary file not shown.

View file

@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Label="Globals">
<SccProjectName>%24/Development/ServerManagers/Main/WPFSharp.Globalizer</SccProjectName>
<SccProvider>{4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}</SccProvider>
<SccAuxPath>https://dev.azure.com/bretthewitson</SccAuxPath>
<SccLocalPath>.</SccLocalPath>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net462</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>WPFSharp.Globalizer.Key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="PresentationFramework.Aero" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
</ItemGroup>
</Project>