Class LocalizableString
- Namespace
- GroupeIsa.Neos.Shared.Localization
- Assembly
- GroupeIsa.Neos.Shared.dll
Represents a localizable string.
[JsonConverter(typeof(LocalizableStringJsonConverter))]
public sealed class LocalizableString : IEquatable<LocalizableString>
- Inheritance
-
LocalizableString
- Implements
- Inherited Members
- Extension Methods
Constructors
LocalizableString()
Initializes a new instance of the LocalizableString class.
public LocalizableString()
LocalizableString(IDictionary<string, string>)
Initializes a new instance of the LocalizableString class from the specified dictionary.
public LocalizableString(IDictionary<string, string> dictionary)
Parameters
dictionaryIDictionary<string, string>The dictionary that contains the data to copy.
LocalizableString(string)
Initializes a new instance of the LocalizableString class from a single localized string.
public LocalizableString(string defaultTranslation)
Parameters
defaultTranslationstringDefault localized string.
Properties
Count
Gets the number of elements.
public int Count { get; }
Property Value
DefaultTranslation
Gets the default translation corresponding to the default language of the cluster.
public string DefaultTranslation { get; }
Property Value
ExtendedProperties
Gets the extended properties used with OData query.
public IDictionary<string, object> ExtendedProperties { get; }
Property Value
this[string]
Gets the translation for the specified language.
public string this[string key] { get; }
Parameters
keystringThe language id.
Property Value
- string
The translation.
Exceptions
- KeyNotFoundException
The language id does not exist.
Keys
Gets the collection of localized string languages.
public ICollection<string> Keys { get; }
Property Value
Values
Gets the collection of localized string values.
public ICollection<string> Values { get; }
Property Value
Methods
AsEnumerable()
Converts to enumerable.
public IEnumerable<KeyValuePair<string, string>> AsEnumerable()
Returns
- IEnumerable<KeyValuePair<string, string>>
An enumerable.
Combine(LocalizableString, Func<string, string, string>)
Combines a localization string with another localizable string.
public LocalizableString Combine(LocalizableString value, Func<string, string, string> combineMethod)
Parameters
valueLocalizableStringLocalizable string..
combineMethodFunc<string, string, string>Combine method.
Returns
- LocalizableString
The new localizable string.
ContainsKey(string)
Gets a value indicating whether the specified language is defined.
public bool ContainsKey(string language)
Parameters
languagestringThe language.
Returns
- bool
Truewhen the specified language is defined,Falseotherwise.
ConvertFromJson(string)
Converts from JSON.
public static LocalizableString ConvertFromJson(string value)
Parameters
valuestringValue.
Returns
- LocalizableString
A new instance of the LocalizableString class.
ConvertFromString(string)
Converts from string.
public static LocalizableString ConvertFromString(string value)
Parameters
valuestringValue.
Returns
- LocalizableString
A new instance of the LocalizableString class.
ConvertToJson()
Converts to JSON.
public string ConvertToJson()
Returns
- string
string representation.
ConvertToString()
Converts to string.
public string ConvertToString()
Returns
- string
string representation.
Equals(LocalizableString?)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(LocalizableString? other)
Parameters
otherLocalizableStringAn object to compare with this object.
Returns
- bool
true if the current object is equal to the other parameter; otherwise, false.
Equals(object?)
Determines whether the specified object is equal to the current object.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current object.
Returns
- bool
true if the specified object is equal to the current object; otherwise, false.
FromFormattedResource(ILocalizationSettings, ResourceManager, string, params object?[])
Gets a LocalizableString from a resource with a format item in each language replaced with the string representation of a corresponding object in the specified array.
public static LocalizableString FromFormattedResource(ILocalizationSettings localizationSettings, ResourceManager resourceManager, string resourceWithFormatName, params object?[] args)
Parameters
localizationSettingsILocalizationSettingsLocalization settings.
resourceManagerResourceManagerResource manager. For example
Resources.MyModule.ResourceManager.resourceWithFormatNamestringName of the resource that contains a format.
argsobject[]An object array that contains zero or more objects to format.
Returns
- LocalizableString
Localizable string corresponding to the resource in which the format items in each language have been replaced by the string representation of the corresponding objects in
args.
FromResource(ILocalizationSettings, ResourceManager, string)
Gets a LocalizableString from a resource.
public static LocalizableString FromResource(ILocalizationSettings localizationSettings, ResourceManager resourceManager, string resourceName)
Parameters
localizationSettingsILocalizationSettingsLocalization settings.
resourceManagerResourceManagerResource manager. For example
Resources.MyModule.ResourceManager.resourceNamestringName of the resource.
Returns
- LocalizableString
Localizable string corresponding to the resource.
FromString(string)
Converts a string to LocalizableString.
public static LocalizableString FromString(string defaultTranslation)
Parameters
defaultTranslationstringDefault localized string.
Returns
- LocalizableString
The localizable string containing the default translation.
GetAdditionalTranslations(ILocalizationSettings?)
Gets the list of translations except the default one.
public IEnumerable<KeyValuePair<string, string>> GetAdditionalTranslations(ILocalizationSettings? settings = null)
Parameters
settingsILocalizationSettingsSettings.
Returns
- IEnumerable<KeyValuePair<string, string>>
The additional translations.
GetDefaultTranslation(ILocalizationSettings?)
Gets default translation.
public string GetDefaultTranslation(ILocalizationSettings? settings = null)
Parameters
settingsILocalizationSettingsSettings.
Returns
- string
The default translation.
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
GetTranslationOrDefault(string?, ILocalizationSettings?)
Gets the translation for the specified language or the default one if not found.
public string GetTranslationOrDefault(string? language = null, ILocalizationSettings? settings = null)
Parameters
languagestringThe language.
settingsILocalizationSettingsThe settings.
Returns
- string
The translation.
ToDictionary()
Converts to dictionary.
public IDictionary<string, string> ToDictionary()
Returns
- IDictionary<string, string>
The dictionary.
ToString()
Gets one of the strings according to the current localization settings.
public override string ToString()
Returns
- string
The localized string.
Remarks
This is the overridden version of the object.ToString method:
it allows using those objects for string interpolation.
ToString(char, char)
Join strings with a delimiter and escape any occurrence of the delimiter and the escape character in the string.
public string ToString(char delimiterChar, char escapeChar = '\\')
Parameters
Returns
- string
Joined string.
TryGetValue(string, out string)
Gets the value associated with the specified language.
public bool TryGetValue(string language, out string value)
Parameters
Returns
- bool
true if the object contains an element with the specified language; otherwise, false.
WithTranslation(string, string?)
Gets a new instance with a modified translation.
public LocalizableString WithTranslation(string language, string? value)
Parameters
Returns
- LocalizableString
A new instance.
Operators
implicit operator Dictionary<string, string>(LocalizableString)
Implicitly converts a LocalizableString to a dictionary.
public static implicit operator Dictionary<string, string>(LocalizableString localizableString)
Parameters
localizableStringLocalizableStringThe localizableString to implicitly convert.
Returns
implicit operator LocalizableString(Dictionary<string, string>)
Defines an implicit conversion of a given Dictionary{string, string} to LocalizableString.
public static implicit operator LocalizableString(Dictionary<string, string> dictionary)
Parameters
dictionaryDictionary<string, string>A array to implicitly convert.
Returns
implicit operator LocalizableString(string)
Implicitly converts a string to LocalizableString.
public static implicit operator LocalizableString(string defaultTranslation)
Parameters
defaultTranslationstringDefault localized string.