TnmsLocalizationPlatform.Shared
0.0.2
dotnet add package TnmsLocalizationPlatform.Shared --version 0.0.2
NuGet\Install-Package TnmsLocalizationPlatform.Shared -Version 0.0.2
<PackageReference Include="TnmsLocalizationPlatform.Shared" Version="0.0.2" />
<PackageVersion Include="TnmsLocalizationPlatform.Shared" Version="0.0.2" />
<PackageReference Include="TnmsLocalizationPlatform.Shared" />
paket add TnmsLocalizationPlatform.Shared --version 0.0.2
#r "nuget: TnmsLocalizationPlatform.Shared, 0.0.2"
#:package TnmsLocalizationPlatform.Shared@0.0.2
#addin nuget:?package=TnmsLocalizationPlatform.Shared&version=0.0.2
#tool nuget:?package=TnmsLocalizationPlatform.Shared&version=0.0.2
TnmsLocalizationPlatform
What is this?
This is a common platform for managing player language settings and enabling each plugin to easily support multiple languages.
On the first connection, the player's cl_language setting is automatically retrieved and saved.
Features
Automatic Management of Player Language Settings
When a player connects to the server, their cl_language setting is automatically retrieved and saved to the database. On subsequent connections, the saved language setting is used.
Localizer for Multilingual Support
Provides multilingual support based on Microsoft.Extensions.Localization through the ITnmsLocalizer interface.
Usage
Adding Dependencies
Install TnmsLocalizationPlatform.Shared from NuGet.
dotnet add package TnmsLocalizationPlatform.Shared
Plugin Development
Getting an Instance
private ITnmsLocalizationPlatform? _localizationPlatform;
public void OnAllModulesLoaded()
{
_localizationPlatform = SharedSystem.GetSharpModuleManager()
.GetRequiredSharpModuleInterface<ITnmsLocalizationPlatform>(
ITnmsLocalizationPlatform.ModSharpModuleIdentity).Instance;
}
Implementing ILocalizableModule
Implement ILocalizableModule in your plugin.
public class YourPlugin : IModSharpModule, ILocalizableModule
{
public string ModuleDirectory => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
// ...other implementations
}
Creating and Using a Localizer
private ITnmsLocalizer _localizer = null!;
// Creating a Localizer
public void OnAllModulesLoaded()
{
_localizer = _localizationPlatform.CreateStringLocalizer(this);
}
// Usage example
public void SendLocalizedMessage(IGameClient client, string key, params object[] args)
{
var localizedString = _localizer.ForClient(client, key, args);
client.PrintToChat(localizedString.Value);
}
// Getting a string for a specific culture
public string GetLocalizedString(string key, CultureInfo culture, params object[] args)
{
if (_localizer != null)
{
return _localizer[key, culture, args].Value;
}
return key;
}
Getting Player Language Settings
public void CheckPlayerLanguage(IGameClient client)
{
var playerCulture = _localizer.GetClientCulture(client);
Console.WriteLine($"Player {client.PlayerName} uses language: {playerCulture.Name}");
}
Placing Language Files
modules/yourmodle/lang/
Another develop info
For more details, please refer to the code documentation.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- ModSharp.Sharp.Shared (>= 2.1.79)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on TnmsLocalizationPlatform.Shared:
| Package | Downloads |
|---|---|
|
TnmsPluginFoundation
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.