Class I18nString

  • All Implemented Interfaces:
    android.os.Parcelable

    public final class I18nString
    extends Object
    implements android.os.Parcelable
    A string with a different value depending of the language. It's recommended to support a default value defaultValue() (optional) for non supported languages.

    ISO 639-2 is used to identify the languages.

    See Also:
    Locale.getISO3Language()
    • Field Detail

      • ANY_LANGUAGE

        public static final String ANY_LANGUAGE
        Special code, non ISO 693-2, to denote value to use by default.
        See Also:
        Constant Field Values
      • CREATOR

        public static final android.os.Parcelable.Creator<I18nString> CREATOR
    • Constructor Detail

      • I18nString

        public I18nString​(@NonNull
                          Map<String,​String> values)
        Parameters:
        values - non null map, with non null keys and values. Keys should be language's ISO 693-2 codes
    • Method Detail

      • get

        @NonNull
        public String get​(@NonNull
                          String language)
        Obtains the string in the provided language. If there is no value for that language, return value for ANY_LANGUAGE
        Parameters:
        language - ISO 639-2 language name representation, or ANY_LANGUAGE. If is null, will check for ANY_LANGUAGE
        Returns:
        String. Empty if there is no value for this language, or if provided language is null or empty.
      • defaultValue

        @NonNull
        public String defaultValue()
      • has

        public boolean has​(@NonNull
                           String language)
        Check if the language is supported by this I18nString
        Parameters:
        language - ISO 639-2 language name representation. Not null.
        Returns:
        true if there is some value for this string, false otherwise.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • describeContents

        public int describeContents()
        Specified by:
        describeContents in interface android.os.Parcelable
      • writeToParcel

        public void writeToParcel​(android.os.Parcel dest,
                                  int flags)
        Specified by:
        writeToParcel in interface android.os.Parcelable