Core Foundation: Locales: Working With Locales

·ÎÄÉÀÏ ´Ù·ç±â

·ÎÄÉÀÏÀº CFLocaleÀÇ ÀνºÅϽº·Î Ç¥ÇöµË´Ï´Ù. º¸Åë ÇöÀçÀÇ »ç¿ëÀÚ¸¦ À§Çؼ­ ·ÎÄÉÀÏ °´Ã¼¸¦ »ç¿ëÇÏÁö ¾î¶² ƯÁ¤ÇÑ ÇϳªÀÇ ·ÎÄÉÀÏÀ» À§Çؼ­ »ç¿ëÇÏÁø ¾Ê½À´Ï´Ù. ¶ÇÇÑ Æ÷¸ËÅÍ(formatter)°ú °°Àº ´Ù¸¥ °´Ã¼µé°ú ÇÔ²² »ç¿ëÀ» ÁÖ·Î ÇÕ´Ï´Ù. ·ÎÄÉÀÏ °´Ã¼µéÀº ÇöÀç´Â immutableÇÕ´Ï´Ù. ±×¸®°í ·ÎÄÉÀÏ°ú Preference ½Ã½ºÅÛ°£ÀÇ »óÈ£ °ü°è¸¦ ÀÌÇØÇÏ´Â °ÍÀÌ Áß¿äÇÕ´Ï´Ù.

Contents:

·ÎÄÉÀÏ °´Ã¼ »ý¼ºÇϱâ
ÇöÀç »ç¿ëÀÚÀÇ ·ÎÄÉÀÏ
·ÎÄÉÀÏ °´Ã¼ÀÇ À¯È¿±â°£
·ÎÄÉÀÏ °´Ã¼ »ç¿ëÇϱâ

·ÎÄÉÀÏ °´Ã¼ »ý¼ºÇϱâ

º¸Åë ÇöÀç »ç¿ëÀÚ¸¦ À§Çؼ­ Á¤º¸¸¦ Æ÷¸ËÇϰųª Çؼ®ÇÏ°í ½ÍÀ» °Ì´Ï´Ù. ±×·¯¹Ç·Î º¸Åë ±× »ç¿ëÀÚÀÇ ·ÎÄÉÀÏÀ» »ç¿ëÇÏ°Ô µÇ´Âµ¥, ±×°ÍÀº CFLocaleCopyCurrent¶ó´Â ÇÔ¼ö·Î ¾ï¼¼½ºÇÒ ¼ö ÀÖ½À´Ï´Ù. (“ÇöÀç »ç¿ëÀÚÀÇ ·ÎÄÉÀÏ”À» ÂüÁ¶ÇϽʽÿÀ.) ÇÏÁö¸¸ ¶§¶§·Î ƯÁ¤ ·ÎÄÉÀÏ¿¡ ¸ÂÃß¾îÁ® ÀÖ´Â Á¤º¸¸¦ »ç¿ëÀÚÀÇ ÇÁ¸®ÆÛ·±½º ¼¼Æÿ¡ °ü°è¾øÀÌ È­¸é¿¡ Ç¥½ÃÇÏ°í ½ÍÀ» °Ì´Ï´Ù.

ÀûÀýÇÑ ½Äº°ÀÚ¸¦ °¡Áö°íCFLocaleCreateÀ» È£ÃâÇϸé ƯÁ¤ ·ÎÄÉÀÏÀ» À§ÇÑ ·ÎÄÉÀÏ °´Ã¼¸¦ ¸¸µé ¼ö ÀÖ½À´Ï´Ù. (“·ÎÄÉÀÏ À̸§ ¸í¸í¹ý”À» ÂüÁ¶ÇϽʽÿÀ.)

CFStringRef localeIdent = CFSTR("fr_FR");
CFLocaleRef localeRef = CFLocaleCreate(kCFAllocatorDefault, localeIdent);
CFStringRef stringRef =
    CFLocaleCreateCanonicalLocaleIdentifierFromString(kCFAllocatorDefault,
    localeIdent)

