Localization

suggest change

Localization (l10n) means showing text, numbers, dates and sorted lists the way a user in a given region expects. Internationalization (i18n) is the preparation work that makes it possible: no hard-coded strings, no hand-built number formats, no "s" glued onto words for plurals.

On the JVM, Kotlin uses the Java platform for this:

Task API
identify language and region java.util.Locale
numbers, currency, percent java.text.NumberFormat
dates and times java.time.format.DateTimeFormatter
translated strings java.util.ResourceBundle + .properties files
messages with arguments java.text.MessageFormat
sorting and comparing text java.text.Collator
"a, b, and c" java.text.ListFormat (JDK 22+)
plural rules, advanced formatting ICU4J (com.ibm.icu:icu4j)

All examples were run with Kotlin 2.4 on JDK 25. Locale data comes from the Unicode CLDR database bundled with the JDK, so output may differ slightly between JDK versions.

Locale

A Locale is a language, optionally with a region (country), script and variant. Create one from parts with Locale.of() or from a BCP 47 language tag (the format used by HTTP Accept-Language, HTML lang and Android) with Locale.forLanguageTag():

import java.util.Locale

fun main() {
    val us = Locale.US
    val pl = Locale.of("pl", "PL")
    val ptBR = Locale.forLanguageTag("pt-BR")
    val serbianLatin = Locale.forLanguageTag("sr-Latn-RS")

    for (loc in listOf(us, pl, ptBR, serbianLatin)) {
        println("${loc.toLanguageTag()}: language=${loc.language} country=${loc.country} script=${loc.script}")
    }

    // names of a locale, in English and in its own language
    println(pl.getDisplayName(Locale.ENGLISH))
    println(pl.getDisplayName(pl))
    println(Locale.JAPAN.getDisplayLanguage(Locale.FRENCH))

    // toString() uses underscores, toLanguageTag() uses BCP 47 dashes
    println("$ptBR vs ${ptBR.toLanguageTag()}")
}
en-US: language=en country=US script=
pl-PL: language=pl country=PL script=
pt-BR: language=pt country=BR script=
sr-Latn-RS: language=sr country=RS script=Latn
Polish (Poland)
polski (Polska)
japonais
pt_BR vs pt-BR

Locale.of() replaced the Locale(...) constructors, which are deprecated since JDK 19. Use toLanguageTag() when storing or transmitting a locale, never toString().

getDisplayName(locale) in the locale itself is what you show in a language picker: users look for "polski", not "Polish".

The default locale is a trap

The JVM picks a default locale from the operating system (override with -Duser.language=pl -Duser.country=PL). Many APIs silently use it, including String.format():

import java.util.Locale

fun main() {
    println("default: ${Locale.getDefault().toLanguageTag()}")
    val price = 1234.5

    // String.format uses the default locale...
    Locale.setDefault(Locale.GERMANY)
    println("%.2f".format(price))
    println("""{"price": ${"%.2f".format(price)}}""")   // broken JSON

    // ...so pass a locale explicitly
    println("%.2f".format(Locale.ROOT, price))           // machine-readable
    println("%,.2f".format(Locale.FRANCE, price))        // for a French user
    println(price.toString())                            // always uses '.'
}
default: en-US
1234,50
{"price": 1234,50}
1234.50
1 234,50
1234.5

Code that works on your machine produces broken JSON, CSV or SQL on a server configured for German. The rule:

Choosing the user's locale

In a web app the browser sends an Accept-Language header with weighted preferences. Locale.LanguageRange.parse() reads it and Locale.lookup() picks the best match from the locales you support:

import java.util.Locale

val supported = listOf("en", "de", "pl", "pt-BR").map(Locale::forLanguageTag)

fun pickLocale(acceptLanguage: String?): Locale {
    if (acceptLanguage.isNullOrBlank()) return Locale.ENGLISH
    val ranges = try {
        Locale.LanguageRange.parse(acceptLanguage)
    } catch (e: IllegalArgumentException) {
        return Locale.ENGLISH
    }
    return Locale.lookup(ranges, supported) ?: Locale.ENGLISH
}

fun main() {
    val headers = listOf(
        "de-AT,de;q=0.9,en;q=0.8",
        "fr-CA,fr;q=0.9,pl;q=0.5",
        "pt-BR",
        "pt-PT,pt;q=0.9",
        "ja",
        "*;q=0.5,???",
        null,
    )
    for (h in headers) println("%-26s -> %s".format(h, pickLocale(h).toLanguageTag()))
}
de-AT,de;q=0.9,en;q=0.8    -> de
fr-CA,fr;q=0.9,pl;q=0.5    -> pl
pt-BR                      -> pt-BR
pt-PT,pt;q=0.9             -> en
ja                         -> en
*;q=0.5,???                -> en
null                       -> en

