genstrings with NSString variables

Ali Ozer aozer at apple.com
Sun Sep 10 00:09:26 PDT 2006


> Now I'm more confused, because "URL1" etc. is working just fine  
> (with just an English localization). (I've been maintaining  
> Localizable.strings by hand during most of the development, which  
> apparently isn't the optimal approach.)

That's because the URL1, URL2, etc are properly looked up at runtime.  
The problem is that genstrings cannot generate a strings file,  
because it does not know the static string to write out.

You can put dummy NSLocalizedString entries in comments for  
genstrings to parse and use. For instance TextEdit's  
ScalingScrollView.m has:

/* For genstrings:
     NSLocalizedStringFromTable(@"10%", @"ZoomValues", @"Zoom popup  
entry")
     NSLocalizedStringFromTable(@"25%", @"ZoomValues", @"Zoom popup  
entry")
     NSLocalizedStringFromTable(@"50%", @"ZoomValues", @"Zoom popup  
entry")
     NSLocalizedStringFromTable(@"75%", @"ZoomValues", @"Zoom popup  
entry")
     NSLocalizedStringFromTable(@"100%", @"ZoomValues", @"Zoom popup  
entry")
     NSLocalizedStringFromTable(@"125%", @"ZoomValues", @"Zoom popup  
entry")
     NSLocalizedStringFromTable(@"150%", @"ZoomValues", @"Zoom popup  
entry")
     NSLocalizedStringFromTable(@"200%", @"ZoomValues", @"Zoom popup  
entry")
     NSLocalizedStringFromTable(@"400%", @"ZoomValues", @"Zoom popup  
entry")
     NSLocalizedStringFromTable(@"800%", @"ZoomValues", @"Zoom popup  
entry")
     NSLocalizedStringFromTable(@"1600%", @"ZoomValues", @"Zoom popup  
entry")
*/

because later in the code there is:

[_scalePopUpButton addItemWithTitle:NSLocalizedStringFromTable 
(_NSDefaultScaleMenuLabels[cnt], @"ZoomValues", nil)];

Ali



On Sep 9, 2006, at 4:24 PM, David Dunham wrote:

> On 9 Sep 2006, at 10:58, Chris Hanson wrote:
>
>>> I'm confused by your suggestion. I want the key URL1 to return a  
>>> different URL depending on localization (i.e. it should point to  
>>> a localized web page). Same for the key URL2, etc.
>>
>> This isn't something that genstrings will notice or that the  
>> NSLocalizedString macro will support.  The macro really expects to  
>> be passed a literal, because genstrings will take that literal and  
>> use it as a key in the generated strings file.
>>
>> On the plus side, this means it's easy to use a more mnemonic key  
>> than "URL1", "URL2", etc.
>
> Now I'm more confused, because "URL1" etc. is working just fine  
> (with just an English localization). (I've been maintaining  
> Localizable.strings by hand during most of the development, which  
> apparently isn't the optimal approach.)
>
> It's not a mnemonic key because it's hooked up in Interface Builder  
> -- there are a number of menu items, each using the same action,  
> distinguished by the menu item's tag.
>
> David Dunham     A Sharp, LLC
> Voice/Fax: 206 783 7404     http://a-sharp.com
> "People seem to misinterpret complexity as sophistication" --  
> Niklaus Wirth



More information about the MacOSX-dev mailing list