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).
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:
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
How to Filter Firebase Data in Swift
How to Use Http Live Streaming Protocol in iPhone Sdk 3.0
Prevent Dispatch_After() Background Task from Being Executed
How to Only Disable Scroll in Scrollview But Not Content View
Block_Release Deallocating UI Objects on a Background Thread
Detect Touch on Child Node of Object in Spritekit
Delete App from Itunes Connect
Switui - Two Navigationlink in a List
Ui Testing Failure - Neither Element Nor Any Descendant Has Keyboard Focus on Securetextfield
How to Get the Rootviewcontroller from a Pushed Controller
Ckquery from Private Zone Returns Only First 100 Ckrecords from in Cloudkit
Avspeechsynthesizer Output as File
Differentiate Between Screen Lock and Home Button Press on iOS7
Error in Xcode 6 - View Controller Does Not Have an Outlet Named (Subview)
Adding Quartzcore to Xcode 4 for iOS
Enable and Debug Zombie Objects in iOS Using Xcode 5.1.1