Marking Some Xib/Storyboard Strings as Not Localizable

Marking some XIB/Storyboard strings as not localizable

UPDATE:

Check out ReMafoX, it's a Mac app that perfectly solves your problem. It can be easily installed and integrated within your project, watch this video for a detailed walkthrough.

To ignore specific Strings, simply add one of the customizable ignore flags from the "Interface Builder" pane in the "Comment for Localizer" field in your Storyboard/XIB files and the build-script you configured following the above linked video will exclude it on next build of your project (or press of the "Update" button in the config).

Config Option, Interface Builder pane


OLD ANSWER:

This is now possible using the BartyCrouch command line utility which I recently wrote to solve this problem (see installation instructions in my answer on that thread).

BartyCrouch runs ibtool for you and does additional processing on top of its resulting .strings file. It will exclude views from translation if you include #bc-ignore! into your value or comment within your base internationalized Storyboard/XIB file.

Please check out out the related section within the README on GitHub for detailed information.

Swift: Localization in Storyboard - Labels not added to Main.strings?

After selecting UILabel from storyboard, You can find object id of UILabel in right panel:

enter image description here

Then you can set text of label as below in your Main.string file:

"sxl-NO-5WX.text" = "Phone";

Why is UILabel with attributed string from a Storyboard localization not supported?

Apple responded on the developer forum with

This is not currently supported in Storyboard/XIB. I would encourage you to make a request on Feedback Assistant.

and ended up using this approach, see below. I still hope Apple adds the reason behind this.

- (void)localizeAttributedLabel:(UILabel*)label withText:(NSString*)text
{
NSMutableAttributedString* attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:label.attributedText];
[attributedString.mutableString setString:text];
label.attributedText = attributedString;
}

[self localizeAttributedLabel:myLabel withText:NSLocalizedString(@"MyLabelTextKey", nil)];

Storyboard/XIB and localization best practice

For just changing text labels I did something like this

+(void) replaceTextWithLocalizedTextInSubviewsForView:(UIView*)view
{
for (UIView* v in view.subviews)
{
if (v.subviews.count > 0)
{
[self replaceTextWithLocalizedTextInSubviewsForView:v];
}

if ([v isKindOfClass:[UILabel class]])
{
UILabel* l = (UILabel*)v;
l.text = NSLocalizedString(l.text, nil);
[l sizeToFit];
}

if ([v isKindOfClass:[UIButton class]])
{
UIButton* b = (UIButton*)v;
[b setTitle:NSLocalizedString(b.titleLabel.text, nil) forState:UIControlStateNormal];
}
}
}

call this function in your viewDidLoad: like this:

[[self class] replaceTextWithLocalizedTextInSubviewsForView:self.view];

It saved me a lot of work declaring and connecting IBOutlets when all you want is localized labels.



Related Topics



Leave a reply



Submit