我想在我的应用程序中使用 NSLocalizedString,但它总是失败。我所做的是:
- 在项目属性中定义 3 个本地化(见下面的截图)
- 创建一个新文件:资源字符串文件
- 检查应用包是否存在 file.strings
然后我使用 NSLocalizedStrings 如下,但它不起作用!
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
NSString *v1 = NSLocalizedString(@"MyWindow", nil);
//NSString *v1 = [[NSBundle mainBundle] localizedStringForKey:(@"MyWindow") value:@"" table:nil];
[label setStringValue:v1];
}
在我的 3 个 .strings 文件中,我定义了以下键/值: "MyWindow"= "Ma Fenetre";
通常,我的标签应该显示“Ma Fenetre”而不是“MyWindows” 您可以下载an example project here and tell me where is the issue .
下面是我的应用程序包中 Resources 文件夹的内容:
DerivedData om$ find test/Build/Products/Debug/test.app/Contents/Resources/
test/Build/Products/Debug/test.app/Contents/Resources/
test/Build/Products/Debug/test.app/Contents/Resources//de.lproj
test/Build/Products/Debug/test.app/Contents/Resources//de.lproj/File.strings
test/Build/Products/Debug/test.app/Contents/Resources//en.lproj
test/Build/Products/Debug/test.app/Contents/Resources//en.lproj/File.strings
test/Build/Products/Debug/test.app/Contents/Resources//fr.lproj
test/Build/Products/Debug/test.app/Contents/Resources//fr.lproj/File.strings
test/Build/Products/Debug/test.app/Contents/Resources//MainMenu.nib
谢谢 埃尔福罗斯
最佳答案
NSLocalizedString
默认使用 Localizable.strings
文件。更改您的 File.strings
名称并重试。
关于objective-c - NSLocalizedString 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10863513/