5

I'm using the new iOS functionnality to translate the storyboards (http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/RoadMapiOS/chapters/InternationalizeYourApp/InternationalizeYourApp/InternationalizeYourApp.html)

The problem with this solution, it does not work with my UILabel subclasses.

Here are the codes for my UILabel subclasses :

.h:

#import <UIKit/UIKit.h>
@interface LabelThinText : UILabel
- (void)awakeFromNib;
-(id)initWithFrame:(CGRect)frame;
@end

.m :

@implementation LabelThinText

- (void)awakeFromNib
{
    [super awakeFromNib];
    [self setFont:[UIFont fontWithName:@"Raleway-Light" size:[[self font] pointSize]]];
}

-(id)initWithFrame:(CGRect)frame
{
    id result = [super initWithFrame:frame];
    if (result) {
        [self setFont:[UIFont fontWithName:@"Raleway-Light" size:[[self font] pointSize]]];
    }
    return result;
}

@end    

I guess i'm missing something to get the automatic translations from my Storyboard.strings file.

Anyone has an idea ?

Thanks !

Arnaud
  • 955
  • 1
  • 6
  • 15
  • You may download my test project : https://github.com/arn00s/iOS_BaseLocalization Just switch the device lang from EN to FR, and you'll see the differences. – Arnaud Jun 05 '13 at 12:33

3 Answers3

1

I ran into the same problem, and for the same reason, setting a custom font in a label. My strategy was a little more general, though. My custom font is Helvetica-like, so I used Helvetica Neue in IB as a placeholder font. The UILabel subclass translated that to my custom font, preserving font size and weight, so I could control all that through IB.

That made my workaround for the translation bug (I assume it's a bug) easier. I traverse all my views recursively in viewDidLoad, and map all UILabel fonts if they match the placeholder font, and the same for UIButton in my case.

Have you filed a bug?

JLundell
  • 1,580
  • 11
  • 14
  • 1
    I didn't filed a bug, but I requested a Technical Support from Apple. They told me they have to look in detail with an engineer (1 month ago). Still waiting for a reply... – Arnaud Jul 01 '13 at 13:37
  • 3
    I'm having a similar issue. Please update when you hear from Apple. – Michael Mangold Aug 23 '13 at 22:41
  • Still broken. Curiously, it works in Xcode builds to attached devices, including the simulator. But distributed builds don't localize. – JLundell May 16 '14 at 01:54
1

Encountered the same problem, here's how I got around it:

Drop your custom class, and create a category on UILabel, in your case UILabel+ThinText:

- (void) setThinText:(BOOL)thinText
{
    if (thinText) {
        [self setFont:[UIFont fontWithName:@"Raleway-Light" size:[[self font] pointSize]]];
    }
}

In your storyboard, select your label, choose the Identity Inspector and add the following User Defined Runtime Attribute:

Keypath: thinText – Type: Boolean – Value: checked

Stephane JAIS
  • 1,413
  • 15
  • 14
0

I got this issue too. I solve it setting the custom font in each ViewController. Let me show you an example:

 CustomViewController.h
@interface CustonViewController

@property (strong, nonatomic) IBOutlet UILabel* someLabel;

@end

The in CustomViewController.m

- (void)viewDidLoad
{
  [self setUoFonts];
}

- (void)setUpFonts
{
    self.someLabel.font = [UIFont fontWithName:@"AmaticSC-Regular" size:self.someLabel.font.pointSize];  
}

And that's it!. You're going to have your translation and your custom font.

Remember to remove the custom class from StoryBoard.

Gabriel Goncalves
  • 5,132
  • 3
  • 25
  • 34