On Dec 21, 2009, at 8:18 PM, Uli Kusterer wrote:
> On 20.12.2009, at 21:30, Ricky Sharp wrote:
>> Thus, I'm wondering if it would ultimately be worth it to externalize all 
>> strings from my nibs and just put everything in my single .strings file.  
>> This will clearly involve me adding tons of IBOutlet ivars just so that at 
>> runtime I can set their text with NSLocalizedString APIs.
> 
> One approach to avoid the whole IBOutlet excess would be to create subclasses 
> of the standard view classes which, when they are loaded, use their 
> contents/title as the key and pass it to NSLocalizedString(). That way, your 
> NIBs only contain keys, and the .strings files can hold the actual strings, 
> including comments.

Another possibility: instead of creating a bunch of subclasses and having to 
specify that subclass for each view you create in IB, you could write a method 
that recurses through all views in a window.  Check each view for a "title" or 
"name" property (maybe "stringValue" too), and maybe use some convention like 
#TITLE# to indicate you want to replace that title or name with a localized 
string to be gotten via NSLocalizedString().  Check whether the view is a table 
view that displays column headers, and if so, iterate through its columns.  Do 
similar special-casing for tab views and segmented views and anything else that 
needs it.

This method could be in its own utility class, where it could be called by 
awakeFromNib.  Offhand I think this is how I would do it if I wanted to take 
the approach of putting keys in the nib.

--Andy

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to