[英]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.