Are parameters in strings.xml possible?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Yes, parameters in Android strings.xml are possible through format placeholders. This is the standard way to insert dynamic values such as names, counts, and dates while keeping text localizable. The key is choosing the correct placeholder type and formatting with resources APIs rather than manual string concatenation.
Use Format Placeholders in strings.xml
Define placeholders like %1$s, %2$d, or %1$.2f in string resources.
Why numbered placeholders matter:
- translators can reorder placeholders for grammar,
- multiple parameters remain unambiguous,
- formatting remains consistent across locales.
Pass Parameters from Kotlin or Java
Kotlin usage:
Java usage:
Always use getString or resource APIs so Android applies locale-sensitive formatting correctly.
Use plurals for Count-Dependent Text
For quantities, prefer plurals instead of trying to handle singular or plural manually.
This gives translators proper control over language rules beyond simple English patterns.
Escaping and Formatting Rules
Some characters require escaping in XML, and format syntax must remain valid.
Example with literal percent sign:
If you need apostrophes, use escaped form or surrounding quotes based on lint recommendations.
Also enable formatting checks in Android lint. It catches placeholder mismatches between default and translated resources.
Placeholder Reordering for Localization
Different languages may change word order. Indexed placeholders support this safely.
Without index markers, reordered parameters can break at runtime.
Avoid Concatenation and Build Messages in Resources
Instead of:
Prefer resource-driven formatting:
This keeps UI text fully translatable and consistent.
Format Numbers and Dates with Locale Awareness
When placeholders include numeric or date values, format those values using locale-aware APIs before passing them into getString.
Kotlin example:
strings.xml:
This keeps localization consistent and avoids forcing translators to parse raw machine formats.
Translation Safety and Lint Validation
Android lint can detect placeholder mismatches between languages. Keep placeholders aligned across all localized strings.xml files and run lint in CI. Placeholder mismatch errors are easier to fix during pull requests than after runtime crashes.
Also keep placeholder indexes stable over time. Renumbering placeholders carelessly can break older translations during incremental localization updates. Consistent review checklists help prevent this regression.
Common Pitfalls
A common mistake is using unnumbered placeholders in strings that may be translated into languages with different token order. Use indexed placeholders such as %1$s to avoid reorder bugs.
Another issue is passing wrong data types for placeholders, such as string for %d. This can throw runtime formatting exceptions.
Developers also hardcode dynamic text through concatenation, which blocks localization and causes inconsistent phrasing across screens.
Summary
- Parameters in
strings.xmlare supported through format placeholders. - Use indexed placeholders to support localization-safe reordering.
- Use
pluralsresources for count-dependent text. - Format strings via
getStringand related resources APIs. - Avoid manual concatenation to keep text translatable and maintainable.

