[英]Xcode 11/iOS 13 Localization issue
自从在 Xcode 11 GM 中打开项目以来,我遇到了一个问题,即分组 UITableView 没有在我的设置控制器中本地化。
我使用 Localizable Strings 并检查所有 ObjectIds 是否正确。 它适用于 Xcode 10 和 iOS 12 SDK。 奇怪的是本地化在应用程序的其他地方都有效。 这只是一个TableView。
有人,有什么想法吗? 我什至尝试删除本地化并再次添加它。
更新:该问题似乎已在 Xcode 11.2 中修复
——
现在,这在 Xcode 11.1 GM 的发行说明中被确认为一个问题。
故事板和 XIB 文件中的 UITableViewCell 标签在运行时不使用字符串文件中的本地化字符串值。 (52839404)
https://developer.apple.com/documentation/xcode_release_notes/xcode_11_1_release_notes/
我在 Xcode 11 GM 上遇到了同样的问题。 在我的情况下,不应用静态 UITableViewCell 中标题 UILabel 的本地化字符串。
这是我的解决方法;
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = super.tableView(tableView, cellForRowAt: indexPath)
if let label = cell.textLabel, let id = label.accessibilityIdentifier, id.count > 0 {
let key = id + ".text"
let localizedString = NSLocalizedString(key, tableName: "Main", comment: "")
if key != localizedString {
label.text = localizedString
}
}
return cell
}
Xcode 11 现在正式发布了,但事情似乎没有改变。 我还有一个带有静态单元格的表格,单元格的标题使用 objectIds 正确本地化,并且这种方法多年来也能正常工作。 但是从 iOS 13 开始,我必须创建 IBOutlets 并本地化 viewDidLoad 中的静态单元格。 如果有人有更好的主意,欢迎!
lavox 提供的解决方法也对我有用。 在我的应用程序中,我使用的是 Objective-c。 这是对应的:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
if(cell != Nil) {
UILabel *label = cell.textLabel;
NSString *labelId = label.accessibilityIdentifier;
if (labelId.length > 0) {
NSString *key = [labelId stringByAppendingString:@".text"];
NSString *localizedString = NSLocalizedStringFromTable(key, @"Main", @"");
if (key != localizedString) {
label.text = localizedString;
}
}
}
return cell;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.