• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: localizable strings file with macro
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: localizable strings file with macro


  • Subject: Re: localizable strings file with macro
  • From: Stephane Sudre <email@hidden>
  • Date: Tue, 4 Mar 2008 13:12:57 +0100


On 4 mars 08, at 11:27, Jean-Daniel Dupas wrote:


Le 4 mars 08 à 11:21, Stephane Sudre a écrit :


On 4 mars 08, at 10:28, Julien Jalon wrote:

1) Might not be a good idea to use CFStringGetCStringPtr as it might return
NULL2) kCFStringEncodingMacRoman is likely not a good choice as the
encoding, especially for localized strings


If I were you, I'd do something like (warning: Mail compiled code):
const char* MyGetLocalizedCString(CFStringRef string)
{
   // if you need to be thread safe, add proper locks around that
   static CFMutableDictionaryRef mapping = NULL;
   if(mapping == NULL) {
       mapping = CFDictionaryCreateMutable(NULL, 0,
&kCFTypeDictionaryKeyCallBacks, NULL);
   }

const char* result = (const char *)CFDictionaryGetValue(mapping,
string);
if(result == NULL) {
CFStringRef localizedString = CFCopyLocalizedStringFromTable(string,
CFSTR("LibraryLocalizable"), NULL);
result = (const char
*)malloc(CFStringGetMaximumSizeForEncoding(CFStringGetLength(localize dString),
kCFStringEncodingUTF8);
CFStringGetCString(localizedString, (char *)result, bufferSize,
kCFStringEncodingUTF8);
CFDictionarySetValue(mapping, string, result);

I'm not sure CFDictionarySetValue would accept a char *.

It accepts whatever you want. You just have to set the corresponding callback when you create it. As you can see here, this sample use NULL as Value CallBack, so it perfectly valid to set a char *.

You're right. It just seems strange from a memory management point of view.



_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


References: 
 >localizable strings file with macro (From: Mitchell Livingston <email@hidden>)
 >Re: localizable strings file with macro (From: "Julien Jalon" <email@hidden>)
 >Re: localizable strings file with macro (From: Stephane Sudre <email@hidden>)
 >Re: localizable strings file with macro (From: Jean-Daniel Dupas <email@hidden>)

  • Prev by Date: WebView searchFor
  • Next by Date: two table view selection problem
  • Previous by thread: Re: localizable strings file with macro
  • Next by thread: Re: Can CoreData return only unique results of an attribute - SOLVED
  • Index(es):
    • Date
    • Thread