Re: objectForKey crashes for string formats
Re: objectForKey crashes for string formats
- Subject: Re: objectForKey crashes for string formats
- From: Lorenzo <email@hidden>
- Date: Thu, 22 May 2003 16:03:54 +0200
Hi,
also I discover the error I made.
I used an AppleScript to collect every string in my code file.m I wanted to
translate. So I put the original Cocoa strings inside the keys of the
dictionary.
So e.g. the NSString
@"Do you want to \"run\"?"
appeared in the key as
Do you want to \"run\"?
Instead I should have changed the key inside the dictionary to
Do you want to "run"?
That's the reason why I was not able to find this key anymore.
I presume that the sequence %@ failed for the same reason.
Thank you.
Best Regards
--
Lorenzo
email: email@hidden
>
From: Darkshadow <email@hidden>
>
Date: Thu, 22 May 2003 08:24:16 -0400
>
To: email@hidden
>
Cc: Lorenzo <email@hidden>
>
Subject: Re: objectForKey crashes for string formats
>
>
Well, I'm not sure about the carriage return (\r) - NSDictionary might
>
not be able to handle keys with line breaks. Not sure on the %@,
>
either. It shouldn't be thinking that it's a format string...
>
>
One big question though - why are you handling the NSLocalized.strings
>
file with a dictionary? There's actually a function that will grab a
>
localized string for you without having to init a dictionary for it.
>
NSLocalizedString(@"string to be localized", @"comment") (that second
>
option is actually not used - you can safely pass it nil). It's a kind
>
of shortcut on NSBundle's localizedStringForKey:value:table:
>
>
So if you passed it NSLocalizedString(@"Registration:",nil), it would
>
return "Enregistrement:" (if the language was set to French, of course).
>
>
Easier than having to alloc a dictionary for it. ;)
>
>
I don't know if that function will handle \r or %@ any better than the
>
NSDictionary does, though.
>
>
Darkshadow
>
>
>
On Thursday, May 22, 2003, at 04:42 AM, Lorenzo wrote:
>
>
> Hi,
>
> thank you for replying. I explain better.
>
> I have a NSDictionary (plist) file called "Localizable.strings" which
>
> contains many objects (sentences). I have this file in each of the
>
> language
>
> folders (e.g. English.lproj, French.lproj, ...).
>
> I load the "Localizable.strings" at the launch time from the proper
>
> folder
>
> regarding the current system language.
>
> For any object of the dictionary I search for the key (it's always in
>
> english) and I get the binded translated string.
>
>
>
> So If I have to show a string to the user I do:
>
>
>
> [self GLS:@"Registration:"]
>
>
>
> and the routine I call is:
>
>
>
> //////////////////////////////////////////////
>
> - (NSString*)GLS:(NSString*)originalString
>
> {
>
> NSString *foundString;
>
>
>
> if(!theString) return @"";
>
>
>
> foundString = [gLanguageStringsDict objectForKey:originalString];
>
>
>
> if([foundString isEqualToString:@""]) return originalString;
>
> if(foundString == nil) return originalString;
>
>
>
> return foundString;
>
> }
>
> //////////////////////////////////////////////
>
>
>
> So, if I earlier loaded the file "Localizable.strings"
>
> from the folder "French.lproj",
>
> I search for "Registration:" and I get "Enregistrement:".
>
>
>
> But I cannot yet search for strings containing \r and %@
>
> So I should workaround this problem.
>
> I am going to take a look at the link you gave me. Thank you.
>
>
>
> Best Regards
>
> --
>
> Lorenzo
>
> email: email@hidden
>
>
>
>> From: Chuck Soper <email@hidden>
>
>> Date: Thu, 22 May 2003 01:16:24 -0700
>
>> To: Lorenzo <email@hidden>, <email@hidden>
>
>> Subject: Re: objectForKey crashes for string formats
>
>>
>
>> I believe that the @"string" directive creates an instance of
>
>> NSConstantString.
>
>> I don't know why \r and %@ is causing a problem.
>
>>
>
>> Shouldn't you use strings files for localization? Or do you have a
>
>> special circumstance?
>
>> http://developer.apple.com/techpubs/macosx/Cocoa/TasksAndConcepts/
>
>> ProgrammingT
>
>> opics/Internationalization/Concepts/StringsFiles.html
>
>>
>
>> Chuck
>
>>
>
>>
>
>> At 9:35 AM +0200 5/22/03, Lorenzo wrote:
>
>>> Hi,
>
>>> I use a NSDictionary to localize my software in different languages.
>
>>> I have just discovered that if I try to get from a NSDictionary
>
>>>
>
>>> theKey = @"Cannot save the file:\r%@";
>
>>> foundString = [gLanguageStringsDict objectForKey:theKey];
>
>>> my application crashes if the key is in the dictionary.
>
>>>
>
>>>
>
>>> And if the key is only:
>
>>> theKey = @"Cannot save the file:\r";
>
>>> objectForKey returns nil even if the key is in the dictionary.
>
>>>
>
>>>
>
>>> And if the key is:
>
>>> theKey = @"Cannot save the file:";
>
>>> objectForKey finds the key and returns the string properly.
>
>>>
>
>>> So, cannot I really use those characters \r and %@ ?
>
>>> Is it a NSDictionary's bug?
>
>>> Is it my fault?
>
>>>
>
>>>
>
>>> Best Regards
>
>>> --
>
>>> Lorenzo
>
>>> email: email@hidden
>
> _______________________________________________
>
> cocoa-dev mailing list | email@hidden
>
> Help/Unsubscribe/Archives:
>
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
> Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.