¾î¶² ·ÎÄÉÀÏÀÇ ½Äº°ÀÚ¸¦ ÀûÀýÈ÷ Ç¥±âÇÏ°í ÀÖ´Ù´Â °ÍÀ» È®½ÇÈ÷ ¾Ë°í ½ÍÀ¸¸é ±× canonical Çü½ÄÀ» ¸¸µé±â À§ÇØ CFLocaleCreateCanonicalLocaleIdentifierFromStringÀ» »ç¿ëÇØ¾ß ÇÕ´Ï´Ù. ÀÌ ÇÔ¼ö´Â ƯÈ÷ ±¸Á¤º¸¸¦ ´Ù·ê ¶§ À¯¿ëÇÕ´Ï´Ù.

CFStringRef localeIdent = CFSTR("French");
CFStringRef stringRef =
    CFLocaleCreateCanonicalLocaleIdentifierFromString(kCFAllocatorDefault,
    localeIdent);
CFLocaleRef localeRef = CFLocaleCreate(kCFAllocatorDefault, stringRef);

ÁöÁ¤ÇØÁØ ·ÎÄÉÀÏ¿¡ ´ëÇÑ Á¤º¸°¡ ²À ÀÖÀ¸¶õ ¹ýÀº ¾ø½À´Ï´Ù. ´ÙÀ½ÀÇ ¿¹´Â Á¦´ë·Î µÈ ·ÎÄÉÀÏ °´Ã¼¸¦ ¸¸µå´Â °ÍÀ» º¸¿©ÁÝ´Ï´Ù. ³ª¶ó´Â ¹Ì±¹ÀÌ°í ¾ð¾î´Â ű¹¾îÀÎ °æ¿ìÀÔ´Ï´Ù. ÇÏÁö¸¸ MacOS X´Â ÀÌ ·ÎÄÉÀÏ¿¡ ´ëÇÑ Á¤º¸¸¦ µ¥ÀÌŸ¸¦ Á¦°øÇÏÁö ¾Ê±â¶§¹®¿¡, th (ű¹¾î)·Î ÀÏ´Ü Á¤ÇØÁö°í ±× ´ÙÀ½¿¡ ·çÆ® ·ÎÄÉÀÏ·Î Á¤ÇØÁú °ÍÀÔ´Ï´Ù. (“·ÎÄÉÀÏ °èÃþ ±¸Á¶”¸¦ ÂüÁ¶ÇϽʽÿÀ.)

CFStringRef localeIdent = CFSTR("th_US");
CFLocaleRef localeRef = CFLocaleCreate(kCFAllocatorDefault, localeIdent);

½Ã½ºÅÛÀÇ ±âº» ¼¼ÆÃÀº CFLocaleGetSystemÀ» ÀÌ¿ëÇÏ¸é ·çÆ® ·ÎÄÉÀϷκÎÅÍ ¾ò¾îÁú °ÍÀÔ´Ï´Ù. ÀÌ ÇÔ¼ö´Â ¸ðµç ·ÎÄÉÀϵéÀÇ ¸ðµç ¼¼Æÿ¡ ´ëÇÑ ±âº» °ªÀ» Á¦°øÇØÁÝ´Ï´Ù.( “·ÎÄÉÀÏ °èÃþ±¸Á¶”¸¦ ÂüÁ¶ÇϽʽÿÀ.)


ÇöÀç »ç¿ëÀÚ¸¦ À§ÇÑ ·ÎÄÉÀÏ

