cocoa touch - iOS, how to localize an app into Chinese, with numbering? -


my app shows numbers of buttons, number symbols.

can ios produce localization of number symbols based on language selection, if how?

i'm outputting string, guess need kind of regional formatting functionality?

first, make project support chinese:

enter image description here

second, add localizable.strings file translated text like: enter image description here

third, make file localized chinese:

enter image description here enter image description here

finally, able use translation like:

self.hellolabel.text = nslocalizedstring(@"hello!", @"a text saying hello label"); 

the "你好!" displayed if iphone's language chinese.

for number converting:

nsstring *localizedstring = [nsnumberformatter localizedstringfromnumber: @(1314)          numberstyle: nsnumberformatterspelloutstyle];   nslog(@"formatted string:%@",localizedstring);  //formatted string:一千三百一十四  (if system region china) 

if want directly convert number symbols:

- (nsstring *)getnumbersymbols:(nsinteger)number {     nsarray *symbols = @[@"零",@"一",@"二",@"三",@"四",@"五",@"六",@"七",@"八",@"九"];     nsmutablestring *result = [nsmutablestring stringwithformat:@"%ld",(long)number];      (int = 0;i<symbols.count;i++) {          [result replaceoccurrencesofstring:          [nsmutablestring stringwithformat: @"%ld",(long)i]                                 withstring: symbols[i]                                    options: nscaseinsensitivesearch                                      range: nsmakerange(0, result.length)];     }     return result; } 

or:

- (nsstring *)getnumbersymbols:(nsinteger)number {     nsmutablestring *result = [nsmutablestring stringwithformat:@"%ld",(long)number];     (int = 0;i<=9;i++) {          nsstring *localizednumber = [nsnumberformatter localizedstringfromnumber:@(i)            numberstyle:nsnumberformatterspelloutstyle];          [result replaceoccurrencesofstring:                [nsmutablestring stringwithformat:@"%ld",(long)i]                     withstring: localizednumber                        options: nscaseinsensitivesearch                          range: nsmakerange(0, result.length)];     }     return result; } 

use it:

nsstring *result = [self getnumbersymbols:134]; //output: 一三四 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -