LocalizableString class
A class to store and manage a set of localized strings for different languages.
Example:
final greetings = LocalizableString({
"en": "Hello",
"es": "Hola",
"fr": "Bonjour",
});
print(greetings.localize("es")); // "Hola"
print(greetings.localize("de")); // "Hello" (fallback to "en")
- Available extensions
Constructors
-
LocalizableString(Map<
String, String> _strings) -
Creates a LocalizableString from a map of language codes to strings.
const
- LocalizableString.empty()
-
Creates an empty LocalizableString.
const
- LocalizableString.from(Object? source)
-
Factory constructor that converts any object into a LocalizableString.
factory
Properties
- hashCode → int
-
The hash code for this object.
no setteroverride
- isEmpty → bool
-
Returns true if no localized strings are available.
no setter
- isNotEmpty → bool
-
Returns true if at least one localized string is available.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- use → LocalizableString
-
Available on LocalizableString?, provided by the LocalizableStringHelper extension
Returns the LocalizableString itself or an empty instance if null.no setter - verified → LocalizableString?
-
Available on LocalizableString?, provided by the LocalizableStringHelper extension
Returns this instance if it contains at least one string; otherwise null.no setter
Methods
-
copyWith(
{Map< String, String> ? strings}) → LocalizableString - Returns a copy of this object, optionally replacing the internal map.
-
localize(
String language) → String? -
Returns the localized string for the given
languagecode. -
localize(
String language) → String? -
Available on LocalizableString?, provided by the LocalizableStringHelper extension
Returns the localized string for the givenlanguage. -
modifyWith(
{Map< String, String> strings = const {}}) → LocalizableString - Adds or updates multiple localized strings in place and returns this instance.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override