lookup truncates de-AT to de and finds it, but it never goes the other way: pt doesn't match pt-BR. If you want Portuguese speakers to get Brazilian Portuguese, add pt to the supported list too. The header is user input, so a malformed value must not crash the request. Store an explicit choice from the user (profile setting or cookie) and prefer it over the header. See HTTP headers for reading headers.

Numbers, currency and percentages

Decimal and grouping separators, currency symbol position and even digits differ between locales:

import java.text.NumberFormat
import java.util.Locale

fun main() {
    val n = 1234567.891
    val locales = listOf(
        Locale.US, Locale.GERMANY, Locale.FRANCE, Locale.of("de", "CH"),
        Locale.forLanguageTag("hi-IN"), Locale.forLanguageTag("ar-EG"),
    )
    for (loc in locales) {
        val num = NumberFormat.getNumberInstance(loc).format(n)
        val cur = NumberFormat.getCurrencyInstance(loc).format(n)
        val pct = NumberFormat.getPercentInstance(loc).format(0.256)
        println("%-6s %-16s %-18s %s".format(loc.toLanguageTag(), num, cur, pct))
    }
}
en-US  1,234,567.891    $1,234,567.89      26%
de-DE  1.234.567,891    1.234.567,89 €     26 %
fr-FR  1 234 567,891    1 234 567,89 €     26 %
de-CH  1’234’567.891    CHF 1’234’567.89   26%
hi-IN  1,234,567.891    ₹1,234,567.89      26%
ar-EG  ١٬٢٣٤٬٥٦٧٫٨٩١    ‏١٬٢٣٤٬٥٦٧٫٨٩ ج.م.‏ ٢٦٪؜

Things to notice:

Use BigDecimal for money (see BigInteger and BigDecimal). The currency is independent of the locale: a US user looking at a price in euros wants the US number style with the euro sign:

import java.math.BigDecimal
import java.text.NumberFormat
import java.util.Currency
import java.util.Locale

fun main() {
    // a currency is separate from the locale: euros shown to a US user
    val usEuro = NumberFormat.getCurrencyInstance(Locale.US).apply {
        currency = Currency.getInstance("EUR")
    }
    println(usEuro.format(BigDecimal("1999.5")))

    // yen has no minor unit, so no decimals
    println(NumberFormat.getCurrencyInstance(Locale.JAPAN).format(1999.5))

    // control the number of fraction digits
    val de = NumberFormat.getNumberInstance(Locale.GERMANY).apply {
        minimumFractionDigits = 2
        maximumFractionDigits = 2
    }
    println(de.format(3.14159))
    println(de.format(42))

    // compact form: "1.2M", "1,2 Mio."
    for (loc in listOf(Locale.US, Locale.GERMANY, Locale.JAPAN)) {
        val short = NumberFormat.getCompactNumberInstance(loc, NumberFormat.Style.SHORT)
        val long = NumberFormat.getCompactNumberInstance(loc, NumberFormat.Style.LONG)
        short.maximumFractionDigits = 1
        long.maximumFractionDigits = 1
        println("${loc.toLanguageTag()}: ${short.format(1_234_567)} | ${long.format(1_234_567)} | ${short.format(15_300)}")
    }
}
€1,999.50
¥2,000
3,14
42,00
en-US: 1.2M | 1.2 million | 15.3K
de-DE: 1,2 Mio. | 1,2 Millionen | 15.300
ja-JP: 123.5万 | 123.5万 | 1.5万

Compact formatting follows local conventions: German has no abbreviation for thousands, and Japanese counts in units of 10,000 (万).

Parsing localized numbers

NumberFormat.parse() is lenient: it stops at the first character it doesn't understand and returns what it has so far. Check that the whole input was consumed:

import java.text.DecimalFormat
import java.text.NumberFormat
import java.text.ParsePosition
import java.util.Locale

fun parseStrict(s: String, locale: Locale): Number? {
    val fmt = NumberFormat.getNumberInstance(locale)
    (fmt as? DecimalFormat)?.isParseBigDecimal = true
    val pos = ParsePosition(0)
    val result = fmt.parse(s.trim(), pos)
    // parse() stops at the first character it doesn't understand;
    // reject input that wasn't consumed completely
    return if (pos.index == s.trim().length) result else null
}

