Re: Localizing NSString Literals
Re: Localizing NSString Literals
- Subject: Re: Localizing NSString Literals
- From: Julio Cesar Silva dos Santos <email@hidden>
- Date: Thu, 8 Jun 2006 09:20:26 -0300
You can use the #define preprocessor directive this way:
#define CONSTANT_FOO @"foo"
#define CONSTANT_BAR @"bar"
This can be done in your .h file if they are not going to change, but
if you want them to be localizable then you have to create a file
with a .strings extension this way:
Localizable.strings Content
MyFoo = "foo";
MyBar = "bar";
And load them this way:
NSString * localFoo = [[NSBundle mainBundle]
localizedStringForKey:@"MyFoo" value:@"" table:@"Localizable"];
NSString * localBar = [[NSBundle mainBundle]
localizedStringForKey:@"MyBar" value:@"" table:@"Localizable"];
To add localizations, select the file and click the Get Info button
on top of the window (or control-click the file and select Get Info)
and click the button 'Make file localizable'.
Julio Cesar Santos
email@hidden
eMac 1GHz ComboDrive
512MB RAM
Linux User #359973
On 08/06/2006, at 02:25, Ben Lachman wrote:
I have several dozen strings that are currently represented in my
app as NSString literals (ie., NSString ConstantFooString =
@"foo";). I want to localize these strings, which are used in
different places throughout my app. What is the best way to
localize this type of data? I've thought of dumping them into a
plist and localizing that. I also thought I might be able to
replace each literal with a marco along the lines of
#define ConstantFooString NSLocalizedString(@"foo", @"bar")
Any recommendations on how to go about this in a easily
maintainable and clean manner?
->Ben
--
The user's going to pick dancing pigs over security every time. —
Bruce Schneier
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden