NwN
NwN

Reputation: 1

ICU Resource bundle best practices

I was wondering about what the best practice is for writing, and mostly maintaining, an ICU resourcebundle. More specifically the best way to handle recurring strings.

For instance, say you have following resourcebundle:

root:table {
  remove_page:string { "Remove this page" }
  remove_widget:sring { "Remove this widget" }
}

Off course this is minimal, but I'm implying a big project with lots of similar strings and "sub-tables". Would it be best to keep it like this, viz. using a specific string for every action in the code, or would it be better practice to combine strings for example, as such:

root:table {
  remove_this:string { "Remove this " }
  page:string { "page" }
  widget:string { "widget" }
}

Being an amateur I don't have much experience with ICU resourcebundles so far, but if they are properly built they should be very handy for i18n and maintenance, hence the question.

Thank you very much in advance for your time.

Edit: ICU info on Recourse Bundle Format - These formats might also be good to keep in mind in structuring a resource bundle, arrays take less memory than tables for instance. Off course these are "nameless", which might be a huge pain for reading the code.

Upvotes: 0

Views: 908

Answers (1)

Steven R. Loomis
Steven R. Loomis

Reputation: 4350

See Formatting Messages. and MessageFormat::format() with named arguments. You do not want to be "concatenating" strings. Instead you might do something like this:

root {
  remove_this  { "Remove this {thing}." }
  page { "page" }
  widget { "widget" }
}

Note that because of rules in various languages, it may be easier to translate "Remove: {thing}", because the word "this" may need to be inflected due to gender, case, number, etc., for which see SelectFormat.

Upvotes: 1

Related Questions