3

Rust's string formatting macros (e.g. "println!" and "format!") require their format string argument to be a string literal (as observed here). Given this, what approach should I use for formatting messages where the text (which will need a additional data embedded into it) needs to come from an external source, e.g. a database of message translations, like a .po file or similar?

Community
  • 1
  • 1
Jules
  • 14,841
  • 9
  • 83
  • 130
  • 1
    This is an area of Rust that is definitely not mature yet. – Chris Morgan Mar 16 '15 at 12:34
  • I have been experimenting with that and have some early version https://github.com/pzol/r18n – Piotr Zolnierek Mar 17 '15 at 16:17
  • If I'm reading your question correctly, you may wish to reword it. I think that people are getting hung up on the internationalization part of your question, and missing that you are basically asking *"how can I have a dynamic format string?"* Including that you want to do i18n is useful for context, though. – Shepmaster Mar 21 '15 at 18:15

1 Answers1

1

Rust explicitly chose NOT to attempt to address the problem for now.

The issue of internationalization and localization is hairy; there are lots of quirks in natural languages:

  • in English, you use the th suffix after a number to form a literal, except when it's st (after 1 or 21 but not after 11) or nd or rd
  • in Polish, you have relatively complex rules for plural forms

To the best of my knowledge, no library today addresses the full complexity of what would be needed for a "complete" solution to internationalization in any language. Rust investigation can be followed here.

Matthieu M.
  • 287,565
  • 48
  • 449
  • 722