Skip to content

Commit

Permalink
[v2.2.2] Update
Browse files Browse the repository at this point in the history
(~) Updated: nullable ResolveString()
(+) Added: ResolveStringOrFallback()
(~) Updated: License
  • Loading branch information
Sargeras02 committed Mar 25, 2024
1 parent 7baf980 commit 2dafba0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Sargeras02
Copyright (c) 2023-2024, SKitLs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
18 changes: 16 additions & 2 deletions Model/DefaultLocalizator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,21 @@ public DefaultLocalizator(string localsPath)
/// The localized string based on the specified language key and key identifier, or a fallback string
/// if the requested string is not defined in the specified language.
/// </returns>
public string ResolveString(LangKey lang, string key, params string?[] format)
=> InternalResolveString(lang, key, format) ?? FallbackString(lang, key, format);
public string? ResolveString(LangKey lang, string key, params string?[] format) => InternalResolveString(lang, key, format);

/// <summary>
/// Resolves the localized string for the specified language key and key identifier, with optional format parameters.
/// </summary>
/// <param name="lang">The language key for localization.</param>
/// <param name="key">The unique identifier for the localized string.</param>
/// <param name="format">Optional. An array of strings to be formatted into the resolved localized string.</param>
/// <returns>
/// The localized string based on the specified language key and key identifier, or a fallback string
/// if the requested string is not defined in the specified language.
/// </returns>
public string ResolveStringOrFallback(LangKey lang, string key, params string?[] format) => InternalResolveString(lang, key, format)
?? FallbackString(lang, key, format);

private string? InternalResolveString(LangKey lang, string key, params string?[] format)
{
if (!(Localizations.ContainsKey(lang) && Localizations[lang].ContainsKey(key)))
Expand All @@ -79,6 +92,7 @@ public string ResolveString(LangKey lang, string key, params string?[] format)

return string.Format(Localizations[lang][key], format);
}

private string FallbackString(LangKey lang, string key, params string?[] format)
{
var reply = InternalResolveString(LangKey.EN, NotDefinedKey, Enum.GetName(lang), key, LocalsPath)
Expand Down
12 changes: 11 additions & 1 deletion Prototype/ILocalizator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public interface ILocalizator
/// Represents the key indicating that the requested string is not defined in the specified language.
/// </summary>
public string NotDefinedKey { get; }

/// <summary>
/// Represents the path to the localization resource files.
/// </summary>
Expand All @@ -22,6 +23,15 @@ public interface ILocalizator
/// <param name="key">The unique identifier for the localized string.</param>
/// <param name="format">Optional. An array of strings to be formatted into the resolved localized string.</param>
/// <returns>The localized string based on the specified language key and key identifier.</returns>
public string ResolveString(LangKey lang, string key, params string?[] format);
public string? ResolveString(LangKey lang, string key, params string?[] format);

/// <summary>
/// Resolves the localized string for the specified language key and key identifier, with optional format parameters.
/// </summary>
/// <param name="lang">The language key for localization.</param>
/// <param name="key">The unique identifier for the localized string.</param>
/// <param name="format">Optional. An array of strings to be formatted into the resolved localized string.</param>
/// <returns>The localized string based on the specified language key and key identifier.</returns>
public string ResolveStringOrFallback(LangKey lang, string key, params string?[] format);
}
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,14 @@ Thank you for considering contributing to our project.
This project is distributed under the terms of the MIT License.
Copyright (C) Sargeras02 2023
Copyright (C) 2023-2024, Sargeras02
## Developer contact
For any issues related to the project, please feel free to reach out to us through the project's GitHub page.
We welcome bug reports, feedback, and any other inquiries that can help us improve the project.
You can also contact the project owner directly via their GitHub profile at the following [link](https://github.com/Sargeras02).
You can also contact the project owner directly via their GitHub profile at the [following link](https://github.com/Sargeras02) or email: skitlsdev@gmail.com
Your collaboration and support are highly appreciated, and we will do our best to address any concerns or questions promptly and professionally.
Thank you for your interest in our project.
Expand Down
11 changes: 6 additions & 5 deletions SKitLs.Utils.Localizations.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>$(AssemblyName)</Title>
<AssemblyVersion>2.2.0</AssemblyVersion>
<AssemblyVersion>2.2.2</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<PackageProjectUrl>https://github.com/Sargeras02/SKitLs.Utils.Localizations.git</PackageProjectUrl>
<PackageProjectUrl>https://github.com/SKitLs-dev/SKitLs.Utils.Localizations.git</PackageProjectUrl>
<Version>$(AssemblyVersion)</Version>
<Description>Comprehensive localization package that facilitates seamless string translation and adaptation for diverse language contexts.</Description>
<Authors>Sargeras02, SKit-Labs</Authors>
<Copyright>Copyright (C) Sargeras02 2023</Copyright>
<Authors>SKitLs, Sargeras02</Authors>
<Copyright>Copyright (C) 2023-2024, SKitLs</Copyright>
<PackageIcon>libIcon_localizations.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>XML Docimentation Included</PackageReleaseNotes>
<PackageReleaseNotes>Package info Updated.
Ownership transfered to SKitLs.</PackageReleaseNotes>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<PackageTags>Localization, Internationalization, Multilingual, Globalization</PackageTags>
Expand Down

0 comments on commit 2dafba0

Please sign in to comment.