can you get more random?

Better l10n for Joomla

July 6th, 2014 Posted in geeky stuff, languages | No Comments »

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 :

  • Plugins like FaLang, jDiction which allow you to translate entire articles via a web interface. The problem with these plugins is that if an article contains html or javascript, this needs to copied into the translated version, thereby meaning 3 copies of code need to be managed,
  • Plugins like EasyLanguage and Multilanguages CK which allow you to tag strings for translation in templates, rather than translating entire files. However both these extensions require the translated text to be inserted directly into the source file.

I was looking for the following features :

  • ability to tag translatable strings, like Ruby’s <%=t :translate_me %>, Django’s {% trans “Translate me” %} or Symfony’s ,
  • an easy way to manage translation strings. to extract them for translation and integrate the translated text. My german isn’t up to the task, so someone else will be translating the site. I’ve got better things to do than cut-paste strings into a spreadsheet, then cut and paste the translations back.

Easylanguage seemed to be the most suitable (small codebase, well written, easy to understand code) so I spent a few hours yesterday adding my feature requests. It works in the following way :

  1. mark strings for translation in articles, categories, templates, menus, anywhere with the following syntax: {lang}translate me{/lang}. You can also leave the default easylanguage syntax: {lang fr}texte en français{/lang}{lang de}Satz in Deutsch{/lang} and this will be used if there is nothing in the translation file.
  2. Turn on automatic file creation.
  3. Browse your site – visit every page and the translation file is automatically created.
  4. Translate the strings in the file language/de-DE/de-DE.easylanguage.csv (or the intl of your choice)
  5. Turn off automatic file creation.
  6. That’s it.

You can download my updated version of the plugin here. It’s not prefect, but it suits my needs and it only took 2 hours. I’m posting this in the hope that it will be useful for someone else. If you have any comments or imporvements, let me know. Next feature request is the ability to manage the translation viles via the admin interface ;-)

plg_system_easylanguageplus-1.0_j25_30

Share

Learning portuguese : Day 1 – Pronunciation

September 4th, 2013 Posted in languages, portuguese | No Comments »

There are many different language learning strategies, but the one thing you’ll hear again and again is the importance of immersing yourself in the language. Obviously the best way to do this is to live in the country where your language is spoken, but if that’s not possible, listening to podcasts is the next best thing, as it will help you recognise the sound of the language and start to learn the pronunciation. Whilst learning German, I listened to the Tagesschau daily news podcast. The subjects aren’t always relevant, and you do end up learning a lot of words with limited daily use. Bundesregierung (federal government) and Verteidigungsministerium (defense department) are two that come immediately to mind. Despite this, actively listening to real German for 10 minutes every day helps you to rapidly increase your comprehension levels.

If you’re an intermediate or advanced level learner, you can find interesting podcasts in iTunes by changing your country in iStore and looking at the top podcasts for your country. You can do this by following the “Change Country” link at the bottom of the iTunes Store window.

As I’m starting from zero with Portuguese, Podcasts for native speakers will be less useful initially, so I’ve decided to start off with a few websites and podcasts aimed specifically at beginners. This will specifically help me to learn pronunciation basics as well as some basic vocabulary and phrases.

In the order I found them, I’ve looked at:

  • BBC Talk Portuguese – an on-line video Portuguese course for beginners. A series of 10 short clips with basic vocabulary and phrases aimed at beginning language learners. You can listen to the pronunciation of each phrase and there are short descriptions of the main rules of pronunciations. Unfortunately the full HD videos are only available in the UK, making this less useful for me. Each lesson takes under 5 minutes so I’ve decided to listen to a couple of these every day for the rest of the week. There is also a course for learners of Brazilian.
  • One Minute Portuguese – A series of 10 “supposedly” one-minute podcasts, purporting to teach you basic words and phrases to “impress your portuguese friends”. Each podcast actually lasts around 4 minutes and contains lots of superfluous english (“Let’s hear that again”, “One more time”, “Can you imagine how impressed your friends would be if you wished them ‘Happy birthday’ in Portuguese?”). Within the first 30 seconds of listening to this podcast I was already feeling frustrated and annoyed at my time being wasted. It could be useful for someone who has never learned a foreign language, someone lacking confidence in their language learning ability, or someone who wants to know a few basic words for use on holiday. I’ll listen to a couple of these every day too (if I can force myself to sit through them).

  • Brazilian pod class – as it’s name suggests, its for learning Brazilian. the podcasts are free but you need to pay for the learning guides. Each podcast lasts around 10 minutes and contains a real Portuguese conversation.