fun main() {
    val de = NumberFormat.getNumberInstance(Locale.GERMANY)
    println(de.parse("1.234,5"))
    println(de.parse("1,234.5"))        // wrong locale: silently becomes 1.234
    println(parseStrict("1.234,5", Locale.GERMANY))
    println(parseStrict("1,234.5", Locale.GERMANY))
    println(parseStrict("12abc", Locale.US))
    // "1.5".toDouble() is locale-independent and always uses '.'
    println("1.5".toDouble())
}
1234.5
1.234
1234.5
null
null
1.5

isParseBigDecimal = true avoids the precision loss of parsing into Double.

Dates and times

DateTimeFormatter.ofPattern("MM/dd/yyyy") hard-codes an American order. For users, let the locale decide with ofLocalizedDate/ofLocalizedDateTime, or with ofLocalizedPattern (JDK 19+), which takes a skeleton of the fields you want and arranges them per locale:

import java.time.DayOfWeek
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
import java.time.format.TextStyle
import java.time.temporal.WeekFields
import java.util.Locale

fun main() {
    val dt = LocalDateTime.of(2026, 3, 9, 14, 30)
    val locales = listOf(Locale.US, Locale.UK, Locale.GERMANY, Locale.JAPAN)
    for (loc in locales) {
        val short = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withLocale(loc)
        val long = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL).withLocale(loc)
        // a skeleton: say which fields you want, the locale decides order and punctuation
        val skeleton = DateTimeFormatter.ofLocalizedPattern("yMMMd").withLocale(loc)
        println("%-6s %-18s %-28s %s".format(loc.toLanguageTag(), dt.format(short), dt.format(long), dt.format(skeleton)))
    }

    println(DayOfWeek.MONDAY.getDisplayName(TextStyle.FULL, Locale.forLanguageTag("pl")))
    println(WeekFields.of(Locale.US).firstDayOfWeek)
    println(WeekFields.of(Locale.GERMANY).firstDayOfWeek)
}
en-US  3/9/26, 2:30 PM    Monday, March 9, 2026        Mar 9, 2026
en-GB  09/03/2026, 14:30  Monday, 9 March 2026         9 Mar 2026
de-DE  09.03.26, 14:30    Montag, 9. März 2026         9. März 2026
ja-JP  2026/03/09 14:30   2026年3月9日月曜日                 2026年3月9日
poniedziałek
SUNDAY
MONDAY

Calendars in a UI should start on WeekFields.of(locale).firstDayOfWeek. In US output the space before PM is a narrow no-break space (U+202F) since JDK 20, another surprise for tests. Time zones, parsing and patterns are covered in Dates and time.

Translated strings with ResourceBundle

Keep user-visible text out of the code, in one .properties file per language. In a Gradle project they go in src/main/resources:

src/main/resources/
  messages.properties       # base / fallback (English)
  messages_de.properties
  messages_pl.properties

messages.properties:

app.title=Photo Gallery
greeting=Hello, {0}!
photos.count=You have {0,number,integer} photos.
logout=Log out

messages_de.properties (no logout key, on purpose):

app.title=Fotogalerie
greeting=Hallo, {0}!
photos.count=Sie haben {0,number,integer} Fotos.

messages_pl.properties:

app.title=Galeria zdjęć
greeting=Cześć, {0}!
photos.count=Masz {0,number,integer} zdjęć.
logout=Wyloguj się

Since Java 9 .properties files used by ResourceBundle are read as UTF-8, so you can write ę directly instead of \u0119 escapes.

A small wrapper makes lookups pleasant from Kotlin:

import java.text.MessageFormat
import java.util.Locale
import java.util.ResourceBundle

class Messages(val locale: Locale) {
    private val bundle = ResourceBundle.getBundle("messages", locale)

    operator fun get(key: String): String = bundle.getString(key)

    fun format(key: String, vararg args: Any): String =
        MessageFormat(bundle.getString(key), locale).format(args)
}

fun main() {
    for (tag in listOf("en-US", "de-DE", "pl-PL")) {
        val m = Messages(Locale.forLanguageTag(tag))
        println("[$tag] bundle locale: '${ResourceBundle.getBundle("messages", m.locale).locale}'")
        println("  ${m["app.title"]}")
        println("  ${m.format("greeting", "Anna")}")
        println("  ${m.format("photos.count", 12345)}")
        println("  ${m["logout"]}")
    }
}
[en-US] bundle locale: ''
  Photo Gallery
  Hello, Anna!
  You have 12,345 photos.
  Log out