·ÎÄÉÀÏÀÌ ºñ·Ï ÁÖ¾îÁø ¾ð¾î³ª Áö¿ª¿¡ ´ëÇÑ ±âº»°ªÀ» Á¤ÇØÁÖ±ä ÇÏÁö¸¸, °¢ »ç¿ëÀÚµéÀº ÀÚ±â ÀڽŸ¸ÀÇ ¼¼ÆÃÀ» ¿øÇÒ ¼öµµ ÀÖ½À´Ï´Ù. ÀÌ »ç¿ëÀÚ ¼¼ÆÃÀº ¼±ÅÃµÈ ·ÎÄÉÀÏÀÇ °ªÀ» ¾þ¾î ¾²°Ô µË´Ï´Ù. MacOS X´Â »ç¿ëÀÚ°¡ ±âº»À¸·Î Á¤ÇÑ ½Ã½ºÅÛ ·ÎÄÉÀÏ ¼¼Æÿ¡ »ç¿ëÀÚ°¡ º¯°æÀ» °¡ÇÑ °Í±îÁö ´Ù ¹Ý¿µÇÑ ·ÎÄÉÀÏ °´Ã¼¸¦ Á¦°øÇØ ÁÝ´Ï´Ù. CFLocaleCopyCurrentÀ» »ç¿ëÇϸé ÇöÀç »ç¿ëÀÚ¸¦ À§ÇÑ ³í¸®Àû »ç¿ëÀÚ ·ÎÄÉÀÏÀ» ¾ï¼¼½º ÇÒ ¼ö ÀÖ½À´Ï´Ù.

ÇÑ »ç¿ëÀÚÀÇ ·ÎÄÉÀÏ¿¡ ÀÖ´Â ¼¼ÆÃÀº ½Ã½ºÅÛ ±âº»°ª°ú ´Ù¸¦ ¼ö ÀÖÁö¸¸, ±× µÎ ¼¼Æÿ¡ ´ëÇÑ ½Äº°ÀÚ´Â °°À» ¼öµµ ÀÖ½À´Ï´Ù. ¿¹¸¦µéÀÚ¸é ¾î¶² »ç¿ëÀÚ°¡ ¿µ±¹½Ä ¿µ¾î¸¦ ·©±ÍÁö ÇÁ¸®ÆÛ·±½º¿¡¼­ ¼±ÅÃÀ» ÇØ ³õ°í´Â ³¯Â¥³ª ½Ã°£ Æ÷¸ËÀº ÀÓÀÇ·Î º¯°æÇØ ³õÀ» ¼ö ÀÖ½À´Ï´Ù. ´ÙÀ½ ÄÚµå ¿¹Á¦´Â »ç¿ëÀÚ¿Í ½Ã½ºÅÛ ·ÎÄÉÀÏÀÇ Æ÷¸ËÅÍ°¡ ´Ù¸¦ ¶§µµ, ±× ·ÎÄÉÀÏÀÇ ½Äº°ÀÚ°¡ °°Àº °æ¿ì¸¦ º¸¿© ÁÝ´Ï´Ù.

systemLocaleRef = CFLocaleCreate(kCFAllocatorDefault, CFSTR("en_GB"));
// created "default" localeRef for "en_GB"
dateFormatter = CFDateFormatterCreate(kCFAllocatorDefault, systemLocaleRef, kCFDateFormatterLongStyle, kCFDateFormatterMediumStyle);
CFShow(CFDateFormatterGetFormat(dateFormatter));
// output "d MMMM yyyy HH:mm:ss"
userLocaleRef = CFLocaleCopyCurrent();
CFShow(CFLocaleGetIdentifier(userLocaleRef));
// output "en_GB"
dateFormatter = CFDateFormatterCreate(kCFAllocatorDefault, userLocaleRef, kCFDateFormatterLongStyle, kCFDateFormatterMediumStyle);
CFShow(CFDateFormatterGetFormat(dateFormatter));
// output “MMM’ ‘d’, ‘yyy h’:’mm’:’ss’ ‘a”

¸¸¾à ¾î¶² Áö¿ª¿¡ ´ëÇÑ ·ÎÄÉÀÏ °´Ã¼¸¦ ¸¸µé¾ú´Ù¸é, »ç¿ëÀÚ°¡ ±× Áö¿ªÀ» µðÆúÆ®·Î Á¤ÇØ ³õ°í ÀÚ½ÅÀÇ ÇÁ¸®ÆÛ·±½º ¼¼ÆÃÀ» ÇØ ³õ¾ÒÀ»Áö¶óµµ ±× Áö¿ª¿¡ ´ëÇÑ ±âº»°ªÀ» ¾ò°Ô µË´Ï´Ù. ¸¸¾à ±× »ç¿ëÀÚÀÇ ·ÎÄÉÀÏÀ» ¿øÇÑ´Ù¸é CFLocaleCopyCurrentÀ» »ç¿ëÇϽʽÿÀ.


