简体   繁体   中英

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.

I use Localizable Strings and checked that all ObjectIds are correct. It worked in Xcode 10 and iOS 12 SDK. The weird things is that the localization works everywhere else in the app. It is just that one TableView.

Someone, any ideas? I even tried removing localization and adding it again.

Update: The issue seems to be fixed in Xcode 11.2

--

This is now acknowledged as an issue in the release notes for Xcode 11.1 GM.

UITableViewCell labels in storyboards and XIB files do not use localized string values from the strings file at runtime. (52839404)

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

I faced the same issue with Xcode 11 GM. In my case, localization strings for title UILabel in static UITableViewCell are not applied.

Here is my workaround;

  1. Copy the labels' Object ID into Accessibility Identifier with the storyboard manually.
  2. Implement the following codes in the UITableViewDataSource class.
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. 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. But since iOS 13 I must create IBOutlets and localize the static cells in viewDidLoad. If somebody has a better idea, welcome!

The workaround provided by lavox also worked for me. In my app I'm using 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.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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