Note that there are some explanatory texts on larger screens.

plurals
  1. PONSLocalizedString loads the string sometimes, not always
    text
    copied!<p>NSLocalizedString works only half of the time where I get back the expected the value for the referenced key. The other times I get back the key name specified in NSLocalizedString and consistently happens on every other run.</p> <p>Currently, I am only supporting English at the moment.</p> <p>I'm calling: </p> <pre><code>NSString *someText = NSLocalizedString(@"mystring.keyname", nil); </code></pre> <p>Contents of en.lproj/Localizable.strings:</p> <pre><code>"mystring.keyname" = "Hello there!"; </code></pre> <p>When it's not working correctly, <code>someText's</code> value is <code>mystring.keyname</code>. </p> <p>Here's how I'm testing reliability:</p> <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSBundle *bundle = [NSBundle bundleForClass:[self class]]; NSLog(@"Strings file: %@", [bundle pathForResource:@"Localizable" ofType:@".strings"]); NSLog(@"Localizations: %@", [bundle localizations]); NSLog(@"Local Dict: %@", [bundle localizedInfoDictionary]); NSLog(@"localizedStringForKey: %@", [bundle localizedStringForKey:@"mystring.keyname"value:@"Wha happened?" table:nil]); NSLog(@"Localized String: %@", NSLocalizedString(@"mystring.keyname", @"Are you sure you want to start a new game?")); } </code></pre> <p>This prints out the expected values every the other run:</p> <pre><code>Run #1: Local Dict: (null) localizedStringForKey: Hello there! Localized String: Hello there! Run #2: Local Dict: (null) localizedStringForKey: Wha happened? Localized String: mystring.keyname </code></pre> <p>My files are laid out as such:</p> <pre><code>WORKSPACE_DIR/ my_workspace_name.xcworkspace PROJECT_DIR/ - my_project_name.xcodeproj RESOURCES_DIR/ - en.lproj/ Localizable.strings </code></pre> <p>XCode's project-level settings:</p> <pre><code>1) Build Phases has Localizable.strings listed in the "Copy Bundle Resources". 2) Build Settings: Convert Copied Files =&gt; YES Property List Output Encoding =&gt; binary Strings file Output Encoding =&gt; UTF-16 3) Info.plist's: CFBundleDevelopmentRegion =&gt; 'en' </code></pre> <p>Localizable.strings is configured as UTF-16 although I do not see a Text Settings option in the File Inspector with the strings file selected. But I've verified the encoding type by opening the file in TextWrangler which does show encoding as Unicode (UTF-16) with Unix LF.</p> <p>Any suggestions on how to get this working all of the time?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload