Localisation strings not always work having ShareKit in a project

删除回忆录丶 提交于 2020-01-11 11:32:22

问题


since I've removed some localisations from my app, I have this problem: the first time I load my app, I see the localised string of my key in a label. The second time I load the app, the xxxxxkey appears. The next time I load the app, everything is fine again (showing the localized string). How can this be?

I would be glad, if anyone could point me in the right direction. I'm on Xcode 4.2.

Thanks in advance!


回答1:


I experienced this too after adding the ShareKit library to my project. As it turned out, the issue was that ShareKit includes a localizable.strings file and that my own project included a file with the same name. I'm not sure why, but when you launched the app either of these two localizable.strings were picked up, not both. If you rename your localizable.strings file so that there is no conflicting filename, the issue should disappear.

If you rename your localizable.strings, you need to update the code that loads strings from this particular strings file by using the NSLocalizedStringFromTable macro instead of NSLocalizedString. For example, I renamed ShareKit's localizable.strings to ShareKit.strings and edited the first line of this method as follows:

NSString* SHKLocalizedString(NSString* key, ...) 
{
    // Localize the format
    // Was:
    // NSString *localizedStringFormat = NSLocalizedString(key, key);
    NSString *localizedStringFormat = NSLocalizedStringFromTable(key, @"ShareKit", key);

    va_list args;
    va_start(args, key);
    NSString *string = [[[NSString alloc] initWithFormat:localizedStringFormat arguments:args] autorelease];
    va_end(args);

    return string;
}


来源:https://stackoverflow.com/questions/7747436/localisation-strings-not-always-work-having-sharekit-in-a-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!