[de-DE] bundle locale: 'de'
  Fotogalerie
  Hallo, Anna!
  Sie haben 12.345 Fotos.
  Log out
[pl-PL] bundle locale: 'pl'
  Galeria zdjęć
  Cześć, Anna!
  Masz 12 345 zdjęć.
  Wyloguj się

For de-DE the bundle looks for messages_de_DE, then messages_de, then messages. Bundles are chained, so the missing logout key in German falls back to the English base file instead of failing. Bundles are cached by getBundle, so calling it per request is cheap.

Note that the Polish "Masz 12 345 zdjęć" is only grammatical for some numbers; plurals are covered below.

Fallback to the default locale

When no bundle matches the requested locale, getBundle tries the JVM's default locale before the base file. On a server with a German default locale, a French user gets German:

import java.util.Locale
import java.util.MissingResourceException
import java.util.ResourceBundle

fun main() {
    // pretend the server runs with a German default locale
    Locale.setDefault(Locale.GERMANY)
    val french = Locale.FRENCH  // we have no messages_fr.properties

    val b1 = ResourceBundle.getBundle("messages", french)
    println("default control: '${b1.locale}' -> ${b1.getString("app.title")}")

    val noFallback = ResourceBundle.Control.getNoFallbackControl(ResourceBundle.Control.FORMAT_DEFAULT)
    val b2 = ResourceBundle.getBundle("messages", french, noFallback)
    println("no fallback:     '${b2.locale}' -> ${b2.getString("app.title")}")

    try {
        b2.getString("no.such.key")
    } catch (e: MissingResourceException) {
        println("missing: ${e.key}")
    }
}
default control: 'de' -> Fotogalerie
no fallback:     '' -> Photo Gallery
missing: no.such.key

Use getNoFallbackControl in servers so the result depends only on the user's locale. A missing key throws MissingResourceException; a test that loads every bundle and checks it has the same keys as the base file catches forgotten translations early.

MessageFormat

MessageFormat fills {0}, {1} placeholders and formats each argument for the locale. Translators can reorder arguments freely, which is why you should never build sentences by concatenating fragments or with string templates:

import java.text.MessageFormat
import java.time.ZoneId
import java.time.ZonedDateTime
import java.util.Date
import java.util.Locale

fun main() {
    val pattern = "{0} uploaded {1,number,integer} files on {2,date,long} at {2,time,short}."
    // MessageFormat predates java.time and wants java.util.Date
    val whenUploaded = Date.from(
        ZonedDateTime.of(2026, 3, 9, 14, 30, 0, 0, ZoneId.systemDefault()).toInstant()
    )
    for (loc in listOf(Locale.US, Locale.FRANCE)) {
        println(MessageFormat(pattern, loc).format(arrayOf<Any>("Anna", 1500, whenUploaded)))
    }

    // single quotes are escape characters: double them
    println(MessageFormat.format("Don't delete {0}", "a.txt"))
    println(MessageFormat.format("Don''t delete {0}", "a.txt"))
    println(MessageFormat.format("Use '{name}' literally, {0}", "ok"))

    // choice format: a simple plural that works for English
    val files = MessageFormat("{0,choice,0#no files|1#one file|1<{0,number,integer} files}", Locale.US)
    for (n in listOf(0, 1, 2, 1000)) println(files.format(arrayOf(n)))
}
Anna uploaded 1,500 files on March 9, 2026 at 2:30 PM.
Anna uploaded 1 500 files on 9 mars 2026 at 14:30.
Dont delete {0}
Don't delete a.txt
Use {name} literally, ok
no files
one file
2 files
1,000 files

The apostrophe rule bites in French and Italian translations ("l'utilisateur"): a single ' starts a quoted section, swallowing the quote and everything up to the next one, including placeholders. Every apostrophe in a pattern passed to MessageFormat must be written as ''. Strings you only read with getString (no arguments) keep single apostrophes, so be consistent about which keys go through MessageFormat.

{2,date,long} takes a java.util.Date. To use java.time values, format them with a DateTimeFormatter first and pass the resulting string.

Plurals with ICU4J

choice only compares numbers against ranges, which is enough for English but not for most languages. Polish has different forms for 1, for 2-4 (but also 22-24, 32-34...), for 5-21, and for fractions. The rules for every language are in CLDR, and ICU4J implements them along with ICU MessageFormat syntax, the same syntax used by Android, iOS and most translation tools.

