// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
using System;
using System.Globalization;
namespace FlaxEngine
{
partial class Localization
{
///
/// Creates new culture.
///
/// The name (eg. en, pl-PL).
/// The culture.
public static CultureInfo NewCulture(string name)
{
return new CultureInfo(name);
}
}
partial class LocalizedString : IEquatable, IEquatable, IComparable, IComparable, IComparable
{
///
/// Empty string without localization.
///
public static readonly LocalizedString Empty = new LocalizedString(null);
///
/// Initializes a new instance of the class.
///
/// The value.
public LocalizedString(string value)
{
Value = value;
}
///
/// Gets the localized plural string for the current language by using string id lookup.
///
/// The value count for plural message selection.
/// The localized text.
public string ToStringPlural(int n)
{
return string.IsNullOrEmpty(Value) ? Localization.GetPluralString(Id, n) : Value;
}
///
/// Implicit converter of into .
///
/// The localized string.
/// The string.
public static implicit operator string(LocalizedString str)
{
return str.ToString();
}
///
/// Implicit converter of into .
///
/// The string.
/// The localized string.
public static implicit operator LocalizedString(string str)
{
return new LocalizedString(str);
}
///
public int CompareTo(object obj)
{
if (obj is string asString)
return CompareTo(asString);
if (obj is LocalizedString asLocalizedString)
return CompareTo(asLocalizedString);
return 0;
}
///
public bool Equals(LocalizedString other)
{
return Id == other.Id && Value == other.Value;
}
///
public bool Equals(string other)
{
return Value == other || Localization.GetString(Id) == other;
}
///
public int CompareTo(LocalizedString other)
{
return string.Compare(ToString(), ToString(), StringComparison.Ordinal);
}
///
public int CompareTo(string other)
{
return string.Compare(ToString(), other, StringComparison.Ordinal);
}
///
public override bool Equals(object obj)
{
return ReferenceEquals(this, obj) || obj is LocalizedString other && Equals(other);
}
///
public override int GetHashCode()
{
unchecked
{
return ((Id != null ? Id.GetHashCode() : 0) * 397) ^ (Value != null ? Value.GetHashCode() : 0);
}
}
///
public override string ToString()
{
return string.IsNullOrEmpty(Value) ? Localization.GetString(Id) : Value;
}
}
}