Localisation strings not always work having ShareKit in a project

后端 未结 1 1713
渐次进展
渐次进展 2021-01-25 08:12

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 th

相关标签:
1条回答
  • 2021-01-25 08:56

    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;
    }
    
    0 讨论(0)
提交回复
热议问题