HaemmerElectronics.SeppPenner.Language
1.0.0.10
Prefix Reserved
See the version list below for details.
dotnet add package HaemmerElectronics.SeppPenner.Language --version 1.0.0.10
NuGet\Install-Package HaemmerElectronics.SeppPenner.Language -Version 1.0.0.10
<PackageReference Include="HaemmerElectronics.SeppPenner.Language" Version="1.0.0.10" />
paket add HaemmerElectronics.SeppPenner.Language --version 1.0.0.10
#r "nuget: HaemmerElectronics.SeppPenner.Language, 1.0.0.10"
// Install HaemmerElectronics.SeppPenner.Language as a Cake Addin #addin nuget:?package=HaemmerElectronics.SeppPenner.Language&version=1.0.0.10 // Install HaemmerElectronics.SeppPenner.Language as a Cake Tool #tool nuget:?package=HaemmerElectronics.SeppPenner.Language&version=1.0.0.10
CSharpLanguageManager
CSharpLanguageManager is an assembly/ library to build multilingual programms in .Net. The assembly was written and tested in .Net 4.7.
Basic usage:
If you just have one language loaded, you don't need to set the current language as the language manager uses the only language as default.
public void Test()
{
ILanguageManager _lm = new LanguageManager();
var test = _lm.GetCurrentLanguage().GetWord("YourKey");
}
If you have more than one language loaded, you need to set the current (wanted) language. The language identifiers are taken from https://msdn.microsoft.com/de-de/library/ee825488(v=cs.20).aspx.
public void Test()
{
ILanguageManager _lm = new LanguageManager();
_lm.SetCurrentLanguage("de-DE"); //Version 1.0.0.0 to Version 1.0.0.3
_lm.SetCurrentLanguageFromName("German"); //Version 1.0.0.4 and above
var test = _lm.GetCurrentLanguage().GetWord("YourKey");
}
Subscription to OnLanguageChanged Version 1.0.0.4 and above:
You can "subscribe" to the EventHandler OnLanguageChanged to update your GUI whenever the language is changed. This can be done like the following: (For more information see the example project)
namespace TestLanguage
{
public partial class Main : Form
{
private readonly ILanguageManager _lm = new LanguageManager();
private ILanguage _lang;
public Main()
{
InitializeComponent();
InitializeLanguageManager();
LoadLanguagesToCombo();
}
private void InitializeLanguageManager()
{
_lm.SetCurrentLanguage("de-DE");
_lm.OnLanguageChanged += OnLanguageChanged;
}
private void LoadLanguagesToCombo()
{
foreach (var lang in _lm.GetLanguages())
comboBoxLanguage.Items.Add(lang.Name);
comboBoxLanguage.SelectedIndex = 0;
}
private void comboBoxLanguage_SelectedIndexChanged(object sender, EventArgs e)
{
_lm.SetCurrentLanguageFromName(comboBoxLanguage.SelectedItem.ToString());
}
private void OnLanguageChanged(object sender, EventArgs eventArgs)
{
_lang = _lm.GetCurrentLanguage();
labelSelectLanguage.Text = _lang.GetWord("SelectLanguage");
}
}
}
where the basic change is that the _lm.SetCurrentLanguage() handling was simplified by setting it via the language name, too:
_lm.SetCurrentLanguageFromName(comboBoxLanguage.SelectedItem.ToString());
Subscription to OnLanguageChanged Version 1.0.0.0 to 1.0.0.3:
You can "subscribe" to the EventHandler OnLanguageChanged to update your GUI whenever the language is changed. This can be done like the following: (For more information see the example project)
using System;
using System.Windows.Forms;
using Languages.Implementation;
using Languages.Interfaces;
namespace TestLanguage
{
public partial class Main : Form
{
private readonly ILanguageManager _lm = new LanguageManager();
private ILanguage _lang;
public Main()
{
InitializeComponent();
InitializeLanguageManager();
LoadLanguagesToCombo();
}
private void InitializeLanguageManager()
{
_lm.SetCurrentLanguage("de-DE");
_lm.OnLanguageChanged += OnLanguageChanged;
}
private void LoadLanguagesToCombo()
{
foreach (var lang in _lm.GetLanguages())
comboBoxLanguage.Items.Add(lang.Name);
comboBoxLanguage.SelectedIndex = 0;
}
private void comboBoxLanguage_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxLanguage.SelectedItem.ToString())
{
case "German":
_lm.SetCurrentLanguage("de-DE");
break;
case "English (US)":
_lm.SetCurrentLanguage("en-US");
break;
}
}
private void OnLanguageChanged(object sender, EventArgs eventArgs)
{
_lang = _lm.GetCurrentLanguage();
labelSelectLanguage.Text = _lang.GetWord("SelectLanguage");
}
}
}
How do the language files need to look like:
The file's naming is not important but should be something like "de-DE.xml". All language files need to be included into the "languages" folder in your application folder.
<?xml version="1.0" encoding="UTF-8" ?>
<Language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Identifier>de-DE</Identifier>
<Name>German<Name>
<Words>
<Word>
<Key>YourKey</Key>
<Value>TestString</Value>
</Word>
</Words>
</Language>
An example project can be found here. The project can be found on nuget.
Change history
- Version 1.0.0.10 (2018-03-12) : Fixed a bug in the package with wrong .Net frameworks.
- Version 1.0.0.9 (2018-02-11) : Updated the .Net 4.5 and .Net 4.6.2 dll files, too.
- Version 1.0.0.8 (2018-01-22) : Added .Net 4.7. dll.
- Version 1.0.0.7 (2017-08-16) : Adjusted ReloadLanguages() method to work properly.
- Version 1.0.0.6 (2017-08-16) : Added ReloadLanguages() method to ILanguageManager.
- Version 1.0.0.5 (2017-05-14) : Added documentation.
- Version 1.0.0.4 (2017-03-24) : Again simplified the usage of languages.
- Version 1.0.0.3 (2017-03-21) : Simplified the usage of languages.
- Version 1.0.0.2 (2017-02-17) : Code review.
- Version 1.0.0.1 (2016-12-06) : Added EventHandler to subscribe to Event.
- Version 1.0.0.0 (2016-12-06) : 1.0 release.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net2045 is compatible. net2046 is compatible. net2047 is compatible. |
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.1.6 | 0 | 11/24/2024 |
1.1.5 | 134 | 5/16/2024 |
1.1.4 | 303 | 12/7/2023 |
1.1.3 | 141 | 11/13/2023 |
1.1.2 | 465 | 11/10/2022 |
1.1.1 | 358 | 10/30/2022 |
1.1.0 | 536 | 2/8/2022 |
1.0.11 | 339 | 11/11/2021 |
1.0.10 | 344 | 8/9/2021 |
1.0.9 | 374 | 7/25/2021 |
1.0.8 | 383 | 2/21/2021 |
1.0.7 | 574 | 11/11/2020 |
1.0.6 | 536 | 6/5/2020 |
1.0.5 | 557 | 11/8/2019 |
1.0.4.1 | 565 | 10/28/2019 |
1.0.4 | 665 | 10/13/2019 |
1.0.3 | 586 | 9/29/2019 |
1.0.2 | 571 | 9/29/2019 |
1.0.1 | 615 | 6/23/2019 |
1.0.0.12 | 657 | 5/5/2019 |
1.0.0.11 | 1,109 | 3/15/2018 |
1.0.0.10 | 1,083 | 3/12/2018 |
1.0.0.9 | 1,086 | 2/11/2018 |
1.0.0.8 | 1,159 | 1/22/2018 |
1.0.0.7 | 1,187 | 8/18/2017 |
1.0.0.6 | 974 | 8/16/2017 |
1.0.0.5 | 1,046 | 8/10/2017 |
Version 1.0.0.10 (2018-03-12) : Fixed a bug in the package with wrong .Net frameworks.
Version 1.0.0.9 (2018-02-11) : Updated the .Net 4.5 and .Net 4.6.2 dll files, too.
Version 1.0.0.8 (2018-01-22) : Added .Net 4.7. dll.
Version 1.0.0.7 (2017-08-18) : Adjusted ReloadLanguages() method to work properly.
Version 1.0.0.6 (2017-08-16) : Added ReloadLanguages() method to ILanguageManager.
Version 1.0.0.5 (2017-05-14) : Added documentation.
Version 1.0.0.4 (2017-03-24) : Again simplified the usage of languages.
Version 1.0.0.3 (2017-03-21) : Simplified the usage of languages.
Version 1.0.0.2 (2017-02-17) : Code review.
Version 1.0.0.1 (2016-12-06) : Added EventHandler to subscribe to Event.
Version 1.0.0.0 (2016-12-06) : 1.0 release.