Rasyidf.Localization 0.5.0

There is a newer version of this package available.
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
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Rasyidf.Localization" Version="0.5.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Rasyidf.Localization --version 0.5.0
#r "nuget: Rasyidf.Localization, 0.5.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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

Nuget

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.5.3 549 4/3/2020
0.5.2 455 3/8/2020
0.5.0 509 1/9/2020
0.3.0 822 1/20/2019
0.2.0 1,009 1/8/2019

Added some functionalities, see readme for more details.