Gradle dependency:

dependencies {
    implementation("com.ibm.icu:icu4j:78.3")
}
import com.ibm.icu.text.MessageFormat
import com.ibm.icu.text.PluralRules
import com.ibm.icu.util.ULocale

fun main() {
    val en = MessageFormat(
        "{count, plural, =0 {No new messages} one {# new message} other {# new messages}}",
        ULocale.ENGLISH,
    )
    val pl = MessageFormat(
        "{count, plural, =0 {Brak nowych wiadomości} one {# nowa wiadomość} " +
            "few {# nowe wiadomości} many {# nowych wiadomości} other {# nowej wiadomości}}",
        ULocale.forLanguageTag("pl"),
    )
    for (n in listOf(0, 1, 2, 5, 22, 25, 1.5)) {
        val args = mapOf("count" to n)
        println("%-4s %-20s %s".format(n, en.format(args), pl.format(args)))
    }

    // which category does a number fall into?
    val rules = PluralRules.forLocale(ULocale.forLanguageTag("pl"))
    println(rules.keywords)
    println(listOf(1, 2, 5, 12, 22, 101).associateWith { rules.select(it.toDouble()) })
}
0    No new messages      Brak nowych wiadomości
1    1 new message        1 nowa wiadomość
2    2 new messages       2 nowe wiadomości
5    5 new messages       5 nowych wiadomości
22   22 new messages      22 nowe wiadomości
25   25 new messages      25 nowych wiadomości
1.5  1.5 new messages     1,5 nowej wiadomości
[few, many, one, other]
{1=one, 2=few, 5=many, 12=many, 22=few, 101=many}

ICU MessageFormat supports named arguments (passed as a Map), # for the locale-formatted number, exact matches like =0, and select for grammatical gender: {gender, select, female {She} male {He} other {They}} liked your photo. The code only passes the number; each translation lists the categories its language needs.

ICU4J also fills gaps in the JDK's formatting:

import com.ibm.icu.number.NumberFormatter
import com.ibm.icu.number.Precision
import com.ibm.icu.text.RelativeDateTimeFormatter
import com.ibm.icu.util.MeasureUnit
import com.ibm.icu.util.ULocale

fun main() {
    val hi = ULocale.forLanguageTag("hi-IN")
    println(java.text.NumberFormat.getNumberInstance(java.util.Locale.forLanguageTag("hi-IN")).format(12345678))
    println(com.ibm.icu.text.NumberFormat.getNumberInstance(hi).format(12345678))

    val speed = NumberFormatter.withLocale(ULocale.GERMANY)
        .unit(MeasureUnit.KILOMETER_PER_HOUR)
        .unitWidth(NumberFormatter.UnitWidth.FULL_NAME)
        .precision(Precision.maxFraction(1))
    println(speed.format(87.26))

    val rel = RelativeDateTimeFormatter.getInstance(ULocale.FRANCE)
    println(rel.formatNumeric(-3.0, RelativeDateTimeFormatter.RelativeDateTimeUnit.DAY))
    println(rel.format(1.0, RelativeDateTimeFormatter.RelativeDateTimeUnit.DAY))
    println(rel.format(-1.0, RelativeDateTimeFormatter.RelativeDateTimeUnit.WEEK))
}
12,345,678
1,23,45,678
87,3 Kilometer pro Stunde
il y a 3 jours
demain
la semaine dernière

ICU4J's jar is large (about 15 MB) because it carries its own copy of CLDR data. Unlike java.text.NumberFormat, the LocalizedNumberFormatter returned by NumberFormatter is immutable and thread-safe.

Lists

JDK 22 added ListFormat for joining items with the locale's separators and conjunction:

import java.text.ListFormat
import java.util.Locale

fun main() {
    val items = listOf("apples", "pears", "plums")
    for (loc in listOf(Locale.US, Locale.UK, Locale.GERMAN, Locale.forLanguageTag("es"))) {
        val and = ListFormat.getInstance(loc, ListFormat.Type.STANDARD, ListFormat.Style.FULL)
        val or = ListFormat.getInstance(loc, ListFormat.Type.OR, ListFormat.Style.FULL)
        println("${loc.toLanguageTag()}: ${and.format(items)} / ${or.format(items.take(2))}")
    }
}
en-US: apples, pears, and plums / apples or pears
en-GB: apples, pears and plums / apples or pears
de: apples, pears und plums / apples oder pears
es: apples, pears y plums / apples o pears

