开发者

Localization of a variable value on iOS

I have around 72 html files in my resource folder and I need to localize them. Now I have translated them in french. A file selection depends on user input so file name is created by a variable. Now the problem is how to localize the value of a variable.

For example, I have following 3 files in resource folder.

  1. AAAAA0.html
  2. BBBBB28.html
  3. CCCCC33.html

I also have these files with in french in resource folder.

  1. AAAAA0-French.html
  2. BBBBB28-French.html
  3. CCCCC33-French.html

Here is my code that is working fine without localization.


// ViewController.m File

appDelegate2=[[[UIApplication sharedApplication] delegate] retain];
NSString *getSign2=[appDelegate2.globalString    stringByAppendingString:appDelegate2.globalindex];
NSString *filePath=[[NSBundle mainBundle] pathForResource:getSign2 ofType:@"html" ];

If user input causes the selection of AAAAA0.html then globalString will be "AAAAA",globalIndex will be "0" and getSign2 will Be "AAAAA0".

If user input causes the selection of BBBBB28.html then globalString will be "BBBBB",globalIndex will be "28" and getSign2 will Be "BBBBB28".

If user input causes the selection of CCCCC33.html then globalString will be "CCCCC",globalIndex will be "33" and getSign2 will Be "CCCCC33".

Now I already have a Localizable.string file and my .xib files are already localized(all labels,images and datepicker etc.).

I want to change the value of getSign2 from AAAAA0.html to AAAA0-French.html if user language is french. Similarly it should change to BBBB28-French.html and CCCC33-French.html for BBBB28.html and CCCC33.html respectively.

What should I add in localizable.string to do this? What change should I make in ViewController.m file?


I know I can use following

NSLocale *locale=[NSLocale currentLocale];
NSString *currentlocale =[locale displayNameForKey:NSLocaleIdentifier value:[locale localeIdentifier]];
NSLog(@"Complete Locale: %@",currentlocale);

if (currentocale==@"French") {

    NSString *getSignNew=[getSign2 stringByAppendingString:@"-French"];
    NSString *filePath=[[NSBundle mainBundle] pathForResource:getSignNew ofType:@"html" ];
}

But开发者_如何学运维 this method check conditions in ViewController.m file while I have done all other localization related coding in localizable.string. Will it cause problem when I will submit my application? If this is not the correct solution then please tell me how to fix this problem.

Please reply as soon as possible.

Thanks.


Localized file should be placed in the structure like this:

Your.app/
  English.lproj/
    AAAAA0.html     // English localized file
    ....
  French.lproj/
    AAAAA0.html     // French localized file
    ...
  zh_TW.lproj/
    AAAAA0.html     // Chinese localized file
    ...

and then -pathForResource:ofType: will automatically look up the correct file matching the current locale.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