# MessageFormat

# MessageFormat

Artifact:[androidx.core:core-i18n](https://developer.android.com/jetpack/androidx/releases/core)  
[View Source](https://cs.android.com/search?q=file:androidx/core/i18n/MessageFormat.kt+class:androidx.core.i18n.MessageFormat)  
Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/core#1.0.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/core/i18n/MessageFormat "View this page in Java")

<br />

```
class MessageFormat
```

<br />

*** ** * ** ***

## Summary

|                          ### Public companion functions                           |
|-----------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | [format](https://developer.android.com/reference/kotlin/androidx/core/i18n/MessageFormat#format(android.content.Context,kotlin.Int,kotlin.collections.Map))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`, id: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, namedArguments: `[Map](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html)`<`[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`, `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`>)` Formats a message pattern from Android resource for the default locale with a variable number of name/value pair arguments.                                                                                         |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | [format](https://developer.android.com/reference/kotlin/androidx/core/i18n/MessageFormat#format(android.content.Context,java.util.Locale,kotlin.String,kotlin.collections.Map))`(` ` context: `[Context](https://developer.android.com/reference/android/content/Context.html)`,` ` locale: `[Locale](https://developer.android.com/reference/java/util/Locale.html)`,` ` msg: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`,` ` namedArguments: `[Map](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html)`<`[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`, `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`>` `)` Formats a message pattern string with a variable number of name/value pair arguments. |

## Public companion functions

### format

```
fun format(context: Context, id: Int, namedArguments: Map<String, Any>): String
```

Formats a message pattern from Android resource for the default locale with a variable number of name/value pair arguments. Creates an ICU MessageFormat for Locale.getDefault() and pattern, and formats with the arguments.  

|                                                                                                                                   Parameters                                                                                                                                    |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)                                                                                                                                                                                      | Android context object                                                  |
| `id: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                                                                                                                               | Android string resource ID representing ICU-MessageFormat-syntax string |
| `namedArguments: `[Map](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html)`<`[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`, `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`>` | map of argument name to argument value                                  |

### format

```
fun format(
    context: Context,
    locale: Locale = Locale.getDefault(),
    msg: String,
    namedArguments: Map<String, Any>
): String
```

Formats a message pattern string with a variable number of name/value pair arguments. Creates an ICU MessageFormat for the locale and pattern, and formats with the arguments.  

|                                                                                                                                   Parameters                                                                                                                                    |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)                                                                                                                                                                                      | Android context object. Used to retrieve user preferences. |
| `locale: `[Locale](https://developer.android.com/reference/java/util/Locale.html)` = Locale.getDefault()`                                                                                                                                                                       | Locale for number formatting and plural selection etc.     |
| `msg: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)                                                                                                                                                                                        | an ICU-MessageFormat-syntax string                         |
| `namedArguments: `[Map](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html)`<`[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`, `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`>` | map of argument name to argument value                     |