top of page

Message Format

  • xiaofudong1
  • Mar 15, 2025
  • 2 min read

What is Message Fromat?

In short word, message format is syntax used for preparing text messages in software applications, allowing them easiliy to be translated into differnt languages while local specific rules dynamically.


This areticle will demonstarte how ICU's formatting message function helps the source text to be prepared for internalization and help tranlators translate strings to other languages with less effort. I will use ICU Playground. to create demo.


Interpolation

Within a translation message, ICU allows developers to interpolate dynamic data. This gives developers flexiablity to create dynamic strings and translators freedom to arrange the possion or select the usage of variables in a sentence. Below is an example:




As you can see, the sentence can be updates based on user input and dynamic data. And the variables (the placeholder in the curley brasket) can be moved to any positions of a sentence based on the need and grammar of the target languge.


Plurals


The messages can be displayed based on the data.



In the example above, ICU can automatically detect the number can display the number based on its category.


In English, when you would like to express plaural, you simply add a "s" at the end of the word in most cases. However, in Russian, numbers ending in "1", "2,3,4", and "5,6,7,8,9,0" have differnt set of rules inplaural.


For example:

один доллар - one dollar

четыре доллара - four dollars

сто долларов - one hundred dollars





Please note, "one", "few", "many" do not necessarily match the traditional grammatical categories. Instead, the categories are determined by changes required in a phrase or sentence if a numeric placeholder changes value. Feel free to look up Plural Rules for reference.


Ordinals


Some languages use ordinals to represent the rank of a number, For example, in English, we have 1st, 2nd, 3rd, 4th.


Select


The select format is used to match a value to a string. It can be used in multiple scenarios. Examples below:




Numbers


The ICU numbder format can format the numbers based on the target local. It can format currencies, plaint numbers, percentages, etc.


Some languages, such as English, use thousand, million, billion to shorten the numbers. However, some languages, such as Chinese, use “万”(Ten thousand), “亿” (100 million) to shorten the numbers. For example, in English, to express "120,000" in a short form it's 120K. In Chinese, it's "12万".


The currency formats are difference across the languges as well. For example, in English, the currency symbol is placed in front of the numbers. However, in Spanish, the currency symbol is placed after the figure with a space.





Date


The date formats varies from languages to languages. For example, in English (United States), the format is month, day, year. In Chinese (China), however, it's year, month, day. With ICU, date format can be easily formatted.





Comments


bottom of page