ios - Localising a UILabel with attributed string from a Storyboard -


i have uilabel text set "attributed" in storyboard. when generate main.strings file translating different language text label not appear.

i tried add manually entry main.strings file copying object id. tried setting "text" property , "attributedtext" property when run app translated string not used.

so, how localise uilabel set "attributed" on storyboard?

i ended solving combination of storyboard , code, using this answer reference.

to start with, attributed string used on storyboard applied 1.5 line spacing whole string, easier set text on code preserving storyboard's label formatting.

the storyboard contains uilabel text property set attributed , 1.5 line height multiple.

on view controller code have setupui method , outlet uilabel.

@interface myclass () @property (weak, nonatomic) iboutlet uilabel *alabel; @end  @implementation myclass - (void)setupui {     nsmutableattributedstring *attributedstring = [[nsmutableattributedstring alloc] initwithattributedstring:self.alabel.attributedtext];     [attributedstring.mutablestring setstring:nslocalizedstring(@"this label text should localisable.", "")];     self.alabel.attributedtext = attributedstring; } @end 

with above code, variable attributedstring stores formatting set on storyboard, when change attributedstring text don't have set formatting again. and, of, course, label text appears on localizable.strings when execute "export localizations" command.

this wouldn't work if attributedstring had different formatting internal substrings. in case formatting have set manually on code (or using rtf files suggested answer posted on comment jelly).


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -