the bemused blog

can you get more random?

Category: geeky stuff

  • debugging ansible

    Posted in
    No comments on debugging ansible

    I’ve been playing with Ansible recently, and enjoying automating my server installs, after years of relying on home-made scripts (or worse).

    From time to time I need to find out why Ansible isn’t doing what I think it should be, and after using -vvvv verbose flag, my next step is running the generated ansible installation script manually on the server. I didn’t find this explained anywhere, so I’m documenting it here for future reference. (more…)

  • Email productivity with Spark and ActiveInbox

    I recently discovered Spark, and now use it along with ActiveInbox to effectively fight my way through the hundreds of emails I receive every day. If you haven’t tried either of these tools, I can recommend both of them.

    ActiveInbox uses GMail’s labels to convert your inbox into a GTD-style task manager, allowing you to quickly go through emails in your inbox, classifying them as Actions to do, or postponing them until a future date (amongst other actions). It means you don’t need to treat your inbox as a todo list, with emails backing up until you no longer have a clear view of awaiting tasks. Instead you can clearly see overdue actions and add tasks and events to your calendar.

    I discovered Spark with the release of version 2.0 of their app. Spark is an iOS email app that makes burning through your emails easy. Tasks like tagging, deleting, forwarding and archiving mails can be easily achieved by swiping directly on the mail, making it easy to treat emails rapidly.

    Unfortunately there is a compatibility problem with these tools – in their default state it isn’t possible to use them together.  (more…)

  • Better l10n for Joomla

    For the past couple of weeks I’ve been working on a site developed in Joomla. This wasn’t by choice, but it was a good chance to learn more about the CMS. The site is available in three languages so the question of content translation quickly came up.

    There are several Joomla Plugins for managing multi-lingual content available, but none of them fit our needs.

    The current available plugins can be broadly classified in 2 groups (more…)

  • 10 000 sentences, the easy way

    Apart from spending copious amounts of time learning Spanish German, I’ve also been researching the most effective methods for language learning. Meta-language learning, I guess.

    My first discovery was (more…)

  • Symfony i18n : dumping and loading translation strings

    I’ve been meaning to write about this for literally years, but never got round to it. Hopefully this will be useful to someone. After an only partially sucessful attempt to manage symfony i18n strings in a MySQL DB, I finally gave up and reverted back to the default XLIFF file method. One of the reasons for initially wanting to store the translations in a DB was to build an easy to use interface to allow translators to easily find untranslated strings. Unfortunatley this didn’t work as well as I was hoping, and the alternatives (installing pootle, or getting translators to install and learn how to use an xliff tool) werent’ much better.

    I finally decided that the easiest way to update translations would be by dumping untranslated strings to a file before sending them to a translator. Unfortunately I couldn’t find a way to easily dump strings to a file and reload translated strings, so I wrote a couple of new tasks to do this for me.

    (more…)
  • Symfony: extracting strings from 1.2 forms using i18n:extract

    Anyone using Sympfony 1.2 will probably have realised by now that the i18n:extract task doesn’t extract strings from any files in lib/form/*

    This useful thread shows how to dump all translated strings into a file which can later be parsed by the i18n:extract task, unfortunately it creates huge files, and needs to be disabled in production environments for performance reasons.

    After a quick search through the code, I  have patched my code to only dump untranslated strings to the i18n.temp file.

    Here’s the patch for lib/vendor/symfony/lib/i18n/sfMessageFormat.class.php

    // found, but untranslated
     if (empty($target))
     {
    +          file_put_contents(sfConfig::get('sf_app_template_dir').'/i18n.temp.php',"<?php __('$string'); ?>\n",FILE_APPEND);
     return $this->postscript[0].$this->replaceArgs($string, $args).$this->postscript[1];
     }
     return $this->replaceArgs($target, $args);

    (I would have posted this in reply to the original comment, but I couldn’t find the original post for some reason)

  • I18n of sfSimpleForumPlugin

    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 :

    sfSimpleForumCategory:
      c1:
        name:        Public Boards
        description: We talk about stuff here.
        rank:        1
        culture:     en_GB
      c2:
        name:        Miscellaneous
        description: Secret matters
        rank:        2
        culture:     en_GB
      c3:
        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(sfSimpleForumCategoryPeer::RANK);
      $c->addAscendingOrderByColumn(self::RANK);return self::doSelectJoinCategoryLeftJoinPost($c);
    }

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

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

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

    < ?php
    use_helper('Utils');
    $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))
    {
    unset($cultures[$key]);
    }
    }
    }
    asort($cultures);
    $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
  • Test from phone

    Posted in
    No comments on Test from phone

    Not much to say, the clue is in the title ;)

  • Symfony and i18n – site interface translation

    UPDATE: I’ve packaged up the files into a plugin, which can be found here.

    I’ve been playing around with Symfony recently, with some interesting results.
    One frustrations for me was the lack of documentation explaining how to store translations in a database. While symfony provides a way to localise records in the DB, the default method of using XLIFF files for site translation seemed more complicated than necessary.
    As I couldnt find any information about implementing a admin interface to manage site translations, I’ve implemented this myself, what follows is a description of the steps to do this. If there are better ways to do this, I’d love to know, I’m new to symfony, so still learning.

    Here are the steps to add a admin interface to manage site interface translations.
    (more…)

  • is this page in france?

    This is of no interest for anyone except me, check out this HanhonZendcomlane