I'm creating this iOS app, in which I use the PushWoosh (www.pushwoosh.com) notification service. Notification is working fine, but now I want to differentiate notification based upon the locale of the app: I want the users of the app running their OS in English to receive a notification in English, the German users in German, etc. For that, I register this one app several times with PushWoosh, so each localization gets its own Pushwoosh App ID. For simplicity sake, I'm aiming to have all localization stuff in one file ("localizable.strings"). PushWoosh requires to have their APPID listed in the info.plist. So what would make sense to me, is to have the value of the PushWoosh .plist key localized. This is what I did:

In the .plist, I replaced

<key>Pushwoosh_APPID</key>
<string>2B46A-F82CC</string>

with

<key>Pushwoosh_APPID</key>
<string>PUSHWOOSH_ID</string>

Then, in the localizable.strings, I added the following entry:

"PUSHWOOSH_ID" = "2B46A-F82CC";

Finally, in the code, I replaced

[[NSUserDefaults standardUserDefaults] setObject:appCode forKey:@"Pushwoosh_APPID"];

with

[[NSUserDefaults standardUserDefaults] setObject:appCode forKey:NSLocalizedString(@"Pushwoosh_APPID", nil)];

Somehow, however, when running the app, "Pushwoosh_APPID" resolves into "PUSHWOOSH_ID", rather than in "2B46A-F82CC".

All other strings in localizable.strings are called just fine, so I guess it's a syntax thing.

Concrete question: what am I doing wrong, code-wise? Also, shoot me if this is an undesirable approach in general.

Thanks in advance!

有帮助吗?

解决方案

For localizing Info.plist values, you will need to create a separate strings file called InfoPlist.strings under your language-specific project directory, such as en.lproj, etc, and put the key and the translated value there, for example:

Pushwoosh_APPID = "2B46A-F82CC";

Take a look at the reference of Information Property List Key:

... you store the values for a particular localization in a strings file with the name InfoPlist.strings. You place this file in the same language-specific project directory that you use to store other resources for the same localization. The contents of the InfoPlist.strings file are the individual keys you want localized and the appropriately translated value. The routines that look up key values in the Info.plist file take the user’s language preferences into account and return the localized version of the key (from the appropriate InfoPlist.strings file) when one exists. If a localized version of a key does not exist, the routines return the value stored in the Info.plist file.

其他提示

FYI Pushwoosh provides the Multi-language support for sending notifications in the language, which is set in the OS. Its based on Tags, and can be used both via the Control Panel and API. I suppose it would be way easier not to reinvent the wheel :)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top