String Functions (MOPS)

$interpolate()

Signature: $interpolate(localizedStr, replacement)

Replaces dynamic patterns in strings using JSON data. Processes ${"expression"} templates against replacement JSON data. Returns original string if either localizedStr is not a string or no matching replacement found and returns “undefined” for invalid replacement JSON expressions or Non-existent JSON object paths.

Parameters

Parameter Type Description
localizedStr string Template string containing ${"…"} placeholders (Required)
replacement object JSON data containing values for substitution

Examples

  • Simple replacement

    $interpolate("Welcome ${"user.name"}", {user: {name: "Alice"}}) => "Welcome Alice"
    
  • Nested data access

    $interpolate("Total: ${"cart.items[0].price"}", {cart: {items: [{price: 49}]}}) => "Total: 49"
    
  • Function evaluation

    $interpolate("Alert: ${"$uppercase(message.text)"}", {message: {text: "error"}}) => "Alert: ERROR"