简体   繁体   English

Xcode 11/iOS 13 本地化问题

[英]Xcode 11/iOS 13 Localization issue

I am having an issue with a grouped UITableView not getting localized in my settings controller since opening the project in Xcode 11 GM.自从在 Xcode 11 GM 中打开项目以来,我遇到了一个问题,即分组 UITableView 没有在我的设置控制器中本地化。

I use Localizable Strings and checked that all ObjectIds are correct.我使用 Localizable Strings 并检查所有 ObjectIds 是否正确。 It worked in Xcode 10 and iOS 12 SDK.它适用于 Xcode 10 和 iOS 12 SDK。 The weird things is that the localization works everywhere else in the app.奇怪的是本地化在应用程序的其他地方都有效。 It is just that one TableView.这只是一个TableView。

Someone, any ideas?有人,有什么想法吗? I even tried removing localization and adding it again.我什至尝试删除本地化并再次添加它。

Update: The issue seems to be fixed in Xcode 11.2更新:该问题似乎已在 Xcode 11.2 中修复

-- ——

This is now acknowledged as an issue in the release notes for Xcode 11.1 GM.现在,这在 Xcode 11.1 GM 的发行说明中被确认为一个问题。

UITableViewCell labels in storyboards and XIB files do not use localized string values from the strings file at runtime.故事板和 XIB 文件中的 UITableViewCell 标签在运行时不使用字符串文件中的本地化字符串值。 (52839404) (52839404)

https://developer.apple.com/documentation/xcode_release_notes/xcode_11_1_release_notes/ https://developer.apple.com/documentation/xcode_release_notes/xcode_11_1_release_notes/

I faced the same issue with Xcode 11 GM.我在 Xcode 11 GM 上遇到了同样的问题。 In my case, localization strings for title UILabel in static UITableViewCell are not applied.在我的情况下,不应用静态 UITableViewCell 中标题 UILabel 的本地化字符串。

Here is my workaround;这是我的解决方法;

  1. Copy the labels' Object ID into Accessibility Identifier with the storyboard manually.手动将标签的对象 ID 与故事板一起复制到辅助功能标识符中。
  2. Implement the following codes in the UITableViewDataSource class.在 UITableViewDataSource 类中实现以下代码。
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 is now officially released, but the things seem not to have been changed. Xcode 11 现在正式发布了,但事情似乎没有改变。 I have also a table with static cells, the cells' titles are correctly localized using objectIds, and this approach also used to work fine for years.我还有一个带有静态单元格的表格,单元格的标题使用 objectIds 正确本地化,并且这种方法多年来也能正常工作。 But since iOS 13 I must create IBOutlets and localize the static cells in viewDidLoad.但是从 iOS 13 开始,我必须创建 IBOutlets 并本地化 viewDidLoad 中的静态单元格。 If somebody has a better idea, welcome!如果有人有更好的主意,欢迎!

The workaround provided by lavox also worked for me. lavox 提供的解决方法也对我有用。 In my app I'm using objective-c.在我的应用程序中,我使用的是 Objective-c。 This is the counterpart:这是对应的:

- (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;
}

I have to convert every single table static I have to custom cells.我必须将每个表静态转换为自定义单元格。 If you keep them with a "style different than custom" you lose the localisation feature.如果您将它们保留为“不同于自定义的样式”,您将失去本地化功能。 I'm attaching a image on where you have to change it.我在你必须改变它的地方附上了一张图片。 It means a lot of work too, you must delete every single wire already made it make it again, set up the constraints of your labels etc... Basically, does not use any style different than Custom and you are ok.这也意味着很多工作,您必须删除已经制作的每一根电线,重新制作它,设置标签的约束等......基本上,不使用与自定义不同的任何样式,您没问题。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM