can you get more random?

I18n of sfSimpleForumPlugin

January 19th, 2009 Posted in geeky stuff

The sfSimpleForum plugin is a great way to quickly add a forum to a site, but it doesn’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 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’m using ‘lang’ and not ‘culture’ 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’s not appropriate to use the field name ‘culture’.

2. Add culture to the test data :

    name:        Public Boards
    description: We talk about stuff here.
    rank:        1
    culture:     en_GB
    name:        Miscellaneous
    description: Secret matters
    rank:        2
    culture:     en_GB
    name:        Alleatoire
    description: Les choses alleatoires
    rank:        1
    culture:     fr_FR

3. Select by culture when getting list of all categories in plugins/sfSimpleForumPlugin/lib/model/plugin/PluginsfSimpleForumForumPeer.php:

public static function getAllOrderedByCategory()
  $c = new Criteria();
  $c->addJoin(self::CATEGORY_ID, sfSimpleForumCategoryPeer::ID);
  $c->add(sfSimpleForumCategoryPeer::LANG, sfContext::getInstance()->getUser()->getCulture());
  $c->addAscendingOrderByColumn(self::RANK);return self::doSelectJoinCategoryLeftJoinPost($c);

4. Add culture to admin interface in plugins/sfSimpleForumPlugin/modules/sfSimpleForumCategoryAdmin/config/generator.yml :

  title: Category Administration
  display: [=name, description, rank, lang]
  title: Edit category "%%name%%"
  display: [name, description, rank, _lang, _forums]

5. Add set_culture partial in plugins/sfSimpleForumPlugin/modules/sfSimpleForumCategoryAdmin/templates/_lang.php :

< ?php
$cultures = array('en_GB' => 'English', 'fr_FR' => 'French', 'de_DE' => 'German');
echo select_culture_tag('sf_simple_forum_category[lang]', $sf_simple_forum_category->getLang(), $cultures, array('id' => 'lang'));

6. add select_culture_tag function in apps/backend/lib/helper/UtilsHelper.php :

function select_culture_tag($name, $selected = null, $cultures = array(), $options = array())
$c = new sfCultureInfo(sfContext::getInstance()->getUser()->getCulture());
if (! is_array($cultures)) {
$cultures = $c->getCultures();
if ($culture_option = _get_option($options, 'cultures'))
foreach ($cultures as $key => $value)
if (!in_array($key, $culture_option))
$option_tags = options_for_select($cultures, $selected);
return select_tag($name, $option_tags, $options);

7. Rebuild model and you’re good to go:

symfony propel:build-model

Post a Comment