LocalizedValueParser

class LocalizedValueParser(preferredLocaleKeys: List<String> = DEFAULT_PREFERRED_LOCALE_KEYS)

Parses a backend field that's either a plain string or a JSON-encoded {locale: value} map, preferring preferredLocaleKeys (falling back to the first non-blank value) when it's a map.

A common shape for backends that localize a single field without a full i18n response envelope.

Constructors

Link copied to clipboard
constructor(preferredLocaleKeys: List<String> = DEFAULT_PREFERRED_LOCALE_KEYS)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun parse(value: String?): String?

Parses a plain string (returned as-is) or a JSON-encoded {locale: value} map. A decoded locale map with no usable entry yields null (as the JsonElement overload does) rather than leaking the raw JSON into the UI. Non-string entries are handled exactly as the JsonElement overload handles them.

fun parse(element: JsonElement): String?
Link copied to clipboard

Returns the first non-blank value among preferredLocaleKeys, else the first non-blank value in values. A preferred locale present with a blank value is skipped, not returned.