本地化字符串并不总是在项目中使用ShareKit [英] Localisation strings not always work having ShareKit in a project

查看:119
本文介绍了本地化字符串并不总是在项目中使用ShareKit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我从我的应用程序中删除了一些本地化,所以我遇到了这个问题:第一次加载应用程序时,我在标签中看到了我的密钥的本地化字符串。第二次加载应用程序时,会出现xxxxxkey。下次加载应用程序时,一切都很好(显示本地化的字符串)。这怎么可能?

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?

如果有人能指出我正确的方向,我会很高兴的。我在Xcode 4.2上。

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

提前致谢!

推荐答案

我将ShareKit库添加到项目后也遇到过这种情况。事实证明,问题是ShareKit包含一个localizable.strings文件,我自己的项目包含一个同名文件。我不知道为什么,但是当你启动应用程序时,这两个localizable.strings中的任何一个都被拾取,而不是两者。如果重命名localizable.strings文件,以便没有冲突的文件名,问题就会消失。

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.

如果重命名localizable.strings,则需要更新代码通过使用NSLocalizedStringFromTable宏而不是NSLocalizedString从此特定字符串文件加载字符串。例如,我将ShareKit的localizable.strings重命名为ShareKit.strings并编辑了此方法的第一行,如下所示:

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;
}

这篇关于本地化字符串并不总是在项目中使用ShareKit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