Rasyidf.Localization
0.5.0
See the version list below for details.
Requires NuGet 2.12 or higher.
dotnet add package Rasyidf.Localization --version 0.5.0
NuGet\Install-Package Rasyidf.Localization -Version 0.5.0
<PackageReference Include="Rasyidf.Localization" Version="0.5.0" />
paket add Rasyidf.Localization --version 0.5.0
#r "nuget: Rasyidf.Localization, 0.5.0"
// Install Rasyidf.Localization as a Cake Addin
#addin nuget:?package=Rasyidf.Localization&version=0.5.0
// Install Rasyidf.Localization as a Cake Tool
#tool nuget:?package=Rasyidf.Localization&version=0.5.0
Rasyidf Localization
Fast and simple localization framework for wpf. allow dynamic loading and multiple language pack.
Getting Started
Installation
To use this framework. add nuget package:
Install-Package Rasyidf.Localization
Then register the the services on App.cs
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
// set the language packs folder and default language
LanguageService.Current.Initialize("Assets/Languages", "en-US");
}
...
Usage
after installing and loading th assembly, add namespace in the xaml
xmlns:rf="clr-namespace:Rasyidf.Localization;assembly=Rasyidf.Localization"
All set, now you can implement Binding in any XAML like this:
Bind like this
<MenuItem Header="{rf:Tr File, Uid=11}"/>
Or this
<TextBlock Text="{rf:Tr Default='Default Hello World', Uid=11}"/>
<TextBlock Text="{rf:Tr FallBackText, Uid=12}"/>
Or this, with Format String
<TextBlock>
<Run>
<rf:Tr Uid="24" Default="Language : {0}, Count : {1} ">
<Binding FallbackValue="en-US" Mode="OneWay"
Path="CurrentLanguage" />
<Binding FallbackValue="0" Mode="OneWay"
Path="LanguageCount" />
</rf:Tr>
</Run>
</TextBlock>
in code, you can consume directly by using :
MessageBox.Show(LocalizationService.GetString("511", "Text", "Default Message"),LocalizationService.GetString("511", "Header","Default Title"));
another way is to use String extension. "[uid],[vid]".Localize("[Default]")
MessageBox.Show("511,Text".Localize("Default Message"),("511,Header").Localize("Default Title"));
Language Packs
The Language Pack can be XML or JSON like below, put in the language folder:
Version 0.5 support some additional metadata (AppId, Author, Type, Version) planned for future version.
XML Language Pack
<Pack Version="0.5" AppId="YourAppId" Author="Rasyid" EnglishName="English" CultureName="English" Culture="en-US">
<Value Id="0" Header="Window Title" />
<Value Id="11" Header="File" />
<Value Id="110" Header="Exit" />
...
<Value Id="511" Header="Hello Wold" Text="This Is message String" />
</Pack>
JSON Language Pack
Version 0.5 Support Json Multilingual Package.
Single Language Pack
{ "AppId" : "YourAppId",
"Version" : "0.5", "Type" : "Single",
"EnglishName": "Indonesian", "CultureName": "Bahasa Indonesia",
"Culture": "id-ID",
"Data": [
{ "Id": 0, "Header": "Judul Jendela" },
{ "Id": 11, "Header": "Berkas" },
{ "Id": 110, "Header": "Keluar" }
]
}
Multi Language Pack
{
"AppId": "",
"Version": "0.5",
"Type": "Multi",
"Author": "Rasyid",
"Languages": [
{
"CultureId": "en-US"
},
{
"CultureId": "de-DE"
}
],
"Data": [
{
"data": [
{
"Id": 0,
"Text": {
"en-US": "Hello", "de-DE": "Hallo"
}
},
]
}
]
}
}
All Done 😃
What is new
0.5.0
- Translation string extension use
"UID, VID".Translate()
to get localized string. - Multiple Language pack in single file.
- Decouple LanguageStream with Language Item.
0.4.0
- Raw support for xml
Authors
- Rasyid, Muhammad Fahmi - Initial work - Rasyidf
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE.md file for details
Acknowledgments
See list of third party components for aditional acknowledgements
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. 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.
Added some functionalities, see readme for more details.