HaemmerElectronics.SeppPenner.Language
1.0.0.11
Prefix Reserved
See the version list below for details.
dotnet add package HaemmerElectronics.SeppPenner.Language --version 1.0.0.11
NuGet\Install-Package HaemmerElectronics.SeppPenner.Language -Version 1.0.0.11
<PackageReference Include="HaemmerElectronics.SeppPenner.Language" Version="1.0.0.11" />
paket add HaemmerElectronics.SeppPenner.Language --version 1.0.0.11
#r "nuget: HaemmerElectronics.SeppPenner.Language, 1.0.0.11"
// Install HaemmerElectronics.SeppPenner.Language as a Cake Addin #addin nuget:?package=HaemmerElectronics.SeppPenner.Language&version=1.0.0.11 // Install HaemmerElectronics.SeppPenner.Language as a Cake Tool #tool nuget:?package=HaemmerElectronics.SeppPenner.Language&version=1.0.0.11
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.11 (2018-03-15) : Fixed bug with different .Net versions in the Nuget package.
- 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 | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 is compatible. net463 was computed. net47 is compatible. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
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.5 | 105 | 5/16/2024 |
1.1.4 | 261 | 12/7/2023 |
1.1.3 | 122 | 11/13/2023 |
1.1.2 | 440 | 11/10/2022 |
1.1.1 | 340 | 10/30/2022 |
1.1.0 | 517 | 2/8/2022 |
1.0.11 | 319 | 11/11/2021 |
1.0.10 | 323 | 8/9/2021 |
1.0.9 | 345 | 7/25/2021 |
1.0.8 | 358 | 2/21/2021 |
1.0.7 | 553 | 11/11/2020 |
1.0.6 | 517 | 6/5/2020 |
1.0.5 | 536 | 11/8/2019 |
1.0.4.1 | 544 | 10/28/2019 |
1.0.4 | 642 | 10/13/2019 |
1.0.3 | 560 | 9/29/2019 |
1.0.2 | 554 | 9/29/2019 |
1.0.1 | 595 | 6/23/2019 |
1.0.0.12 | 626 | 5/5/2019 |
1.0.0.11 | 1,086 | 3/15/2018 |
1.0.0.10 | 1,062 | 3/12/2018 |
1.0.0.9 | 1,060 | 2/11/2018 |
1.0.0.8 | 1,138 | 1/22/2018 |
1.0.0.7 | 1,157 | 8/18/2017 |
1.0.0.6 | 955 | 8/16/2017 |
1.0.0.5 | 1,022 | 8/10/2017 |
Version 1.0.0.11 (2018-03-15) : Fixed bug with different .Net versions in the Nuget package.
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.