-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ILocalizable and LocalizedString to help build a localized application.
- Loading branch information
Showing
3 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace CLUNL.Localization | ||
{ | ||
/// <summary> | ||
/// Mark a class is localizable | ||
/// </summary> | ||
public interface ILocalizable | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
void ApplyLocalization(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
|
||
namespace CLUNL.Localization | ||
{ | ||
/// <summary> | ||
/// Localized via Language. | ||
/// </summary> | ||
public class LocalizedString | ||
{ | ||
/// <summary> | ||
/// Initialize the string with LanguageID and fallback. | ||
/// </summary> | ||
/// <param name="ID"></param> | ||
/// <param name="Fallback"></param> | ||
public LocalizedString(string ID,string Fallback) | ||
{ | ||
this.ID = ID; | ||
this.Fallback = Fallback; | ||
} | ||
private string ID; | ||
private string Fallback; | ||
/// <summary> | ||
/// Return the localized string. | ||
/// </summary> | ||
/// <returns></returns> | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public override string ToString() | ||
{ | ||
return Language.Find(ID, Fallback); | ||
} | ||
/// <summary> | ||
/// Return the value from ToString(); | ||
/// </summary> | ||
/// <param name="L"></param> | ||
public static implicit operator string(LocalizedString L) | ||
{ | ||
return L.ToString(); | ||
} | ||
} | ||
} |