I18n Translations with a database backend

Having used Rails I18n translations in yaml for some time, we’ve recently started thinking about how users might want to customise content on the fly, without editing flat files and reloading our application. In my mind it should read from the database.

I found the Il8n Backend Database plugin, however it appears its not Rails 3 compliant yet and we can cope with and probably should build the interface for updating our own translations

https://github.com/dylanz/i18n_backend_database

It seems there was support for ActiveRecord in the i18n gem, but it has since been moved out into the i18n-active_record gem.

./Gemfile

gem 'i18n-active_record', 
  :git => 'git://github.com/svenfuchs/i18n-active_record.git',
  :require => 'i18n/active_record'

./config/initializers/i18n.rb

I18n.backend = I18n::Backend::ActiveRecord
Translation  = I18n::Backend::ActiveRecord::Translation

./db/migrate/20101218175356_create_translations.rb

class CreateTranslations < ActiveRecord::Migration

  def self.up
    create_table :translations do |t|
      t.string   :locale
      t.string   :key
      t.text     :value
      t.text     :interpolations
      t.boolean  :is_proc, :default => false
    end
  end

  def self.down
    drop_table :translations
  end

end

irb

irb(main):001:0> I18n.t('loathsome')
=> "loathsome"
irb(main):002:0> Translation.create(:locale => :en, :key => 'loathsome', :value => 'dave')
=> #<I18n::Backend::ActiveRecord::Translation id: 1, locale: :en, key: "loathsome", value: "dave", interpolations: nil, is_proc: false>
irb(main):003:0> I18n.t('loathsome')
=> "dave"

So fairly simple start, it shouldn’t be too difficult to build an interface to handle this.

You can even keep the existing flat files as a fallback if the translations don’t exist in the database.

./config/initializers/i18n.rb

I18n.backend = I18n::Backend::Chain.new(I18n::Backend::ActiveRecord.new, I18n.backend)
Translation = I18n::Backend::ActiveRecord::Translation

Fan Funded and Exciting Times

This week has been an interesting one, and its all come at once.

Abominable Iron Sloth

For a start, The Abominable Iron Sloth album has finally seen its release on the 27th April after 4 fours of development hell. The band asked for funding from its fans after the debut release and tour. And it seems to have been one tragedy after another for them, what keeps you down only makes you stronger, eh? And here it is, arrived today with a thanks from Justin.

Stabbing Eden

Pledge Music also got their first Grindcore band on board, Stabbing Eden and I am mightily impressed what what I’ve heard so far so I one of the first to pledge. Their project to fund the recording of their 2nd album “A Second Reason To Hate Us” was launch on the 27th April.

Funeral For A Friend

Firstly, we had Madina Lake, then Tab The Band, but now the biggest metal band so far Funeral For A Friend who went live on Monday, and made their target within 36 hours which is a first for us. Well done those men, but its not over yet.

Thomas Truax

Last but not least, a man we stumbled across lately for a random zombie event in Eastbourne. The very quirky, very eccentric Thomas Truax. If only I could afford one of his famous Sister Spinster contraptions.

installing Redcar editor on Windows in 5 minutes

download

download

[Start Command Prompt with Ruby]

gem install redcar --pre 
redcar install
redcar

how to create a singleton with Io

rl@bloodandguts:~/github/io$ io
Io 20090105
Io> Highlander := Object clone
==>  Highlander_0x1957db0:
  type             = "Highlander"

Io> Highlander clone := Highlander
==>  Highlander_0x1957db0:
  clone            = Highlander_0x1957db0
  type             = "Highlander"

Io> h := Highlander clone
==>  Highlander_0x1957db0:
  clone            = Highlander_0x1957db0
  type             = "Highlander"

Io> h type
==> Highlander
Io> h
==>  Highlander_0x1957db0:
  clone            = Highlander_0x1957db0
  type             = "Highlander"

Io>

New Facebook Tools

Just playing with the new Facebook widgets to see if we can get anything useful out of them.

Pledge Music on Facebook

autotest on ubuntu

Finally got around to sorting out autotest on this ubuntu box, I remembered reading on Mr JohnC’s blog about it. Also found a rather nice article on Autotest notifications on Ubuntu using lib-notify