·ÎÄÉÀÏ °´Ã¼ÀÇ À¯È¿±â°£

·ÎÄÉÀÏ °´Ã¼´Â ¾î¶² ƯÁ¤ ½Ã°£ÀÇ ¼¼ÆÃÀ» º¸¿©ÁÖ´Â °Í¿¡ ºÒ°ú ÇÕ´Ï´Ù. ½Ã½ºÅÛ ±âº» ·ÎÄÉÀÏ ¼¼ÆÃÀº OSÀÇ ¹öÁ¯¸¶´Ù ´Ù¸¦ ¼ö ÀÖ½À´Ï´Ù. (¿¹¸¦ µéÀÚ¸é ¿µ±¹ÀÇ È­Æó ±âÈ£´Â Á¶¸¸°£ £ ¿¡¼­ ¬§À¸·Î ¹Ù²ðÁöµµ ¸ð¸¨´Ï´Ù.) »ç¿ëÀÚÀÇ ·ÎÄÉÀÏÀº ±× »ç¿ëÀÚ°¡ ¹Ù²Ù±â·Î ÇÏ¸é ¾ðÁ¦µçÁö ¹Ù²ð ¼ö ÀÖ½À´Ï´Ù.

·ÎÄÉÀÏ °´Ã¼´Â ÇöÀç´Â immutableÇÏÁö¸¸ ¾ÕÀ¸·Î ¹ßÇ¥µÉ OS ¹öÁ¯¿¡¼­´Â ¾È±×·² ¼öµµ ÀÖ½À´Ï´Ù. ÀÌ·± immutable ·ÎÄÉÀÏ °´Ã¼¸¦ »ç¿ëÇÒ¶§´Â, ±âÁ¸ µ¥ÀÌÅÍ °´Ã¼ÀÇ immutable º¹»çº»À» ¿ì¼± ¸¸µç ÈÄ¿¡ °¡´ÉÇÑÇÑ ±×°ÍÀ» ¿À·¡ »ç¿ëÇÒ °Å¶ó´Â °ÍÀ» ¸íÈ®ÇÏ°Ô ÇÏ´Â Á¡ÀÌ ÁÁ½À´Ï´Ù.

CFLocaleCopyCurrent¸¦ ÀÌ¿ëÇؼ­ ¾ò¾î³½ °´Ã¼´Â »ç¿ëÀÚ°¡ ±×µéÀÇ ÇÁ¸®ÆÛ·±½º ¼¼ÆÃÀ» ¹Ù²Ü¶§¿¡µµ º¯°æµÇÁö ¾Ê½À´Ï´Ù. ´õ´õ±º´Ù³ª ±× °´Ã¼ ÀÚü´Â ·±Å¸ÀÓ ½Ã½ºÅÛ¿¡ ÀÇÇؼ­ ij½³µÉÁöµµ ¸ð¸¨´Ï´Ù. ±×·¯¹Ç·Î CFLocaleCopyCurrentÀ» ¿¬¼ÓÀûÀ¸·Î ºÎ¸£¸é ¾Æ¸¶ °°Àº °´Ã¼¸¦ ¾òÀ»¼öµµ ÀÖ½À´Ï´Ù. »ç¿ëÀÚ°¡ ÇÁ¸®ÆÛ·±½º ¼¼ÆÃÀ» ¹Ù²Ù¾ú´Âµ¥µµ ¸»ÀÔ´Ï´Ù. ¸¸¾à ·ÎÄÉÀÏ ¼¼ÆÃÀÌ »ç¿ëÀÚ ÇÁ¸®ÆÛ·±½º¿Í ÀÏÄ¡ÇÑ´Ù´Â °ÍÀ» È®½ÅÇÏ°í ½ÍÀ¸¸é ÇÁ¸®ÆÛ·±½º¸¦ ½ÌÅ©ÇÏ°í CFLocaleCopyCurrentÀ» ÀÌ¿ëÇؼ­ »õ·Î¿î °´Ã¼¸¦ ¾ò¾î¾ß ÇÕ´Ï´Ù.