If you are an intermediate or advanced learner, you can try listening to Portuguese By SBS Radio, a portuguese language podcast created by SBS, an Australian broadcaster

So, for the next couple of days, I’ll be listening to a couple of these beginners podcasts every day. I’ve also completed DuoLingo level 2. I’m also going to start learning some vocabulary. More about that tomorrow. 39 days to go…

Share

September Challenge : Learn Portuguese

September 3rd, 2013 Posted in languages, portuguese | No Comments »

I’m going to be spending a long weekend in Lisbon in October and thought it would be interesting to see how much Portuguese I can learn in the next few weeks. I’ve been to Portugal several times before and each time I regret not being able to converse with the locals. After 2 weeks in the Azores a few years ago I managed to communicate using Spanish with (what was probably a rather bad approximation to a) Portuguese accent along with a few basic Portuguese words thrown in, but the result wasn’t pretty, although it got me a few smiles along the way.

Ok, so I’m not planning on becoming fluent in 5 weeks (well it would be nice, if a little unrealistic…). The idea is to try out various language learning sites, tools and methods and see what works for me. I’ll be spending an hour a day (if I can motivate myself) and reporting back here on my progress.

My first step was changing the language on my phone, which is always amusing. My phone has been in German for a while now, but I get the impression that I already understand more in Portuguese than I did with a German iPhone, after 2 years of learning German. Next step, basic vocabulary. I think I’ll start with DuoLingo, as I love their ‘Gamification’ of language learning.

40 hours to go…

Share

10 000 sentences, the easy way

June 7th, 2013 Posted in geeky stuff, languages | No Comments »

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 Anki, or SRS systems in general. I’ve got a german Anki deck that I’ve been building for the past year or so, although it hasn’t been updated in a while.

I was recently reading about 10 000 sentences. For me, it sounded like the quickest way to rapidly acquire new language skills. The only problem was finding a source of sentences. AJATT recommends building your deck from sentences you find while learning the language, and many people on the web warn against using someone else’s deck.

When I found out about Tatoeba, I realised that it would be possible to quickly build a personalised deck using sentences of your choice. TaToTen.com is the result.

The idea is to choose sentences that you think will be useful, rather then downloading a bunch of random sentences. One (rather large) caveat is that there are many errors in the Tatoeba corpus, so you shouldn’t blindly trust the translations.

My todo list for the site contains the following items (at the moment) :

  • Search functionality to list sentences containing specific words
  • Ordering the sentences by quality or popularity so bad sentences will be less visible. If you have any ideas about how to do this, I’d love to hear them

If you have any other suggestions, let me know !

Share

Symfony i18n : dumping and loading translation strings

September 13th, 2012 Posted in geeky stuff | No Comments »

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.

You need to create the following two files: lib/tasks/sfI18nDumpTask.class.php

[php]

<?php
/*
* Current known limitations:
* – Can only works with the default "messages" catalogue
* – For file backends (XLIFF and gettext), it only saves/deletes strings in the "most global" file
*/

