Showing posts with label howto. Show all posts
Showing posts with label howto. Show all posts

13 Jun 2012

Rails i18n translations in Yaml: translation tool support

With Rails 2.2 the i18n API was introduced with a new method for translations.  Instead of embracing the venerable gettext which had been the previous standard, the Rails team invented a new way using Yaml files.  The result is a particularly graceful, flexible and very Rubylike way of specifying translations.  It also is much more reliable than gettext, which had many inscrutable issues with locales and caching, and sometimes caused people to get things in the wrong language.  So: bravo, great job.

But to do this, they specified their own translation format, the very flexible Yaml file. There are already a lot of formats floating around, and translation tool vendors and open-source translation developers have been working for a long time on conversion tools between them.  The Translate Toolkit and Pootle emerged from South Africa (a country which groans beneath the weight revels in the glory of eleven official languages) which provide an excellent web-based tool for collaboration, centered around gettext PO files.  However, poor little Pootle started a migration from Python to Django, and we all know how rewrites go.  [Halfway. Badly.]  But Translate Toolkit supported a lot of formats:

  • moz2po - Mozilla .properties and .dtd converter. Works with Firefox and Thunderbird
  • oo2po - OpenOffice.org SDF converter (See also oo2xliff).
  • odf2xliff - Convert OpenDocument (ODF) documents to XLIFF and vice-versa.
  • prop2po - Java property file (.properties) converter
  • php2po - PHP localisable string arrays converter.
  • sub2po - Converter for various subtitle files
  • txt2po - Plain text to PO converter
  • po2wordfast - Wordfast Translation Memory converter
  • po2tmx - TMX (Translation Memory Exchange) converter
  • pot2po - initialise PO Template files for translation
  • csv2po - Comma Separated Value (CSV) converter. Useful for doing translations using a spreadsheet.
  • csv2tbx - Create TBX (TermBase eXchange) files from Comma Separated Value (CSV) files
  • html2po - HTML converter
  • ical2po - iCalendar file converter
  • ini2po - Windows INI file converter
  • json2po - JSON file converter
  • web2py2po - web2py translation to PO converter
  • rc2po - Windows Resource .rc (C++ Resource Compiler) converter
  • symb2po - Symbian-style translation to PO converter
  • tiki2po - TikiWiki language.php converter
  • ts2po - Qt Linguist .ts converter
  • xliff2po - XLIFF (XML Localisation Interchange File Format) converter

In its heels, Google introduced the Google Translate Toolkit, which lets you use the Google Translate engine to suggest translations (based on its own databases or translation memories you provide).  It also does the core of what Pootle does: collaboration, access, but without crashing and flakiness, and it works with:
But neither of them supports Yaml files.  Unfortunately, tooling support libraries have not embraced this format in the intervening two and a half years.  I did find one solution: i18n-translators-tools which supports conversion between Yaml and gettext PO files, but it's somewhat idiosyncratic, and it turns out there's a good reason why there isn't a straightforward Yaml  PO converter: the PO format is consists of name-value pairs with metadata, and the Yaml format is a tree.

English source Yaml fileSpanish Yaml file produced by i18n-translators-tools from a PO file
page_info:

  sales/credit_notes:

    date: "Date"

    title:

      default: "Sales Credit Note"

      new: "New Sales Credit Note"
page_info:
  sales/credit_notes:
    date: "Fecha"
    title:
      default:
        default: "Sales Credit Note"
        translation: "Crédito de venta"
      new:
        default: "New Sales Credit Note"
        translation: "New Sales Credit Note"


There are some interesting things going on here: the Spanish Yaml file provides fallbacks so untranslated strings don't come through as blank.  The intermediate gettext PO file keeps the tree structure in the msgctxt metadata, and looks like this:

msgctxt "page_info.fuji_sales/sales_credit_notes.title.default"
msgid "Sales Credit Note"
msgstr "Crédito de venta"

