Custom UILabel creation to avoid localization problems

427 views Asked by At

Dear programmers,

I am creating a customLabel class like below:

@interface CustomLabel : UILabel {
    NSString *customBundlePath;
}

@implementation CustomLabel

- (void)drawTextInRect:(CGRect)rect
{
   NSString *result=[self getLocalvalue:self.text];
   [result drawInRect:rect withFont:self.font];
}

-(void)awakeFromNib
{
  NSLog(@"%@",self.text);
}

-(NSString *)getLocalvalue:(NSString*)textTolocalize
{

  // some code
  return localizedText;
}

But my problem is, drawTextInRect method calling only once for a Label at the time of nib loading.

If view is Appearing again by popig, then which method will execute for every customLabel object ?

Please help me out. Thanks, in advance.

1

There are 1 answers

2
TigerCoding On

You don't need custom classes.

NSString *someTextString = NSLocalizedString(@"SomeText", @"Description of text for translators")
[myLabel setText:someTextString];

Then you can extract the strings from your files and provide proper localization texts.

A couple of useful links:

http://www.icanlocalize.com/site/tutorials/iphone-applications-localization-guide/

http://www.raywenderlich.com/2876/how-to-localize-an-iphone-app-tutorial