/**
* Dumps i18n strings from messages.xml files.
*
*/
class sfI18nDumpTask extends sfBaseTask
{
/**
* @see sfTask
*/
protected function configure()
{
$this->addArguments(array(
new sfCommandArgument(‘application’, sfCommandArgument::REQUIRED, ‘The application name’),
new sfCommandArgument(‘culture’, sfCommandArgument::REQUIRED, ‘The target culture’),
));

$this->addOptions(array(
new sfCommandOption(‘untranslated’, null, sfCommandOption::PARAMETER_NONE, ‘Output all new found strings’),
));

$this->namespace = ‘i18n’;
$this->name = ‘dump’;
$this->briefDescription = ‘dumps i18n strings from messages.xml files’;

$this->detailedDescription = <<<EOF
The [i18n:dump|INFO] task extracts i18n strings from your project files
for the given application and target culture:

[./symfony i18n:dump frontend fr|INFO]

By default, the task dumps all translations it found in the current project.

[./symfony i18n:dump frontend fr|INFO]

If you want to dump the untranslated strings, use the [--untranslated|COMMENT] option:

[./symfony i18n:dump --untranslated frontend fr|INFO]

EOF;
}

public function execute($arguments = array(), $options = array())
{
$this->logSection(‘i18n’, sprintf(‘dumping i18n strings for the "%s" application’, $arguments['application']));

// get i18n configuration from factories.yml
$config = sfFactoryConfigHandler::getConfiguration($this->configuration->getConfigPaths(‘config/factories.yml’));

$class = $config['i18n']['class'];
$params = $config['i18n']['param'];
unset($params['cache']);

$i18n = new $class($this->configuration, new sfNoCache(), $params);
$i18n->getMessageSource()->setCulture($arguments['culture']);
$i18n->getMessageSource()->load();

$messages = $i18n->getMessageSource()->read();

$count=0;
foreach ($messages as $catalogue => $translations) {
$this->logSection(‘i18n’, sprintf(‘found "%d" i18n strings’, count($translations)));
foreach ($translations as $key => $values) {
if ($options['untranslated'] && (” != $values[0])) {
continue;
}
$count++;
$source = str_replace(‘"’, ‘""’, $key);
$translation = str_replace(‘"’, ‘""’, $values[0]);
print "$values[1]|\"$arguments[culture]\"|\"$source\"|\"$translation\"\n";
}
}

$this->logSection(‘i18n’, sprintf(‘dumped "%d" i18n strings’, $count));

}
}

[/php]

and lib/task/sfI18nLoadTask.class.php

[php]

<?php

/*
* Current known limitations:
* – Can only works with the default "messages" catalogue
* – For file backends (XLIFF and gettext), it only saves/deletes strings in the "most global" file
*/

/**
* loads i18n strings from php files.
*
*/
class sfI18nLoadTask extends sfBaseTask
{
/**
* @see sfTask
*/
protected function configure()
{
$this->addArguments(array(
new sfCommandArgument(‘application’, sfCommandArgument::REQUIRED, ‘The application name’),
new sfCommandArgument(‘culture’, sfCommandArgument::REQUIRED, ‘The target culture’),
new sfCommandArgument(‘filename’, sfCommandArgument::REQUIRED, ‘The translation csv file’),
));

$this->addOptions(array(
new sfCommandOption(‘no-overwrite’, null, sfCommandOption::PARAMETER_NONE, ‘Dont overwrite existing translations’),
));

$this->namespace = ‘i18n’;
$this->name = ‘load’;
$this->briefDescription = ‘loads i18n strings from php files’;

$this->detailedDescription = <<<EOF
The [i18n:load|INFO] task loads i18n strings from your project files
for the given application and target culture:

[./symfony i18n:load frontend fr filename|INFO]

By default, the task will load all strings from the file
into the current project.

If you only want to load previously untranslated strings, use the [--no-overwrite|COMMENT] option:

[./symfony i18n:load --no-overwrite frontend fr filename|INFO]

EOF;
}

/**
* @see sfTask
*/
public function execute($arguments = array(), $options = array())
{
$this->logSection(‘i18n’, sprintf(‘loading i18n strings for the "%s" application’, $arguments['application']));

// get i18n configuration from factories.yml
$config = sfFactoryConfigHandler::getConfiguration($this->configuration->getConfigPaths(‘config/factories.yml’));

$class = $config['i18n']['class'];
$params = $config['i18n']['param'];
unset($params['cache']);

$i18n = new $class($this->configuration, new sfNoCache(), $params);
$i18n->getMessageSource()->setCulture($arguments['culture']);
$i18n->getMessageSource()->load();

$messageSource = $i18n->getMessageSource();
$messages = $messageSource->read();

if ($loaded_list = file($arguments['filename'])) {
foreach ($loaded_list as $line) {
$line = chop($line);
if (preg_match(‘/(\d+)\|"(.*)"\|"(.*)"\|"(.*)"/’, $line, $matches)) {
list($id, $culture, $source, $translation) = array($matches[1], $matches[2], $matches[3], $matches[4]);
if ($culture == $arguments['culture']) {
$messageSource->update($source, $translation, ”);
}
}
}
} else {
$this->logSection(‘i18n’, sprintf(‘Cant open file "%s"’, $arguments['filename']));
}

if ($options['no-overwrite'])
{
$this->logSection(‘i18n’, ‘saving only new i18n strings’);
} else {
}
$messageSource->save();

}
}

[/php]

Before dumping the new strings to a file, you should first add any new untranslated strings using the builtin symfony i18n:extract command: [bash] ./symfony i18n:extract –auto-save –display-new frontend <culture> [/bash] Then you’re ready to dump the new untranslated strings to a file : [bash] ./symfony i18n:dump frontend <culture> –untranslated > untranslated.csv [/bash] You can then import this file into your favourite spreadsheet program. In NeoOffice this is done by opening a fresh spreadsheet and importing the data via “Insert” > “Sheet from external file” and making sure to add pipe ‘|’ as field seperator. YMMV in your spreadsheet tool of choice. Once the translations have been added in the 4th column of the spreadsheet, save the document as a pipe separated csv file before using the following command to reload the translated strings: [bash] ./symfony i18n:dump frontend <culture> translated.csv [/bash]

Share

Word of the day : Hyperpolyglotist

April 12th, 2012 Posted in german, languages | No Comments »

Talking about language learning, as I was, I found an article on the BBC website about hyperpolyglotism. I was pretty happy with my acceptable french, moderate spanish and fairly miserable german until I saw that video.

Share

Learning German with Anki

April 12th, 2012 Posted in german, languages | 6 Comments »

I’ve been told by several people that German is an easy foreign language for English speakers to learn. My experience in the past few months leads me to believe otherwise. I always thought that German was a logical language where it was enough to follow the rules. Well that may be true, but there are hundreds of rules and as many exceptions.

Despite this, I haven’t been put off, and fairly early on I discovered Anki which is an incredible tool to help with learning vocabulary (Apparently this kind or tool is called an SRS or Spaced repetition system. Flashcards to you and I). Vocab learning was never my strong point, but Anki really helps. Whether I have 10 minutes on the U-Bahn or an hour in the evening, I can quickly assimilate a few dozen more words.

However the dearth of dictionary files was an initial problem, so I have created a beginners file from various sources, which may be of use to any other beginning German learners. Check out my English-German Anki deck. I’ve been adding to this file for the past few months, and I hope it is as error-free as possible, but if you do find any errors, please let me know and I’ll correct them.

I’ve also uploaded the file to Google docs, if anyone wants write access to modify/improve the data, let me know. I’ll update the anki file with the latest greatest version.

Share

Bordeaux restaurants

September 27th, 2010 Posted in food and drink | No Comments »

Sitting at home in Paris on a cold wet september night, those three weeks of holiday in August seem like a distant memory. We travelled from Paris to Bordeaux, visiting the surrounding area, then up into the Pyrennées for a few days in the mountains, before continuing down the catalan coast via Cadaques to Barcelona.

In that short time we discovered some incredible restaurants. If you’re in the area, here’s a summary of the best discoveries.

Bordeaux

Bordeaux is a city that has undergone a revolution in the past 10 years. Until the end of the ’90s the centre of the city had a dirty, dusty, polluted feel to it. Since the beginning of the new millenium however, it has been reborn, after the car was banished from the narrow streets of the centre and the exteriors of most of the buildings were given a good clean. Today the town is much more welcoming, if somewhat touristic.

If you’re in Bordeaux for a few days, try to visit some of the following restaurants:

  • Le petit commerce – situated in a tiny pedestrian steet between the Place st. Pierre and Place du Parlement, this bistrot-style restaurant is open for lunch and dinner throughout the week. The lunchtime menu is a bargain at 12 €. If the weather is good, try to arrive early to get a seat on the terrace.
  • For something a little more traditional, try Le plat a oreilles. This small family-run restaurant is somewhat out of place on Rue des Faussets amongst a bunch of mediocre ‘attrape-touriste’ restaurants. Open every evening, the menu at 25€ is great value. Everything (from the starter to the desert) is home-made. the house wine was respectable too and reasonably priced
  • I was a little dissapointed by le Bô Bar. After having read the review in Le guide du Fooding I was curious to discover their concept – the wine is served anonymously by the glass, with the only choice being between a light, medium, full-bodied red, or a fruity or dry white. No other clues are given as to the provenance of the wine. While all of the wines we tasted were wonderful, the food was a disapointment, I had the impression our meal was reheated in a microwave, the dry congealed rice was simply unappetizing.
  • On sunday morning, you can’t do better than Karl in Place du parlement. We arrived early and were lucky to get a seat in the sun on the terrace, but 1/2 hour later and people were queueing up to get a seat inside. An enourmous selection and huge portions, highly recommended

Its late so I’ll stop there. Tomorrow I’ll try and jot down some of the best restaurants in Arcachon, Saillagouse, Cadaques and Barcelona

Share

Symfony: extracting strings from 1.2 forms using i18n:extract

June 9th, 2010 Posted in geeky stuff | No Comments »

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)

Share

I18n of sfSimpleForumPlugin

January 19th, 2009 Posted in geeky stuff | No Comments »

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
Share