[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Localization in an application
From: |
Chris B. Vetter |
Subject: |
Re: Localization in an application |
Date: |
Mon, 29 Mar 2004 12:04:24 -0800 |
On Fri, 26 Mar 2004 21:19:32 -0700
Adam Fedor <fedor@doc.com> wrote:
> On Mar 25, 2004, at 4:49 PM, Chris B. Vetter wrote:
> > No, because this will set NSLanguages in NSGlobalDomain, not the
> > application's.
> Perhaps you'll have to write your own NSUserDefaults method to do it.
> I also think there is a bug in +[NSUserDefaults userLanguages] that
> doesn't properly get the languages if they have been updated.
The problem isn't with setting the language and store it in the user's
defaults.
NSUserDefaults+setUserLanguages: writes into NSGlobalDomain, and
therefor will affect all applications and tools -- that's not what I
want.
So, instead I use
NSArray *array = [NSArray arrayWithObject: @"SomeLanguage"];
[userDefaults setObject: array forKey: @"NSLanguages"];
to write to the application's domain. It works insofar, that upon
restart "SomeLanguage" will be used instead of the default language set
in NSGlobalDomain.
However, what I'm _really_ trying to figure out is, why the change of
the language doesn't take effect right away.
In theory, a
NSLog(@"--> %@", _(@"Foobar"));
after re-reading the userdefaults *should* 'translate' "Foobar" to the
new language -- but does not.
The problem seems to be in NSBundle. If you specify the table (file)
where to get the translation from:
NSString *table = nil;
table =
@"/path/to/Resources/English.lproj/Localizable.strings";
NSLog(@"English: %@",
[[NSBundle mainBundle] localizedStringForKey: @"Hide"
value: @""
table: table]);
table =
@"/path/to/Resources/German.lproj/Localizable.strings";
NSLog(@"German: %@",
[[NSBundle mainBundle] localizedStringForKey: @"Hide"
value: @""
table: table]);
and run the application with --GNU-Debug=NSBundle, I get
File NSBundle.m: 1517.
In [NSBundle -localizedStringForKey:value:table:]
Failed to locate strings file
/path/to/Resources/German.lproj/Localizable
File NSBundle.m: 1517.
In [NSBundle-localizedStringForKey:value:table:]
Failed to locate strings file
/path/to/Resources/English.lproj/Localizable
English: Hide
German: Hide
Why is it trying to read .../Localizable and not .../Localizable.strings
--
Chris