在没有故事板的项目中本地化 UIAlertView 和离线通知
localize UIAlertView & offline notifications in project with no storyboard
我正在做一个没有任何 storyboards
的项目。所以我不能使用 "base internationalization"
我创建了 localizable.string 然后为每种必需的语言打开了本地化。
然后尝试做
- UIAlertView * messageBox = [[UIAlertView alloc] initWithTitle:
NSLocalizedString(@"title", nil)
message: NSLocalizedString(@"msg", nil)
delegate: self
cancelButtonTitle: NSLocalizedString(@"ok", nil)
otherButtonTitles: nil];
对于通知,我使用 nsdictionary 并将通知存储为:
- [alertMessages setObject:NSLocalizedString(@"test_notification", nil)
forKey:@"6"];
但是在更改设备语言时它不会做任何更改。有没有我遗漏的步骤或者是否有更好的方法?任何工作参考将不胜感激!
解决方案 1:
执行以下步骤。
- Clean Project
- Delete App From Device/Simulator
- If Simulator - Reset it.
- Delete Derived Files (XCode > Window > Projects > Derived Data Delete)
- Install App, and it will work.
我认为这只是缓存问题。
解决方案 2:
NSLocalizedString 默认使用 Localizable.strings 文件。更改您的 File.strings 名称并重试。
NSLocalizedStringFromTable(@"Message", @"File");
我正在做一个没有任何 storyboards
的项目。所以我不能使用 "base internationalization"
我创建了 localizable.string 然后为每种必需的语言打开了本地化。
然后尝试做
- UIAlertView * messageBox = [[UIAlertView alloc] initWithTitle:
NSLocalizedString(@"title", nil)
message: NSLocalizedString(@"msg", nil)
delegate: self
cancelButtonTitle: NSLocalizedString(@"ok", nil)
otherButtonTitles: nil];
对于通知,我使用 nsdictionary 并将通知存储为:
- [alertMessages setObject:NSLocalizedString(@"test_notification", nil)
forKey:@"6"];
但是在更改设备语言时它不会做任何更改。有没有我遗漏的步骤或者是否有更好的方法?任何工作参考将不胜感激!
解决方案 1:
执行以下步骤。
- Clean Project
- Delete App From Device/Simulator
- If Simulator - Reset it.
- Delete Derived Files (XCode > Window > Projects > Derived Data Delete)
- Install App, and it will work.
我认为这只是缓存问题。
解决方案 2:
NSLocalizedString 默认使用 Localizable.strings 文件。更改您的 File.strings 名称并重试。
NSLocalizedStringFromTable(@"Message", @"File");