Last active
April 1, 2016 16:39
-
-
Save dodikk/a1f6e66fc3e22b32402d577ab1f2bab5 to your computer and use it in GitHub Desktop.
[localization] Plurals and strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Take %1$#@lu_pills@ at %2$@ | |
| NSString* format = NSLocalizedString(@"REMINDER_PREVIEW_FORMAT", nil); | |
| NSString txtDate = @"5:42 PM"; | |
| NSString* result = [NSString localizedStringWithFormat:format | |
| (unsigned long long)[reminder numberOfPills], | |
| txtDate]; | |
| // Actual : Take 1 pill at (null) | |
| // Expected : Take 1 pill at 5:42 PM | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
| <plist version="1.0"> | |
| <dict> | |
| <key>REMINDER_PREVIEW_FORMAT</key> | |
| <dict> | |
| <key>NSStringLocalizedFormatKey</key> | |
| <string>Take %1$#@lu_pills@ at %2$@</string> | |
| <key>lu_pills</key> | |
| <dict> | |
| <key>NSStringFormatSpecTypeKey</key> | |
| <string>NSStringPluralRuleType</string> | |
| <key>NSStringFormatValueTypeKey</key> | |
| <string>lu</string> | |
| <key>one</key> | |
| <string>%1$lu pill</string> | |
| <key>other</key> | |
| <string>%1$lu pills</string> | |
| </dict> | |
| </dict> | |
| </dict> | |
| </plist> |
Author
Author
Solution : types of integers must match.
%1$lu + unsigned long
%1llu + unsigned long long
// Take %1$#@lu_pills@ at %2$@
NSString* format = NSLocalizedString(@"REMINDER_PREVIEW_FORMAT", nil);
NSString txtDate = @"5:42 PM";
NSString* result = [NSString localizedStringWithFormat:format
(unsigned long)[reminder numberOfPills],
txtDate];
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A very dirty workaround