Skip to content

goaaats/CheapLoc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Jan 10, 2023
58b6c45 · Jan 10, 2023

History

31 Commits
Jun 11, 2021
Jan 10, 2023
Apr 30, 2021
Apr 5, 2020
Apr 30, 2021
Apr 6, 2022

Repository files navigation

CheapLoc Nuget

CheapLoc is a .NET localization library that is easy to integrate, very low-effort to maintain and does not require maintaining a separate localization database.

It outputs JSON files that can be used together with popular localization tools like Crowdin.

Integration Example

To setup the localization library, call Loc.Setup().

var allowedLang = new [] { "de", "ja", "fr", "it", "es" };

var currentUiLang = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
Log.Information("Trying to set up Loc for culture {0}", currentUiLang);

if (allowedLang.Any(x => currentUiLang == x))
{
    Loc.Setup(File.ReadAllText($"loc_{currentUiLang}.json"));
}
else
{
    Loc.SetupWithFallbacks();
}

To receive a localized string, call Loc.Localize().

var locText = Loc.Localize("StringKey", "Hello, World.");

To generate localization files, call Loc.ExportLocalizable(). You can specify the target assembly in each function of Loc.