Xcode 11/iOS 13 Localization issue
Asked Answered
C

5

13

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.

Carpospore answered 12/9, 2019 at 11:41 Comment(3)
did you check it in xcode 11 with ios 12 device?Railroad
@Railroad Yes, both a iOS 12 simulator and a physical device..Carpospore
I can confirm that is happening to me.Chaw
C
11

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/

Carpospore answered 24/9, 2019 at 18:45 Comment(4)
It's Xcode, so what do you expect. This bug prevents me from releasing my update.Unship
@BrenoPrata exactly, and they released it with no workaround facepalmsGailgaile
Just downloaded xCode 11.1 - I am still having the same issue.Nonconcurrence
I'm using XCode 11.2.1 and this issue is still hereSteinmetz
T
8

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
}
Tareyn answered 16/9, 2019 at 14:47 Comment(5)
Thank you! Will have to use something like this if for some reason this new behavior is by design..Carpospore
Today's release... Xcode 11.2 Beta...still not fixed.Daylong
Nice workaround for one of the annoying problems that Apple introduced with iOS 13.Marola
I have many storyboard files, so I have replace the "Main" with something like this: let storyboardName = storyboard?.value(forKey: "name") as? StringCrossrefer
Yep, same issue here, running XCode 11.1Nomen
P
2

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!

Porphyry answered 23/9, 2019 at 13:23 Comment(1)
I don't have any better idea unfortunately this is really such!Chaw
B
1

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;
}
Bonhomie answered 5/10, 2019 at 21:46 Comment(1)
As I have two storyboards (iPhone & iPad) I replaced the explicit "Main" table with a storyboard derivation: NSString *localizedString = NSLocalizedStringFromTable(key, [self.storyboard valueForKey:@"name"], nil);Marola
C
0

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.

enter image description here

Chaw answered 8/11, 2019 at 10:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.