msgctxt "page_info.fuji_sales/sales_credit_notes.title.new"
msgid "New Sales Credit Note"
msgstr "New Sales Credit Note"

So it's possible to use Google Translate Toolkit to translate your Rails Yaml files, provided you use the i18n-translators-tools library to do the conversions, and configure your Rails applications to support fallbacks.


19 Aug 2008

Skating circuit around downtown Vancouver

This evening I did a circuit around downtown Vancouver on skates: 13km round trip from our place; it took me 75 minutes. The route is designed to avoid hills as much as possible: the only steep hill I couldn't avoid was the Main St. bridge.

I used the Google Distance Measurement Tool to create this map, but there was no way to save it.
Downtown Vancouver Skate Circuit: capture of Google Map

Street-by-street summary

Seymour St, Helmcken St. (future greenway!), Richards St, Beach Crescent, Seawall, Carrall St Greenway (beeyoutious!), E. Cordova St. (baaad neighbourhood), Main St (gorgeous view from the bridge, which has a steep decline for inline skates), Waterfront Rd. (which goes under the SeaBus bridge, Canada Place and annex), dive through a parking garage to get to the Coal Harbour Seawalk. At this point you can stay on the seawall, although I use the side streets (Cardero St, Bayshore Dr, Denman St.) because the paving stones are a little too bumpy for my taste. This takes you to Stanley Park. You can go around the Stanley Park Seawall, which is beautiful (another 9km), but I chose to take the bike trail through the Georgia St pedestrian tunnel and along the shore of Lost Lagoon, and follow the path though the bike tunnel under Stanley Park Dr. to Second Beach. From Second Beach the bike path is very narrow and shared with pedestrians, so look out... but continue along the (beautiful) seawall until the end of Sunset Beach where you reach the Vancouver Aquatic Centre. From there, I recommend taking Beach Ave back to Beach Crescent – which is a full loop.

14 Apr 2008

Fix slow Ubuntu shutdown with CIFS (SMBFS)

My Ubuntu machine at home always takes a bazillion years to turn off. I've been seeing this "Server not responding" error forever, but I've just ignored it. An explanation from the article "Five things to do on a freshly installed Ubuntu":

CIFS: Unmount CIFS shares before shutting down the network

There is a very nasty bug in Ubuntu, which occurs, if you use NetworkManager and have any active CIFS share while shutting down your system. If you do that, you'll experience a timeout while shutting down, lengthening it by ~30 seconds per share. You'll also get the message CIFS VFS: Server not responding.

There is a bug entry on launchpad, but it is not yet fixed. Fortunately, there is an easy workaround.

Here are my simplified instructions:
cd /etc/init.d
sudo wget http://www.jejik.com/files/examples/umountcifs
sudo chmod ugo+x umountcifs
sudo update-rc.d umountcifs stop 02 0 6 .
That ought to take care of it.

13 Apr 2008

Speech synthesis on Ubuntu

Text-to-speech (TTS) has been around for a couple of decades, and it keeps getting better. There are a bunch of really fun untapped applications for it, combining RSS, filters (like Pipes), podcasts, telephony, and hidden speakers.

Under Linux there is a nice package available called Festival. To get started, grab an appropriate package, such as:
  • festvox-hi-nsk (Hindi male)
  • festvox-kallpc16k (american English male)
  • festvox-rablpc16k (British English male)
  • festvox-mr-nsk (Marathi male)
  • festvox-suopuhe-lj Finnish female
  • festvox-suopuhe-mv (Finnish male)
  • festvox-te-nsk (Telugu male)
Too bad you can't get a female speaker except in Finnish. (I had never heard of the Indian languages Marathi and Telugu, and I consider myself a language buff... sigh.)

The results are pretty good. Here's how to use it from the command line:
text2wave text-file.txt -o audio-file.wav