¾ó¸¶³ª ÀÚÁÖ ÀÀ¿ëÇÁ·Î±×·¥ÀÌ ÇÁ¸®ÆÛ·±½º¸¦ ½ÌÅ©ÇÏ°í ·ÎÄÉÀÏ °´Ã¼¸¦ ´Ù½Ã °¡Á®¿ÃÁö´Â, »ç¿ëµÇ´Â ¿ÀÆÛ·¹À̼ÇÀÇ granulity¿Í ¾ó¸¶³ª ȯ°æÀÇ º¯°æ¿¡ »¡¸® »¡¸® ¿©·¯ºÐÀÇ ÀÀ¿ë ÇÁ·Î±×·¥ÀÌ ¹ÝÀÀÇϵµ·Ï ÇÒÁö¿¡ µû¶ó ´Þ¶óÁý´Ï´Ù. ¿¹¸¦µé¾î È­¸é¿¡ ÀÚ¸¦ Ç¥½ÃÇÏ´Â ±×·¡ÇÈ ÇÁ·Î±×·¥Àº ±× ÀÚÀÇ ´ÜÀ§¸¦ °¡´ÉÇÑÇÑ ÀÚÁÖ °»½ÅÇØÁà¾ß ÇÕ´Ï´Ù. ÇÏÁö¸¸ ¿À·¡ ½Ã°£ÀÌ Áö³ª¾ß °á°ú°¡ ³ª¿À´Â ¸®Æ÷Æ® °°Àº °æ¿ì´Â ±× ÀÛ¾÷À» Çϱ⠽ÃÀÛÇÒ ¶§¿¡ ·ÎÄÉÀÏÀ» ij½³ÇØ µÎ¾ú´Ù°¡ ³¯Â¥ Æ÷¸ËÀÌ ¹Ù²îÁö ¾Êµµ·Ï °è¼Ó ±× ·ÎÄÉÀÏ °´Ã¼¸¦ »ç¿ëÇÏ´Â °ÍÀÌ ´õ ³ªÀ» °Ì´Ï´Ù.


·ÎÄÉÀÏ °´Ã¼ »ç¿ëÇϱâ

·ÎÄÉÀÏÀº º¸Åë ´Ù¸¥ °´Ã¼, Áï Æ÷¸ËÅÍ°°Àº °´Ã¼µé°ú ÇÔ²² »ç¿ëµË´Ï´Ù. ´ÙÀ½ Äڵ忡¼­ ±×·± °ÍÀ» º¼ ¼ö ÀÖ½À´Ï´Ù.

userLocaleRef = CFLocaleCopyCurrent();
CFNumberFormatterRef numberFormatter = CFNumberFormatterCreate(kCFAllocatorDefault, userLocaleRef, kCFNumberFormatterDecimalStyle);

ÀÚ¸®±¸ºÐ Äĸ¶³ª ³¯Â¥ Æ÷¸ËÀ̳ª Ãø·®ÀÇ ´ÜÀ§¿Í °°Àº Á¤º¸¸¦ ·ÎÄÉÀÏ °´Ã¼¿¡¼­ »Ì¾Æ ³¾ ¼ö ÀÖ½À´Ï´Ù.

userLocaleRef = CFLocaleCopyCurrent();
stringRef = CFLocaleGetValue(localeRef, kCFLocaleDecimalSeparator);

ÇÏÁö¸¸ ¿ùÈ­¼ö¸ñ±ÝÅäÀÏ°ú °°Àº ³¯ÀÚ Çà·Ä Á¤º¸¸¦ ¾ò¾î³»±â À§Çؼ±, ÇÁ¸®ÆÛ·±½º ½Ã½ºÅÛÀ» ÀÌ¿ëÇÏ´Â ÆíÀÌ ´õ ½¬¿ï °Ì´Ï´Ù.

CFArrayRef arrayRef = CFPreferencesCopyAppValue((CFStringRef)NSWeekDayNameArray, kCFPreferencesCurrentApplication);





© 2004 Apple Computer, Inc. All Rights Reserved. (Last updated: 2003-09-25) ¹ø¿ª : ¹ÚÁ¾¾Ï (Translated by JongAm Park)