Even the Oxford comma is a locale setting. The items themselves still need translating, of course. On older JDKs use ICU4J's com.ibm.icu.text.ListFormatter.

Sorting and comparing text

sorted() compares UTF-16 code units, so uppercase letters come before lowercase and accented letters go to the end. A Collator sorts the way a dictionary in that language does:

import java.text.Collator
import java.util.Locale

fun main() {
    val words = listOf("zebra", "Äpfel", "apple", "Zürich", "Österreich", "orange", "été", "eagle")

    println("sorted():  ${words.sorted()}")

    val german = Collator.getInstance(Locale.GERMAN)
    println("German:    ${words.sortedWith(german)}")

    val swedish = Collator.getInstance(Locale.forLanguageTag("sv-SE"))
    println("Swedish:   ${words.sortedWith(swedish)}")

    // strength decides which differences matter when comparing
    val c = Collator.getInstance(Locale.FRENCH)
    for ((s, name) in listOf(Collator.PRIMARY to "PRIMARY", Collator.SECONDARY to "SECONDARY", Collator.TERTIARY to "TERTIARY")) {
        c.strength = s
        println("%-9s été==ete: %-5s ete==Ete: %s".format(name, c.equals("été", "ete"), c.equals("ete", "Ete")))
    }
}
sorted():  [Zürich, apple, eagle, orange, zebra, Äpfel, Österreich, été]
German:    [Äpfel, apple, eagle, été, orange, Österreich, zebra, Zürich]
Swedish:   [apple, eagle, été, orange, zebra, Zürich, Äpfel, Österreich]
PRIMARY   été==ete: true  ete==Ete: true
SECONDARY été==ete: false ete==Ete: true
TERTIARY  été==ete: false ete==Ete: false

The same words sort differently in German (where Ä is a variant of A) and Swedish (where Ä and Ö are separate letters after Z). Collator implements Comparator<Any>, so it plugs straight into sortedWith; to sort objects by a field use compareBy(collator) { it.name }. A PRIMARY collator is a good base for accent- and case-insensitive search. When sorting large lists, convert keys once with collator.getCollationKey(s) and compare the keys. More on comparators in Sorting.

Upper and lower case

Kotlin's uppercase(), lowercase() and titlecase() without arguments use Locale.ROOT, so they behave the same on every machine. That's right for identifiers and keys, but not for user-visible text in every language. The classic example is Turkish, which has a dotted and a dotless i:

import java.util.Locale

fun main() {
    val tr = Locale.forLanguageTag("tr-TR")
    // Kotlin's uppercase()/lowercase() use Locale.ROOT: same result everywhere
    println("title".uppercase())
    println("TITLE".lowercase())
    // pass a locale for text shown to users
    println("title".uppercase(tr))
    println("TITLE".lowercase(tr))
    println("straße".uppercase())
    println("istanbul".replaceFirstChar { it.titlecase(tr) })
    println("élan".replaceFirstChar { it.titlecase(Locale.FRENCH) })
}
TITLE
title
TİTLE
tıtle
STRASSE
İstanbul
Élan

Java's toUpperCase() without arguments uses the default locale instead, so "title".toUpperCase() returns "TİTLE" on a Turkish machine and breaks code that compares it to "TITLE". That's one reason Kotlin deprecated toUpperCase() in favour of uppercase(). Case changes can also change length (ß becomes SS); see Unicode and encodings.

Android

Android has its own resource system instead of ResourceBundle: strings live in res/values/strings.xml with translations in res/values-de/strings.xml, res/values-pl/strings.xml and so on, and the system picks the folder from the device language:

<!-- res/values-pl/strings.xml -->
<resources>
    <string name="greeting">Cześć, %1$s!</string>
    <plurals name="new_messages">
        <item quantity="one">%d nowa wiadomość</item>
        <item quantity="few">%d nowe wiadomości</item>
        <item quantity="many">%d nowych wiadomości</item>
        <item quantity="other">%d nowej wiadomości</item>
    </plurals>
</resources>
val greeting = getString(R.string.greeting, user.name)
val label = resources.getQuantityString(R.plurals.new_messages, count, count)

getQuantityString uses the same CLDR plural categories as ICU. The count is passed twice: once to select the form, once as the format argument. Per-app language selection (Android 13+, backported by AppCompat) is set with AppCompatDelegate.setApplicationLocales(LocaleListCompat.forLanguageTags("pl")). The android.icu package exposes ICU APIs (API 24+) without adding the ICU4J jar.

Checklist

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents