A fully dynamic and easy-to-use solution for multi-lingual support
- Load and switch languages at runtime without recompiling or restarting.
- Simple setup and usage with minimal code changes necessary.
If you want to include Pi18n in your project, you can install it directly from NuGet.
Support: Net40+ | Net5.0+ | netstandard2.0+
-
Resource Files: Create resource files for different languages.
Example:.resource/language-resource-ja-JP.ui.i18n .resource/language-resource-ja-JP.msg.i18n .resource/language-resource-zh-CN.ui.i18n .resource/language-resource-zh-CN.msg.i18n
Resource content style:
Key=Value
-
Configuration: Set up the
ResourceManager
with the appropriate resource path and naming convention.ResourceManager.SetUp("resource", "language-resource-{I18N}.{ANY}.i18n"); ResourceManager.SetLanguage(ResourceManager.CultureInfoList[0].Name);
Access the localized strings using the Resource
.
public class CustomClass
{
public dynamic Resource => ResourceManager.Instance;
}
MessageBox.Show(Resource["MessageText"]);
MessageBox.Show(Resource.MessageText);
public class ViewModel : ObservableObject
{
public dynamic Resource => ResourceManager.Instance;
}
<TextBlock Text="{Binding Resource[Hello]}"/>
<TextBlock Text="{Binding Resource.Hello}"/>
- Instance : Get instance of ResourceManager
- DefaultCulture : Get or set default CultureInfo instance
- CurrentCulture : Get or set current CultureInfo instance
- CultureInfoList : Get list of CultureInfo instance
- CultureCodeList : Get list of culture code (like "en-US")
- CultureNameList : Get list of culture name (like "English (United States)")
void SetUp(string path, string format)
: Sets up the ResourceManager with the appropriate resource path and naming convention.bool SetDefault(CultureInfo cultureInfo)
: Sets the default language by CultureInfo object.bool SetDefault(string cultureCode)
: Sets the default language by culture code.bool SetDefault(CultureType cultureType)
: Sets the default language by culture type (CurrentUICulture | CurrentCulture).bool SetLanguage(CultureInfo cultureInfo)
: Sets or switches the current language by CultureInfo object.bool SetLanguage(string cultureCode)
: Sets or switches the current language by culture code.string GetFormat(string key, params object[] args)
: Get formatted string.
- LanguageChanged : Language changed
- LanguageChangedEventArgs.OldCultureInfo
- LanguageChangedEventArgs.NewCultureInfo