For extra fun, use pidgin-festival to turn incoming instant messages into speech (use festival-gaim if you haven't made the jump to Hardy Heron yet).

29 Oct 2007

BlackBerry support in Ubuntu Gutsy

To charge or backup your BlackBerry device under Ubuntu Gutsy Gibbon, there is a nice little GPL package named barry put together by some nice folks in Ontario. It isn't part of the Ubuntu software catalog yet, so here are some steps to get this up and running. (Note: the authors give instructions on how to build it from source – take your pick.)

First, you'll need to install an updated version of libopensync0 (0.22). Add the following lines to your /etc/apt/sources.list:

#opensync
deb http://opensync.gforge.punktart.de/repo/opensync-0.21/ etch main
deb-src http://opensync.gforge.punktart.de/repo/opensync-0.21/ etch main
So, go get that along with some other prerequisites:

sudo apt-get update
sudo apt-get install libopensync0 libglademm-2.4-1c2a libtar
Then, download and install barry.

wget "http://downloads.sourceforge.net/barry/libbarry_0.9-1_i386.deb?modtime=1192146928&big_mirror=0"
wget "http://downloads.sourceforge.net/barry/barry-util_0.9-1_i386.deb?modtime=1192146873&big_mirror=0"
wget "http://downloads.sourceforge.net/barry/barrybackup-gui_0.9-1_i386.deb?modtime=1192146747&big_mirror=0"
wget "http://downloads.sourceforge.net/barry/libbarry-dev_0.9-1_i386.deb?modtime=1192146953&big_mirror=0"
wget "http://downloads.sourceforge.net/barry/libopensync-plugin-barry_0.9-1_i386.deb?modtime=1192147004&big_mirror=0"
sudo dpkg -i libbarry_0.9-1_i386.deb
sudo dpkg -i barry-util_0.9-1_i386.deb
sudo dpkg -i barrybackup-gui_0.9-1_i386.deb
sudo dpkg -i libbarry-dev_0.9-1_i386.deb
sudo dpkg -i libopensync-plugin-barry_0.9-1_i386.deb

Note: you probably don't need the libbarry-dev package unless you plan to develop with this stuff, but I installed it anyhow. Won't hurt anything. The libopensync package should enable some sort of integration with your local copy of Evolution or Thunderbird, but I haven't tried it.

After all you can plug your BlackBerry into the USB port and it will finally charge. These packages don't put any entries in the Gnome menu system, but you can run "barrybackup" which will let you back up all data (and restore, if you want).

17 Aug 2007

Building Pidgin on Ubuntu with all the fixin's

I had a heck of a time finding the packages I needed to install so that Pidgin would compile with all of its extensions and protocols – particularly screen saver integration for "away" status. Hopefully a good version will be included in Gutsy. These are the components I needed for building Pidgin 2.10 under Edgy. (Why am I still on Edgy? Because distribution upgrade didn't work from Dapper to Edgy, so I mistrust it, and I haven't set aside a morning to upgrade.)

I spent the most time figuring out which packages would contain mono.pc and gstreamer0.10.pc – once I figured that out it went a lot faster. Hope this helps -- it probably isn't everything, but it's most of it. Start with a nice howto, and use the stuff below to turn on the other options.

sudo apt-get install libstartup-notification0-dev libperl-dev libnm-glib-dev libgadu-dev libsilc-dev libhowl-dev libavahi-compat-howl-dev libsqlite-dev libnspr-dev libdbus-glib-1-dev libdbus-1-dev libgtkspell-dev libmono-dev libxss-dev libebook1.2-dev libedata-book1.2-dev libsqlite3-dev libgstreamer0.10-dev tcl8.4-dev tk8.4-dev libmeanwhile-dev liblaunchpad-integration0 libnm-glib0

./configure --enable-gnutls=yes --enable-mono --enable-nm --enable-consoleui --enable-gevolution --enable-gstreamer --enable-plugins --disable-schemas-install --enable-screensaver --enable-tcl --enable-tk