vi ~/.autotest

module Autotest::GnomeNotify
 
  # Time notification will be displayed before disappearing automatically
  EXPIRATION_IN_SECONDS = 2
  ERROR_STOCK_ICON = "gtk-dialog-error"
  SUCCESS_STOCK_ICON = "gtk-dialog-info"
 
  # Convenience method to send an error notification message
  #
  # [stock_icon]   Stock icon name of icon to display
  # [title]        Notification message title
  # [message]      Core message for the notification
  def self.notify stock_icon, title, message
    options = "-t #{EXPIRATION_IN_SECONDS * 1000} -i #{stock_icon}"
    system "notify-send #{options} '#{title}' '#{message}'"
  end
 
  Autotest.add_hook :red do |at|
    notify ERROR_STOCK_ICON, "Tests failed", "#{at.files_to_test.size} tests failed"
  end
 
  Autotest.add_hook :green do |at|
    notify SUCCESS_STOCK_ICON, "All tests passed, good job!", ""
  end
 
end

I never use ri for gems.

I always found ri to just really too slow to be of any use, at least on of the machines I use and everytime I install a new gem it seems to slow everything down to a halt.

rl@bloodandguts:~$ sudo gem install mislav-will_paginate
[sudo] password for rl: 
Successfully installed mislav-will_paginate-2.3.11
1 gem installed
Installing ri documentation for mislav-will_paginate-2.3.11...
Updating ri class cache with 9654 classes...
Installing RDoc documentation for mislav-will_paginate-2.3.11...

If you never use the ri documenation for gems, you can turn this off in your ~/.gemrc file by adding the gem line.

--- 
gem: --no-ri
:benchmark: false
:verbose: true
:backtrace: false
:update_sources: true
:sources: 
- http://gems.rubyforge.org/
- http://gems.github.com
:bulk_threshold: 1000

I think perhaps I need to do a gem cleanup to really clear out anything I’m not using and remove the gems I installed over a year ago for testing and never use.

AWK on the command

I’m pretty sure this is the only example of AWK I’ve ever used. But its come in hand more than a few times.

cat /var/log/apache2/loathsome-access.log | awk '{ print $1 }' | uniq

Abominable Iron Sloth II has a release date - 20th April 2010

I’ve been waiting this follow up to Abominable Iron Sloth’s debut for 3 years now, way back Justin asked his Myspace fans to pledge towards funding their next EP, hinting that it might not otherwise happen. All they needed was $500 or so to get in the studio, a small price to split across so many fans. Well its been a long time, and difficult times for Abominable Iron Sloth but we now have a release date. Roll on April 20th April 27th.

Keep up to date with their news on

Scott Hull - Audiofilm II

Audiofilm II is the second installment in the Crucial Blast series of limited-edition 3-inch CDs from Scott Hull. Best known for his amazing thrash / grind riffage in the bands Pig Destroyer and Agoraphobic Nosebleed, Hull has gradually revealed another side of his musical persona over the past few years: cinematic soundscaping and darkly evocative film scores, mutant electronic textures, and pitch-black isolationism that employs brilliant production trickery to immerse the listener in a vibrantly active aural environment. Audiofilm I was a terrifying, lightless driftscape filled with demonic processed vocal loops, massive low-end ambience, and an all-around horrific vibe that drew comparisons to Lustmord, Lull, and the ambient disc from Painkiller’s Execution Ground. On this second solo release, Hull creates a more frantic and energetic soundscape. Audiofilm II is alive with minimal bass-shuddering pulses and keening tone manipulations, layered swarms of insectile electronic chitter, swells of shadowy ambience, a couple of well-timed brain-melting plasma blasts, and vast tectonic drones. Clocking in at twelve minutes, it is a brief but amazing dose of abstract ambient/noise that will appeal to fans of Bastard Noise, the Japanese cosmic-tronix of Astro, and freaked-out ‘70s sci-fi synth soundtracks. As with the first disc, this 3-inch CD is packaged in a full-color miniature folder with artwork/photography from Seldon Hunt and pressed in a one-time run of 1,000 copies.