objective-c - NSLocalizedString 不起作用

标签 objective-c ios xcode cocoa-touch localization

我想在我的应用程序中使用 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/

相关文章:

ios Google SignIn 集成不会从应用程序注销

ios - 更改 MFMailComposeViewController 的工具栏颜色

objective-c - TripIt 长久以来的代币

objective-c - 在 UIWebView 中预加载 JavaScript

swift - 用于在 Xcode 中实现自定义 UI 设计的资源

javascript - 在 iOS 中通过 javascript 进行 ARC4 加密

objective-c - 这里有内存泄漏吗?

iphone - Xcode 3.1.3 - Organizer 设备未激活。请使用 iTunes 激活

ios - 何时何地以编程方式初始化/创建 View

iphone - UI 导航后退按钮与 "multi paged"父 View 配合使用的问题