{"id":51,"date":"2009-01-19T23:47:50","date_gmt":"2009-01-19T22:47:50","guid":{"rendered":"http:\/\/bemused.org\/blog\/?p=51"},"modified":"2010-07-25T13:54:39","modified_gmt":"2010-07-25T12:54:39","slug":"i18n-of-sfsimpleforumplugin","status":"publish","type":"post","link":"https:\/\/bemused.org\/blog\/2009\/01\/19\/i18n-of-sfsimpleforumplugin\/","title":{"rendered":"I18n of sfSimpleForumPlugin"},"content":{"rendered":"<p>The sfSimpleForum plugin is a great way to quickly add a forum to a site, but it doesn&#8217;t handle multi-lingual sites, so here are my notes on how to add this feature.<\/p>\n<p>1. Edit plugins\/sfSimpleForumPlugin\/config\/schema.yml, add the culture field to the   sf_simple_forum_category table :<\/p>\n<pre>lang:     { type: varchar, size: 7 }<\/pre>\n<p>My thinking is that only the categories need an added lang field, as all forums belong to a category, and all posts belong to a forum, so the language of a post is implicit in its forum and category. Note I&#8217;m using &#8216;lang&#8217; and not &#8216;culture&#8217; here, as culture seems to have a specific meaning in symfony, and is used when an object can exist with several cultures, so a category would exist in all languages.  However in this case, the french site could have a diferent set of categories to the english site, so it&#8217;s not appropriate to use the field name &#8216;culture&#8217;.<\/p>\n<p>2. Add culture to the test data :<\/p>\n<pre>sfSimpleForumCategory:\r\n  c1:\r\n    name:        Public Boards\r\n    description: We talk about stuff here.\r\n    rank:        1\r\n    culture:     en_GB\r\n  c2:\r\n    name:        Miscellaneous\r\n    description: Secret matters\r\n    rank:        2\r\n    culture:     en_GB\r\n  c3:\r\n    name:        Alleatoire\r\n    description: Les choses alleatoires\r\n    rank:        1\r\n    culture:     fr_FR<\/pre>\n<p>3. Select by culture when getting list of all categories in plugins\/sfSimpleForumPlugin\/lib\/model\/plugin\/PluginsfSimpleForumForumPeer.php:<\/p>\n<pre>public static function getAllOrderedByCategory()\r\n{\r\n\u00a0 $c = new Criteria();\r\n\u00a0 $c-&gt;addJoin(self::CATEGORY_ID, sfSimpleForumCategoryPeer::ID);\r\n\u00a0 $c-&gt;add(sfSimpleForumCategoryPeer::LANG, sfContext::getInstance()-&gt;getUser()-&gt;getCulture());\r\n\u00a0 $c-&gt;addAscendingOrderByColumn(sfSimpleForumCategoryPeer::RANK);\r\n  $c-&gt;addAscendingOrderByColumn(self::RANK);return self::doSelectJoinCategoryLeftJoinPost($c);\r\n}<\/pre>\n<p>4. Add culture to admin interface in plugins\/sfSimpleForumPlugin\/modules\/sfSimpleForumCategoryAdmin\/config\/generator.yml :<\/p>\n<pre>list:\r\n  title: Category Administration<\/pre>\n<pre>  display: [=name, description, rank, lang]\r\nedit:\r\n  title: Edit category \"%%name%%\"\r\n  display: [name, description, rank, _lang, _forums]<\/pre>\n<p>5. Add set_culture partial in plugins\/sfSimpleForumPlugin\/modules\/sfSimpleForumCategoryAdmin\/templates\/_lang.php :<\/p>\n<pre>&lt; ?php\r\nuse_helper('Utils');\r\n$cultures = array('en_GB' =&gt; 'English', 'fr_FR' =&gt; 'French', 'de_DE' =&gt; 'German');\r\necho select_culture_tag('sf_simple_forum_category[lang]', $sf_simple_forum_category-&gt;getLang(), $cultures, array('id' =&gt; 'lang'));<\/pre>\n<p>6. add select_culture_tag function in apps\/backend\/lib\/helper\/UtilsHelper.php :<\/p>\n<pre>function select_culture_tag($name, $selected = null, $cultures = array(), $options = array())\r\n{\r\n$c = new sfCultureInfo(sfContext::getInstance()-&gt;getUser()-&gt;getCulture());\r\nif (! is_array($cultures)) {\r\n$cultures = $c-&gt;getCultures();\r\n}<\/pre>\n<pre>if ($culture_option = _get_option($options, 'cultures'))\r\n{\r\nforeach ($cultures as $key =&gt; $value)\r\n{\r\nif (!in_array($key, $culture_option))\r\n{\r\nunset($cultures[$key]);\r\n}\r\n}\r\n}<\/pre>\n<pre>asort($cultures);<\/pre>\n<pre>$option_tags = options_for_select($cultures, $selected);<\/pre>\n<pre>return select_tag($name, $option_tags, $options);\r\n}<\/pre>\n<p>7. Rebuild model and you&#8217;re good to go:<\/p>\n<pre>symfony propel:build-model<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The sfSimpleForum plugin is a great way to quickly add a forum to a site, but it doesn&#8217;t handle multi-lingual sites, so here are my notes on how to add this feature. 1. Edit plugins\/sfSimpleForumPlugin\/config\/schema.yml, add the culture field to the sf_simple_forum_category table : lang: { type: varchar, size: 7 } My thinking is that [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[26,24,23,22,25],"class_list":["post-51","post","type-post","status-publish","format-standard","hentry","category-geeky-stuff","tag-i18n","tag-l10n","tag-plugin","tag-sfsimpleforumplugin","tag-symfony"],"_links":{"self":[{"href":"https:\/\/bemused.org\/blog\/wp-json\/wp\/v2\/posts\/51","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bemused.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bemused.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bemused.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bemused.org\/blog\/wp-json\/wp\/v2\/comments?post=51"}],"version-history":[{"count":8,"href":"https:\/\/bemused.org\/blog\/wp-json\/wp\/v2\/posts\/51\/revisions"}],"predecessor-version":[{"id":96,"href":"https:\/\/bemused.org\/blog\/wp-json\/wp\/v2\/posts\/51\/revisions\/96"}],"wp:attachment":[{"href":"https:\/\/bemused.org\/blog\/wp-json\/wp\/v2\/media?parent=51"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bemused.org\/blog\/wp-json\/wp\/v2\/categories?post=51"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bemused.org\/blog\/wp-json\/wp\/v2\/tags?post=51"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}