CakePHPã®l10nã¨phpã®setlocale()ããã¿åããªã件
setlocale()
ã§ãã±ã¼ã«ãè¨å®ããå¿
è¦ãåºãã®ã§ãCakePHPã®l10nã¨é£åããããã¨ãã¦ã¾ãããã ãæ®å¿µãªäºã«l10nã¨setlocale()
ãä¸æããã¿åããè¡ãè©°ã¾ãã¾ããã
ã¨ããããã®çµè«
l10nããã¯'ja'ã'jpn'ãåå¾ã§ãã¾ããsetlocale()
ã§ãã±ã¼ã«ãæ¥æ¬èªã«ããã«ã¯ã'ja_jp'ã'ja_jp.utf-8'ãæå®ããå¿
è¦ãããã¾ããã¤ã¾ããCakePHPãèªåå¤å¥ããCakePHPã®è¨å®ããã®ã¾ã¾ä½¿ã£ã¦ãsetlocale()
ã§phpã®ãã±ã¼ã«ãè¨å®ããäºã¯åºæ¥ãªãããã§ãã
æ¥æ¬èªã¯åºæ¬çã«æ¥æ¬ã§ãã使ããã¦ç¡ãã®ã§ãja_jpã¯åé·ã§ãCakePHPã§ã¯ç¥ããã¦ãæ§ã§ããéã«ä¾ãã°è±èªã§ã¯ãCakePHPã§ã'en_au'ã'en_bz'ãªã©10åã»ã©è¨å®ãç¨æããã¦ãã¾ãããªã®ã§ãæ¥æ¬èªã¨åãããã«å½åã³ã¼ãã®æ¹ãçç¥ãããè¨èªã®å ´åã«ãsetlocale()
ã«ä½¿ããªãã¨ããäºã«ãªãã¾ãã
CakePHPã®è¨èªè¨å®
CakePHPã¢ããªã§ã®è¨èªã¯ãåºæ¬çã«Configure::write('Config.language', 'ja');
ã®æ§ã«è¨å®ãã¾ãã'ja'ã¯ãã¡ããæ¥æ¬èªã§ãããè¨å®ã«ä½¿ããæååã¯l10n::__l10nCatalogã¨ããã¡ã³ãå¤æ°ã«å®ç¾©ããã¦ãã¾ãã
l10n::__l10nCatalogã«å®ç¾©ããã£ã¦ãè±èªãªã©è¤æ°ã®å½ã§ä½¿ãããå ´åã
'en-gb' => array('language' => 'English (British)', 'locale' => 'en_gb', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
https://github.com/cakephp/cakephp/blob/1.3.6/cake/libs/l10n.php#L224
Configure::write('Config.language', 'en-gb');
ã§è¨å®ãããã®è¨å®ãåæ ããã¾ãã'en-gb'ã¯è±èªã§ãããç¹ã«ã¤ã®ãªã¹è±èªãæãã¦ã¾ããCakePHPã§è¨èªãè¨å®ããã®ã¯ã大æµpoãã¡ã¤ã«ã§ã®ç¿»è¨³ã ã¨æãã¾ãããããã«ã¯'locale'ã'localeFallback'ã使ããã¾ãã
$l10n->languagePath = array('en_gb', 'eng');
ãã®æ§ã«'locale', 'localeFallback'ã®é çªã§languagePathã«è¨å®ããã¾ãããã®å ´åi18nã§ç¿»è¨³ããéãAPP/locale/en_gb/ã«poãã¡ã¤ã«ãããããã§ãã¯ããç¡ããã°APP/locale/eng/ãè¦ã«è¡ãäºã«ãªãã¾ããå ·ä½çã«ã¯https://github.com/cakephp/cakephp/blob/1.3.6/cake/libs/i18n.php#L284ãã®ãããã®ã³ã¼ãã§ãã
l10n::__l10nCatalogã«å®ç¾©ããã£ã¦ãæ¥æ¬èªãªã©å½å¥ã³ã¼ããçç¥ãããå ´åã
'ja' => array('language' => 'Japanese', 'locale' => 'jpn', 'localeFallback' => 'jpn', 'charset' => 'utf-8', 'direction' => 'ltr'),
https://github.com/cakephp/cakephp/blob/1.3.6/cake/libs/l10n.php#L276
Configure::write('Config.language', 'ja');
ã®å ´åã¯ããã®è¨å®ãl10nå
ã§ä½¿ãããããã«ãªãã¾ããåè¿°ã®éãæ¥æ¬èªã®å ´åãåºæ¬çã«æ¥æ¬ã§ã®ã¿ä½¿ãããè¨èªãªã®ã§ã'locale'ã¨'localeFallback'ã®ã©ã¡ãã'jpn'ãæå®ããã¦ãã¾ãã
$l10n->languagePath = array('jpn', 'jpn');
å½ç¶ãlanguagePathã«ã¯'jpn'ã ããå
¥ã£ã¦ãã¾ãã翻訳ã«é¢ãã¦ã¯APP/locale/jpn/ã§ãå¤åCakePHPã§ã®æ¨æºç*1ãªä½ç½®ã ã¨æãã¾ãããã¡ããã©ãããsetlocale()
ã¨åããªãé¨åã§ãã
l10n::__l10nCatalogã«å®ç¾©ãç¡ãå ´åã
$l10n->languagePath = array('ja_jp');
ä¾ãã°Configure::write('Config.language', 'ja_jp');
ãæå®ããããæå®ããæåããã®ã¾ã¾languagePathã«ãè¨å®ããã¾ããAPP/locale/ja_jp/ããã§ãã¯ããäºã«ãªãã¾ãããã®ä¾ã®å ´åãsetlocale()
ã«ã¯ä½¿ããè¨å®ã§ãããl10n::__l10nCatalogã«è¨å®ãç¡ãã®ã§'language'ã'locale'ã'charset'ãªã©ãè¨å®ããã¾ããã
l10n::__l10nCatalogã®ã«ã¿ãã°ã¨ã¯
- è¨èªã«å¯¾ããæ§ã ãªæ å ±ãä¿æãã¦ãã¾ãã
- ãªã¯ã¨ã¹ããããã®HTTP_ACCEPT_LANGUAGEããã¼ã«ãªã£ã¦ãã¾ããï¼æ¯ãåãã容æï¼
<?php // æ¥æ¬èªã®ä¾ 'ja' => array( 'language' => 'Japanese', // è¨èªã®ãã«ãã¼ã 'locale' => 'jpn', // setlocale()ãªã©ã«é©å¿ãããå°åå 'localeFallback' => 'jpn', // ä¸è¨ãåç § 'charset' => 'utf-8', // ãã®è¨èªã使ç¨ããéã«æ¨å¥¨ãããæåã¨ã³ã³ã¼ãã£ã³ã°ï¼èªä¿¡ãªãï¼ 'direction' => 'ltr' // æåã®æ¹åãltr(left to right)ã¨rtl(right to left)ã®ã©ã¡ãã ) ?>localeFallbackã§ãããfallbackã¨ã¯äºåã®ãã®ãã¨ãã£ãæå³åããæã¡ã¾ãã
ä¾ãã°è±èªã®å ´åãæ§ã ãªå°åã»å½ã§ä½¿ãããæ¹è¨ãå¤ç¨®å¤æ§ã«ãããã¾ããã
- locale => en_ca // ã«ããè±èª
- localeFallback => eng // ã«ããè±èªãè±èªï¼
ã¨ãã風ã«ãè±èªãªãã©ãã®å°åã»å½ã§ããengããäºåã¨ãã¦å©ç¨ã§ãããã¨ãã£ã風ã«ãªãã¾ãã
ã¤ã¾ãapp/locale/engã«è¨è¿°ãããã°ãå¤ç¨®å¤æ§ãªè±èªåã®å½ã»å°åã«é©å¿ã§ããã¨ãã£ããã¨ãå¯è½ã«ãªãã¾ãã
多言語化するときのConfig.languageの値 - 24時間CakePHP
ãã®ä»¶ã調ã¹ã¦ãéã®ç³¸å£ã«ãªã£ãã¨ã³ããªã§ãããã«ã¿ãã°ã«ã¤ãã¦è©³ããæ¸ãã¦ããã¾ããä»ã§ãæ°ã«ãªã£ã¦ãäºã¨ãã¦ã'locale' => 'jpn', // setlocale()ãªã©ã«é©å¿ãããå°ååãã¦ãããã©ããã£ã±ã'jpn'ã¯setlocale()
ã«ä½¿ããã¯ããªã®ããªï¼
setlocale()ã§ãã±ã¼ã«è¨å®ããéã®å¼æ°
<?php $locale = setlocale(LC_ALL, '0');var_dump($locale); //string(1) "C" $locale = setlocale(LC_ALL, 'jpn');var_dump($locale); //bool(false) $locale = setlocale(LC_ALL, 'jp');var_dump($locale); //bool(false) $locale = setlocale(LC_ALL, 'ja');var_dump($locale); //bool(false) $locale = setlocale(LC_ALL, 'ja_jp');var_dump($locale); //string(5) "ja_jp" $locale = setlocale(LC_ALL, 'ja_jp.utf-8');var_dump($locale); //string(11) "ja_jp.utf-8" $locale = setlocale(LC_ALL, 'jpn_jp');var_dump($locale); //bool(false) $locale = setlocale(LC_ALL, 'ja-jp');var_dump($locale); //bool(false)
CakePHPã§ã¯'locale'=>'jpn'
ã¨ãã¦ããããæåã¯ãããããã'jpn'ã§ãsetlocale()
ã§ãã±ã¼ã«ã®è¨å®ãåºæ¥ãã®ããã¨æããããããªãã¿ã¼ã³ã試ãã¦ã¿ã¾ãããçµæã¯ä¸è¨ã®éããããè¦ãå½å¥ã³ã¼ãä»ãã®ãã¿ã¼ã³ãããªãã¨è¨å®ã§ãã¾ããã§ããã
ã«ãã´ãªããã±ã¼ã«åã¯ã » RFC 1766 ã » ISO 639 ã«ããã¾ãã ãã±ã¼ã«ã®å½åæ¹å¼ã¯ãã·ã¹ãã ã«ãã£ã¦ç°ãªãã¾ãã
http://jp2.php.net/manual/ja/function.setlocale.php
setlocale()
ã®ããã¥ã¢ã«ãè¦ã¦ã¿ãã¨ãRFC 1766ãISO 639ãè¦ãã¨ããã¾ããISO 639ã¯è¨èªã®ç¥ç§°ã®è¦æ ¼ã§ã3æåã2æåã®ç¥ç§°ãå®ç¾©ããã¦ã¾ããja_jpã®æåã®jaã®é¨åã¯ãRFC 1766ã§ä¸æ¬¡è¨èªã¿ã°ã¨å¼ã°ãã¦ãã¦ãISO 639ã§è¦å®ããã2æåã®è¨èªã³ã¼ãã«ãªã£ã¦ããããã§ãããã®ã¾ã¾è§£éããã¨setlocale()
ã«'jpn'ã¯ä½¿ããªãã¨ããäºã«ãªãã¾ãã
ãªããã·ã¹ãã ã«ãã£ã¦ç°ãªãã¨ãæ¸ãã¦ããã®ã§ãæå¾ã®ç°å¢ã®éãMacã¨Linuxã§è©¦ãã¦ã¿ã¾ããããçµæã¯åãã§ããã
ãã¨ãsetlocale(LC_ALL, '0')
ã®æ§ã«å¼æ°'0'ã ã¨ããã±ã¼ã«è¨å®ã¯é©ç¨ããããåã«ç¾å¨ã®è¨å®ãè¿ããã¾ãã
Cè¨èªã ã¨
ããç¥ãã¾ããããCè¨èªã®æ¹ã ã¨setlocale(jpn) - Google 検索ãsetlocale(japanese) - Google 検索ã®æ§ãªæå®ãåºæ¥ãã¿ããã§ããphpã¯Cè¨èªã£ã½ãé¢æ°ãå¤ãã®ã§ãåãåãããã¦ãããã°è¯ããã§ããã©ã
CakePHPã®åé¡ï¼setlocale()ã®åé¡ï¼
翻訳ãã¡ã¤ã«ã®ç½®ãå ´æããen_gbãen_usã¨ã¯å¥ã«engã§çµ±ä¸ãããå ´åã¨ããã®ã¯ç¢ºãã«ãããããªã®ã§ãjpnã¨è¨ã£ã3æåã®ç¥ç§°ãå¿
è¦ãªãã ã¨ã¯æãã¾ããl10n::__l10nCatalogã«RFC 1766æºæ ãªå¤ãå¿
ãæãããã¨ããã¦ãããã°è¯ãã®ã«ããããã¯éã«phpã®setlocale()
ã'jpn'ã®æ§ãªå½¢ã§æå®ã§ããªãã®ãå¤ãªã®ããªï¼å人çã«ã¯CakePHPãRFC 1766ã«æºæ ãããã±ã¼ã«ãæ±ãããã«ãªã£ã¦æ¬²ããã§ãã
ç°å¢
Linux
ãµã¼ãã¼ | coreserver |
CakePHP | 1.3.6 |
php | 5.2.5 |
*1:pluginã«å«ã¾ãã翻訳ãã¡ã¤ã«ãjpnãæ³å®ãã¦ãã¨æãã