{"id":922,"date":"2010-05-14T23:08:24","date_gmt":"2010-05-14T14:08:24","guid":{"rendered":"http:\/\/www.kazu.tv\/blog\/?p=922"},"modified":"2010-05-14T23:08:24","modified_gmt":"2010-05-14T14:08:24","slug":"symfonyi18n","status":"publish","type":"post","link":"https:\/\/kazu.tv\/blog\/2010\/05\/14\/symfonyi18n\/","title":{"rendered":"symfony\u3067i18n"},"content":{"rendered":"<p>\u57fa\u672c\u7684\u306b\u306f\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306e<a target=\"_blank\" href=\"http:\/\/www.symfony-project.org\/jobeet\/1_4\/Doctrine\/en\/19\">i18n\u306e<\/a>\u306b\u6cbf\u3063\u3066\u3084\u3063\u305f\u3051\u3069\u3001\u3084\u308b\u9806\u756a\u306f\u82e5\u5e72\u5165\u308c\u66ff\u3048\u3066\u308b\u3002\u9593\u9055\u3044\u3068\u304b\u304c\u3042\u308c\u3070\u6307\u6458\u3057\u3066\u4e0b\u3055\u3044\u306a\u3002<\/p>\n<p>\u74b0\u5883\uff1asymfony 1.4.3<\/p>\n<h3>\u25a0settings.yml\u306e\u7de8\u96c6<\/h3>\n<p>settings.yml\u306b\u4ee5\u4e0b\u306e\u8a18\u8ff0\u3092\u3057\u3066i18n\u3092\u6709\u52b9\u306b\u3059\u308b\u3002<\/p>\n<pre class=\"brush: plain\">\nall:\n.settings:\ni18n: true<\/pre>\n<p>\u5f8c\u306f\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u306e&quot;culture&quot;\u3092ja_JP\u306b\u8a2d\u5b9a\u3002culture\u306flocale\u3068\u540c\u3058\u3088\u3046\u306a\u3082\u306e\u306a\u306e\u304b\u306a\u3002<\/p>\n<p>\uff085\/23\u8ffd\u8a18 \uff09\u3042\u3068\u3001i18n\u306e\u30d8\u30eb\u30d1\u30fc\u3092\u4f7f\u3046\u8a2d\u5b9a\u3092\u3057\u3066\u304a\u304f\u3068\u826f\u3044\uff08standard_helpers\u306e\u884c\uff09\u3002<\/p>\n<p>\u6700\u7d42\u7684\u306asettings.yml\u306e\u5909\u66f4\u70b9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<\/p>\n<pre class=\"brush: plain\">\nall:\n.settings:\ni18n: true\ndefault_culture: ja_JP\nstandard_helpers: [Partial, Cache, I18N]\n<\/pre>\n<p>charset\u3092utf-8\u306b\u8a2d\u5b9a\u3059\u308b\u3001\u3068\u3082\u66f8\u3044\u3066\u3042\u3063\u305f\u3051\u3069\u3001\u5225\u306b\u3084\u3089\u306a\u304f\u3066\u3082\u826f\u3055\u305d\u3046\u306a\u306e\u3067\u4eca\u306e\u3068\u3053\u308d\u653e\u7f6e\u4e2d\u3002&nbsp;<\/p>\n<p><!--more--><\/p>\n<h3>\u25a0myUser.class.php\u306b\u521d\u56de\u30a2\u30af\u30bb\u30b9\u304b\u3069\u3046\u304b\u3092\u8fd4\u3059\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0<\/h3>\n<p>myUser\u30af\u30e9\u30b9\u306b\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3002<\/p>\n<pre class=\"brush: php\">\nclass myUser extends sfGuardSecurityUser\n{\npublic function isFirstRequest($boolean = null)\n{\nif (is_null($boolean))\n{\nreturn $this-&gt;getAttribute('first_request', true);\n}\n$this-&gt;setAttribute('first_request', $boolean);\n}\n}<\/pre>\n<p>\u203b\u81ea\u5206\u306e\u5834\u5408sfDoctrineSecurityPlugin\u3092\u4f7f\u3063\u3066\u308b\u306e\u3067\u3001\u7d99\u627f\u5143\u304csfGuardSecurityUser\u306b\u306a\u3063\u3066\u3044\u308b\u3051\u3069\u6c17\u306b\u3057\u306a\u3044\u3002<\/p>\n<p>\u25a0routing.yml\u3092\u4fee\u6b63\u3057\u3001&quot;ja&quot;\u4ed8\u304d\u3067\u30a2\u30af\u30bb\u30b9\u51fa\u6765\u308b\u3088\u3046\u306b\u3059\u308b<\/p>\n<p>&quot;homepage&quot;\u4ee5\u5916\u306e\u30a8\u30f3\u30c8\u30ea\u306b:sf_culture\u3092\u8ffd\u52a0\u3059\u308b\u3002\u3063\u3066\u66f8\u3044\u3066\u3082\u5206\u304b\u3089\u306a\u3044\u3068\u601d\u3046\u306e\u3067\u3001\u5177\u4f53\u4f8b\u3092\u3002<\/p>\n<pre class=\"brush: plain\">\nsettings:\nurl: \/settings\nparam: { module: sfApply, action: settings }<\/pre>\n<p>\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u4fee\u6b63\u3059\u308b\u3002\u3053\u308c\u3092routing.yml\u306e\u4e2d\u306ehomepage\u4ee5\u5916\u306e\u5168\u3066\u306e\u30a8\u30f3\u30c8\u30ea\uff08\u3068\u3044\u3063\u3066\u3082\u3001\u901a\u5e38\u306f\u305d\u308c\u7a0b\u6570\u304c\u591a\u304f\u306a\u3044\u306e\u3067\u306f\u306a\u3044\u304b\u3068\uff09\u306b\u5bfe\u3057\u3066\u884c\u3046\u3002<\/p>\n<pre class=\"brush: plain\">\nsettings:\nurl: \/:sf_culture\/settings\nparam: { module: sfApply, action: settings }<\/pre>\n<p>\u5f8c\u306f\u3001localized_homepage\u3068\u3044\u3046\u30a8\u30f3\u30c8\u30ea\u3082routing.yml\u306b\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"brush: plain\">\nlocalized_homepage:\nurl:   \/:sf_culture\/\nparam: { module: default, action: index }\nrequirements:\nsf_culture: (?:ja|en)<\/pre>\n<p>\u3061\u306a\u307f\u306b\u81ea\u5206\u306e\u5834\u5408homepage\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<\/p>\n<pre class=\"brush: plain\">\nhomepage:\nurl:   \/\nparam: { module: default, action: index }<\/pre>\n<p>\u25a0homepage\u3067\u8d77\u52d5\u3055\u308c\u308b\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u4fee\u6b63<\/p>\n<p>routing.yml\u306e&quot;homepage&quot;\u3067\u547c\u3073\u51fa\u3055\u308c\u308b\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4fee\u6b63\u3059\u308b\u3002\u81ea\u5206\u306e\u5834\u5408\u306fdefault\u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u3001\u547c\u3073\u51fa\u3055\u308c\u308b\u30a2\u30af\u30b7\u30e7\u30f3\u306findex\u3002<\/p>\n<p>\u5f93\u3063\u3066\u3001\u4fee\u6b63\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u306fapps\/xxxx\/modules\/default\/actions\/action.class.php\u3002\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u304c\u5b58\u5728\u3057\u306a\u3044\u5834\u5408\u306f\u3001symfony\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u30b3\u30d4\u30fc\u3057\u3066\u304d\u3066\u4fee\u6b63\u3059\u308b\u3002\u81ea\u5206\u306e\u74b0\u5883\uff08XAMP\uff09\u306e\u5834\u5408\u306f\u3001C:xamppphpPEARsymfonycontrollerdefaultactions\u306b\u5b58\u5728\u3059\u308b\u3002<\/p>\n<pre class=\"brush: php\">\npublic function executeIndex(sfWebRequest $request)\n{\nif (!$request-&gt;getParameter('sf_culture'))\n{\nif ($this-&gt;getUser()-&gt;isFirstRequest())\n{\n$culture = $request-&gt;getPreferredCulture(array('ja', 'en'));\n$this-&gt;getUser()-&gt;setCulture($culture);\n$this-&gt;getUser()-&gt;isFirstRequest(false);\n}\nelse\n{\n$culture = $this-&gt;getUser()-&gt;getCulture();\n}\n$this-&gt;redirect('localized_homepage');\n}\n}\n<\/pre>\n<p>\u25a0\u8a00\u8a9e\u5207\u66ff\u306e\u8ffd\u52a0<\/p>\n<p>\u8a00\u8a9e\u5207\u66ff\u306e\u30c9\u30ed\u30c3\u30d7\u30c0\u30a6\u30f3\u30ea\u30b9\u30c8\u3092\u8ffd\u52a0\u3059\u308b\u65b9\u6cd5\u306f\u3001\u57fa\u672c\u7684\u306b\u306f<a href=\"http:\/\/www.symfony-project.org\/jobeet\/1_4\/Doctrine\/en\/19\" target=\"_blank\">\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb<\/a>\u306e\u901a\u308a\u3002sfFormExtraPlugin\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3001language\u3068\u8a00\u3046\u540d\u524d\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f5c\u6210\u3057\u3066\u30fb\u30fb\u30fb\u3068\u3044\u3046\u65b9\u6cd5\u3060\u304c\u3001\u305d\u306e\u307e\u307e\u3084\u308b\u3068\u4ee5\u4e0b\u306e\u30a8\u30e9\u30fc\u3092\u51fa\u529b\u3059\u308b\u3002<\/p>\n<p>sfValidatorI18nChoiceLanguage does not support the following options: &#8216;culture&#8217;.<\/p>\n<p>\u3069\u3046\u3084\u3089\u30d7\u30e9\u30b0\u30a4\u30f3\u306e\u30d0\u30b0\u3063\u307d\u304f\u3066\u3001symfony\u306etrac\u306b\u3082\u30d0\u30b0\u3068\u3057\u3066\u767b\u9332\u3055\u308c\u3066\u3044\u308b\uff08<a href=\"http:\/\/trac.symfony-project.org\/ticket\/7797\" target=\"_blank\">&rarr;<\/a>\uff09\u3002\u89e3\u6c7a\u65b9\u6cd5\u306f\u305d\u3053\u306b\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u30d1\u30c3\u30c1\u3092\u9069\u7528\u3059\u308b\u3060\u3051\u3002\u3042\u308b\u3044\u306f\u30d5\u30a9\u30fc\u30e9\u30e0\u306e\u3053\u3063\u3061\u306e<a href=\"http:\/\/forum.symfony-project.org\/index.php\/m\/91907\/\" target=\"_blank\">\u66f8\u304d\u8fbc\u307f<\/a>\u306e\u65b9\u304c\u5206\u304b\u308a\u3084\u3059\u3044\u304b\u3082\u3002<\/p>\n<p>\u25a0\u30c6\u30ad\u30b9\u30c8\u306e\u7ffb\u8a33<\/p>\n<p>\u5f8c\u306f\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001apps\/frontend\/i18n\/ja\/\u306e\u4e0b\u306bmessages.xml\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u304c\u51fa\u6765\u308b\u3002<\/p>\n<pre class=\"brush: plain\">\n# symfony i18n:extract frontend ja --auto-save<\/pre>\n<p>\u3042\u3068\u306f\u3001\u305d\u308c\u3092\u7ffb\u8a33\u3002messages.xml\u306e\u4f8b\u3092\u4ee5\u4e0b\u306b\u793a\u3059\uff08\u629c\u7c8b\uff09\u3002<\/p>\n<pre class=\"brush: xml\">\n&lt;trans-unit id=&quot;3&quot;&gt;\n&lt;source&gt;Forgot your password?&lt;\/source&gt;\n&lt;target&gt;\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u5fd8\u308c\u305f\u5834\u5408\u306f\u3053\u3061\u3089\u3002&lt;\/target&gt;\n&lt;\/trans-unit&gt;\n<\/pre>\n<p>\u25a0\u304a\u308f\u308a<\/p>\n<p>\u3053\u308c\u3067\u5927\u4f53\u5b8c\u4e86\u3002\u9593\u9055\u3063\u3066\u3044\u308b\u6240\u3001\u305d\u306e\u4ed6\u306f\u968f\u6642\u52a0\u7b46\u4fee\u6b63\u4e88\u5b9a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u672c\u7684\u306b\u306f\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306ei18n\u306e\u306b\u6cbf\u3063\u3066\u3084\u3063\u305f\u3051\u3069\u3001\u3084\u308b\u9806\u756a\u306f\u82e5\u5e72\u5165\u308c\u66ff\u3048\u3066\u308b\u3002\u9593\u9055\u3044\u3068\u304b\u304c\u3042\u308c\u3070\u6307\u6458\u3057\u3066\u4e0b\u3055\u3044\u306a\u3002 \u74b0\u5883\uff1asymfony 1.4.3 \u25a0settings.yml\u306e\u7de8\u96c6 settings.yml\u306b\u4ee5\u4e0b&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[401],"tags":[704,442],"class_list":["post-922","post","type-post","status-publish","format-standard","hentry","category-php","tag-i18n","tag-symfony"],"_links":{"self":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/posts\/922","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/comments?post=922"}],"version-history":[{"count":0,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/posts\/922\/revisions"}],"wp:attachment":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/media?parent=922"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/categories?post=922"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/tags?post=922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}