]> git.openstreetmap.org Git - rails.git/blob - app/models/language.rb
Add support for reloading the language table.
[rails.git] / app / models / language.rb
1 class Language < ActiveRecord::Base
2   set_primary_key :code
3
4   has_many :diary_entries, :foreign_key => 'language'
5
6   def self.load(file)
7     Language.transaction do
8       YAML.load(File.read(file)).each do |k,v|
9         begin
10           Language.update(k, :english_name => v["english"], :native_name => v["native"])
11         rescue ActiveRecord::RecordNotFound
12           Language.create do |l|
13             l.code = k
14             l.english_name = v["english"]
15             l.native_name = v["native"]
16           end
17         end
18       end
19     end
20   end
21
22   def name
23     name = english_name
24     name += " (#{native_name})" unless native_name.nil?
25     name
26   end  
27 end