Skip to content

Softeq/XToolkit.Localization

Repository files navigation

Localization Generator

Localization generator was developed to ease using native localization and keep all localization keys and translation in one file (csv) that is easy to read and maintain using external tools such as Excel or Google docs and outsource localization.

Table of Contents:

Example of localization files in google sheet: image

How to Build

using Visual Studio for Mac

  • Download and extract the sources;
  • Open in Visual Studio;
  • Make sure that Softeq.XToolkit.Localization.ConsoleApp is set as startup project;
  • Under Build menu select Publish to Folder:

Publish to folder

using .NET CLI

  • Download and extract the sources;
  • Go to the source folder in the terminal;
  • Build the CLI tool and save to output folder:
dotnet publish -c Release src/Softeq.XToolkit.Localization.ConsoleApp -o <OUTPUT_FOLDER>

Note: Also, you can use -r option to build platform-specific executable binaries.

How to Use

Open terminal in folder with GenerateLocalization.dll and type dotnet GenerateLocalization.dll and configure using configuration options listed below separating by whitespaces.

To call help with suggestions run command dotnet GenerateLocalization.dll -h or dotnet GenerateLocalization.dll --help

help_option

Configuration Options

--csv (Required)

Path to csv file with localization (see example below).

csv_example


--clmns (Required)

Columns mapping from files language columns to language codes. Mapping must be given in form of "file_column_name : language_2_letter_code" separated by space for each map. For example: "English : en" "French : fr", where "English" and "French" is a first row column names and "en" and "fr" is language codes.

Note: configuring only columns map and csv file path will result in generating only resources for all supported platforms (iOS and Android) and will be saved to generated folder inside folder with called GenerateLocalization.dll.


--platforms (Required)

Option to specify for which platforms resource must be generated. Supported options are droid - to generate localization files for Android; ios - to generate localization files for iOS; and resx - to generate resx resources that is used for Xamarin.Forms and MAUI application.

Note: if you choose to generate resx files you can still use platform specific prefixes to generate platform specific values (for iOS InfoPlist prefix (--plist_prf) and --drd-prf for Android specific values).


Note: if you configure with resx option along droid option. Values xml files will be generated for droid configuration. But if you configuring only resx then android xml values files will be generated for --drd-prf keys in csv file.


Suggestion: if you configure generating resources for resx it is better to create Resources.resx files with all supported languages to let automatically generate resouece designer files and link them with in project file.


--int

Option to provide localization interface name. For example setting option --int ILocalization will generate interface:

public interface ILocalization
{
}

To put "ILocalization" inside the namespace pass namespace name along with interface name separating it by dot. For example passing option --int MyProject.Common.Localization.ILocalization will generated interface with next content:

namespace MyProject.Common.Localization
{
    public interface ILocalization
    {
    }
}

--int-fld

Option to specify folder where generator must put generated localization interface. If not specified -- generated interface won't be transferred and could be found in generated folder.


--res-cls

Option to provide ResX localization interface implementation class name. For example setting option --res-cls Resources will generate following class if interface option is not specified:

public class Resources
{
}

If interface option specified such as --int IResources next localization class will be generated:

public class Resources : IResources
{
}

To put Resources inside the namespace pass namespace name along with interface name separating it by dot. For example passing option --res-cls MyProject.Common.Localization.Resources will generated interface with next content:

namespace MyProject.Common.Localization
{
    public class Resources
    {
    }
}

if you pass localization with namespace like --int MyProject.Common.Localization.Interfaces.IResources and specify ResX localization class as --res-cls MyProject.Common.Localization.Resources you will receive next result:

using MyProject.Common.Localization.Interfaces;

namespace MyProject.Common.Localization
{
    public class Resources : IResources
    {
    }
}

--resx-fld

Option to specify folder where generator must put generated Resources.resx files. If not specified -- generated interface won't be transferred and could be found in generated folder.


--resx-int-imp-fld

Option to specify folder where generator must put generated Resources class class set by --res-cls option with getting strings from resx file properties. If not specified -- generated interface won't be transferred and could be found in generated folder.


--ios

Option to provide iOS localization interface implementation class name. For example setting option --ios IosLocalization will generate following class if interface option is not specified:

public class IosLocalization
{
}

If interface option specified such as --int ILocalization next localization class will be generated:

public class IosLocalization : ILocalization
{
}

To put IosLocalization inside the namespace pass namespace name along with interface name separating it by dot. For example passing option --ios MyProject.Ios.Localization.IosLocalization will generated interface with next content:

namespace MyProject.Ios.Localization
{
    public class IosLocalization
    {
    }
}

if you pass localization with namespace like --int MyProject.Common.Localization.ILocalization and specify iOS localization class as --ios MyProject.Ios.Localization.IosLocalization you will receive next result:

using MyProject.Common.Localization;

namespace MyProject.Ios.Localization
{
    public class DroidLocalization : ILocalization
    {
    }
}

--ios-fld

iOS project folder where generated resources and generated localization class will be put.

Note: resources files will be transferred to Resources folder inside languageCode.jproj folders


--ios-int-imp-fld

Option to specify exact folder inside iOS project folder specified by --ios-fld option where generated localization class must be put after generation.


--drd

Option to provide Android localization interface implementation class name. For example setting option --drd DroidLocalization will generate following class if interface option is not specified:

public class DroidLocalization
{
}

If interface option specified such as --int ILocalization next localization class will be generated:

public class DroidLocalization : ILocalization
{
}

To put DroidLocalization inside the namespace pass namespace name along with interface name separating it by dot. For example passing option --drd MyProject.Droid.Localization.DroidLocalization will generated interface with next content:

namespace MyProject.Droid.Localization
{
    public class DroidLocalization
    {
    }
}

if you pass localization with namespace like --int MyProject.Common.Localization.ILocalization and specify Android localization class as --drd MyProject.Droid.Localization.DroidLocalization you will receive next result:

using MyProject.Common.Localization;

namespace MyProject.Droid.Localization
{
    public class DroidLocalization : ILocalization
    {
    }
}

--drd-fld

Droid project folder where generated resources and generated localization class will be put.

Note: resources files will be transferred to Resources folder inside values-.. folders


--drd-int-imp-fld

Option to specify exact folder inside Android project folder specified by --drd-fld option where generated localization class must be put after generation.


--drd-prf

Option to specify Android only resource prefix that used in localization csv file.

Default prefix: Droid_


--ios-prf

Option to specify iOS only resource prefix that used in localization csv file.

Default prefix: IOS_


--plist_prf

Option to specify iOS InfoPlist resource prefix that used in localization csv file.

Default prefix: IosIPlist_


--df-lng

Option to specify default language. You must pass two letter language code that is one column mapping specified for --clmns option. For example to specify default language as English you have to pass: --df-lng en

It will result in generating English resource files inside values folder for Android and Base.lproj folder in iOS.

Note: value of default language will be used if there is no translation for key for another language.


--cln-gen

Option for cleaning previous generated localization files before generating new files. Possible options is true or false.



© 2023 Softeq Development Corporation.