// Copyright (c) 2012-2024 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) : string.Format(Value, n); } /// /// Implicit converter of into . /// /// The localized string. /// The string. public static implicit operator string(LocalizedString str) { if ((object)str == null) return null; return string.IsNullOrEmpty(str.Value) ? Localization.GetString(str.Id) : str.Value; } /// /// Implicit converter of into . /// /// The string. /// The localized string. public static implicit operator LocalizedString(string str) { if (str == null) return null; return new LocalizedString(str); } /// /// Compares two localized strings. /// /// The lft string. /// The right string. /// True if both values are equal, otherwise false. public static bool operator ==(LocalizedString left, LocalizedString right) { return left?.Equals(right) ?? (object)right == null; } /// /// Compares two localized strings. /// /// The lft string. /// The right string. /// True if both values are not equal, otherwise false. public static bool operator !=(LocalizedString left, LocalizedString right) { if ((object)left == null) return (object)right != null; return !left.Equals(right); } /// 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 (object)other != null && 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 (object)this == (object)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; } } }