Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ICU's MessageFormat on iOS

Tags:

ios

iphone

icu

It is my understanding that iOS uses ICU under the hood. I'd like to access the functionality of ICU's MessageFormat for strings involving numbers and plurals, for example,

There {0,choice,0#are no files|1#is one file|1<are {0,number,integer} files}.

Does iOS expose this capability? If so how do I use it? I thought I might be able to write

[NSString stringWithFormat: "There {0,choice,0#are no files|1#is one file|1<are {0,number,integer} files}.", n];

or

[NSString stringWithFormat: "There {0,plural, =0{are no files}=1{is one file}other{are %ld files}}.", n];

But these formats (ICU4J and ICU, respectively) do not work.

like image 358
user371320 Avatar asked Feb 22 '26 03:02

user371320


1 Answers

iOS, like OS X, does include /usr/lib/libicucore.dylib. However, it's not a supported public API on either OS. See this old message for an explanation of how to use it on OS X, and what are the potential issues.

On iOS, I guess there is the additional issue that Apple might reject your application for using unsupported APIs.

like image 86
LaC Avatar answered Feb 24 '26 19:02

LaC