Add a list of languages and fix a few issues with the schema. Also get
authorTom Hughes <tom@compton.nu>
Sat, 30 May 2009 16:37:21 +0000 (16:37 +0000)
committerTom Hughes <tom@compton.nu>
Sat, 30 May 2009 16:37:21 +0000 (16:37 +0000)
language selection for diary entries working.

app/controllers/diary_entry_controller.rb
app/models/diary_entry.rb
app/models/language.rb
app/views/diary_entry/edit.rhtml
config/languages.yml [new file with mode: 0644]
db/migrate/032_add_user_locale.rb
db/migrate/033_change_diary_entries_language.rb
db/migrate/034_create_languages.rb

index 9ce5409..96bf154 100644 (file)
@@ -13,8 +13,6 @@ class DiaryEntryController < ApplicationController
     if params[:diary_entry]     
       @diary_entry = DiaryEntry.new(params[:diary_entry])
       @diary_entry.user = @user
-      @diary_entry.language = Language.find_by_code(params[:language])
-      @diary_entry.language = Language.find_by_code("en") if @diary_entry.language.nil?
 
       if @diary_entry.save 
         redirect_to :controller => 'diary_entry', :action => 'list', :display_name => @user.display_name 
@@ -22,6 +20,7 @@ class DiaryEntryController < ApplicationController
         render :action => 'edit'
       end
     else
+      @diary_entry = DiaryEntry.new(:language => @user.language)
       render :action => 'edit'
     end
   end
index 33e95d1..7054382 100644 (file)
@@ -1,6 +1,6 @@
 class DiaryEntry < ActiveRecord::Base
   belongs_to :user
-  belongs_to :language, :foreign_key => 'language'
+  belongs_to :language, :foreign_key => 'language_code'
   
   has_many :diary_comments, :include => :user,
                             :conditions => ["users.visible = ?", true],
@@ -14,4 +14,5 @@ class DiaryEntry < ActiveRecord::Base
   validates_numericality_of :longitude, :allow_nil => true,
                             :greater_than_or_equal_to => -180, :less_than_or_equal_to => 180
   validates_associated :user
+  validates_associated :language
 end
index 150341c..81441db 100644 (file)
@@ -3,12 +3,10 @@ class Language < ActiveRecord::Base
 
   has_many :users, :foreign_key => 'locale'
   has_many :diary_entries, :foreign_key => 'language'
-  
-  def self.generate(code, name, translation_available)
-    Language.create do |l|
-      l.code = code
-      l.name = name
-      l.translation_available = translation_available
-    end
-  end
+
+  def name
+    name = english_name
+    name += " (#{native_name})" unless native_name.nil?
+    name
+  end  
 end
index 41b9c8b..5533677 100644 (file)
@@ -14,7 +14,7 @@
     </tr>
     <tr valign="top">
       <td class="fieldName"><%= t 'diary_entry.edit.language' -%></td>
-      <td><%= f.collection_select :language, Language.find(:all), :code, :name %></td>
+      <td><%= f.collection_select :language_code, Language.find(:all, :order => :english_name), :code, :name %></td>
     </tr>
     <tr valign="top">
       <td class="fieldName"><%= t 'diary_entry.edit.location' -%></td>
diff --git a/config/languages.yml b/config/languages.yml
new file mode 100644 (file)
index 0000000..df0a832
--- /dev/null
@@ -0,0 +1,735 @@
+aa:
+  english: Afar
+  native: Afaraf
+
+ab:
+  english: Abkhazian
+  native: Аҧсуа
+
+ae:
+  english: Avestan
+  native: avesta
+
+af:
+  english: Afrikaans
+  native: Afrikaans
+
+ak:
+  english: Akan
+  native: Akan
+
+am:
+  english: Amharic
+  native: አማርኛ
+
+an:
+  english: Aragonese
+  native: Aragonés
+
+ar:
+  english: Arabic
+  native: العربية
+
+as:
+  english: Assamese
+  native: অসমীয়া
+
+av:
+  english: Avaric
+  native: авар мацӀ; магӀарул мацӀ
+
+ay:
+  english: Aymara
+  native: aymar aru
+
+az:
+  english: Azerbaijani
+  native: azərbaycan dili
+
+ba:
+  english: Bashkir
+  native: башҡорт теле
+
+be:
+  english: Belarusian
+  native: Беларуская
+
+bg:
+  english: Bulgarian
+  native: български език
+
+bh:
+  english: Bihari
+  native: भोजपुरी
+
+bi:
+  english: Bislama
+  native: Bislama
+
+bm:
+  english: Bambara
+  native: bamanankan
+
+bn:
+  english: Bengali
+  native: বাংলা
+
+bo:
+  english: Tibetan
+  native: བོད་ཡིག
+
+br:
+  english: Breton
+  native: brezhoneg
+
+bs:
+  english: Bosnian
+  native: bosanski jezik
+
+ca:
+  english: Catalan
+  native: Català
+
+ce:
+  english: Chechen
+  native: нохчийн мотт
+
+ch:
+  english: Chamorro
+  native: Chamoru
+
+co:
+  english: Corsican
+  native: corsu; lingua corsa
+
+cr:
+  english: Cree
+  native: ᓀᐦᐃᔭᐍᐏᐣ
+
+cs:
+  english: Czech
+  native: česky; čeština
+
+cu:
+  english: Church Slavic
+  native: ѩзыкъ словѣньскъ
+
+cv:
+  english: Chuvash
+  native: чӑваш чӗлхи
+
+cy:
+  english: Welsh
+  native: Cymraeg
+
+da:
+  english: Danish
+  native: dansk
+
+de:
+  english: German
+  native: Deutsch
+
+dv:
+  english: Divehi
+  native: ދިވެހި
+
+dz:
+  english: Dzongkha
+  native: རྫོང་ཁ
+
+ee:
+  english: Ewe
+  native: Ɛʋɛgbɛ
+
+el:
+  english: Greek
+  native: Ελληνικά
+
+en:
+  english: English
+  native: English
+
+eo:
+  english: Esperanto
+  native: Esperanto
+
+es:
+  english: Spanish
+  native: Español; castellano
+
+et:
+  english: Estonian
+  native: eesti; eesti keel
+
+eu:
+  english: Basque
+  native: euskara; euskera
+
+fa:
+  english: Persian
+  native: فارسی
+
+ff:
+  english: Fulah
+  native: Fulfulde
+
+fi:
+  english: Finnish
+  native: suomi; suomen kieli
+
+fj:
+  english: Fijian
+  native: vosa Vakaviti
+
+fo:
+  english: Faroese
+  native: Føroyskt
+
+fr:
+  english: French
+  native: Français; langue française
+
+fy:
+  english: Western Frisian
+  native: Frysk
+
+ga:
+  english: Irish
+  native: Gaeilge
+
+gd:
+  english: Scottish Gaelic
+  native: Gàidhlig
+
+gl:
+  english: Galician
+  native: Galego
+
+gn:
+  english: Guaraní
+  native: Avañe'ẽ
+
+gu:
+  english: Gujarati
+  native: ગુજરાતી
+
+gv:
+  english: Manx
+  native: Gaelg; Gailck
+
+ha:
+  english: Hausa
+  native: هَوُسَ
+
+he:
+  english: Hebrew
+  native: עברית
+
+hi:
+  english: Hindi
+  native: हिन्दी; हिंदी
+
+ho:
+  english: Hiri Motu
+  native: Hiri Motu
+
+hr:
+  english: Croatian
+  native: Hrvatski
+
+ht:
+  english: Haitian
+  native: Kreyòl ayisyen
+
+hu:
+  english: Hungarian
+  native: Magyar
+
+hy:
+  english: Armenian
+  native: Հայերեն
+
+hz:
+  english: Herero
+  native: Otjiherero
+
+ia:
+  english: Interlingua (International Auxiliary Language Association)
+  native: Interlingua
+
+id:
+  english: Indonesian
+  native: Bahasa Indonesia
+
+ie:
+  english: Interlingue
+  native: Interlingue
+
+ig:
+  english: Igbo
+  native: Igbo
+
+ii:
+  english: Sichuan Yi
+  native: ꆇꉙ
+
+ik:
+  english: Inupiaq
+  native: Iñupiaq; Iñupiatun
+
+io:
+  english: Ido
+  native: Ido
+
+is:
+  english: Icelandic
+  native: Íslenska
+
+it:
+  english: Italian
+  native: Italiano
+
+iu:
+  english: Inuktitut
+  native: ᐃᓄᒃᑎᑐᑦ
+
+ja:
+  english: Japanese
+  native: 日本語 (にほんご/にっぽんご)
+
+jv:
+  english: Javanese
+  native: basa Jawa
+
+ka:
+  english: Georgian
+  native: ქართული
+
+kg:
+  english: Kongo
+  native: KiKongo
+
+ki:
+  english: Kikuyu
+  native: Gĩkũyũ
+
+kj:
+  english: Kwanyama
+  native: Kuanyama
+
+kk:
+  english: Kazakh
+  native: Қазақ тілі
+
+kl:
+  english: Kalaallisut
+  native: kalaallisut; kalaallit oqaasii
+
+km:
+  english: Khmer
+  native: ភាសាខ្មែរ
+
+kn:
+  english: Kannada
+  native: ಕನ್ನಡ
+
+ko:
+  english: Korean
+  native: 한국어 (韓國語); 조선말 (朝鮮語)
+
+kr:
+  english: Kanuri
+  native: Kanuri
+
+ks:
+  english: Kashmiri
+  native: कश्मीरी; كشميري‎
+
+ku:
+  english: Kurdish
+  native: Kurdî; كوردی‎
+
+kv:
+  english: Komi
+  native: коми кыв
+
+kw:
+  english: Cornish
+  native: Kernewek
+
+ky:
+  english: Kirghiz
+  native: кыргыз тили
+
+la:
+  english: Latin
+  native: latine; lingua latina
+
+lb:
+  english: Luxembourgish
+  native: Lëtzebuergesch
+
+lg:
+  english: Ganda
+  native: Luganda
+
+li:
+  english: Limburgish
+  native: Limburgs
+
+ln:
+  english: Lingala
+  native: Lingála
+
+lo:
+  english: Lao
+  native: ພາສາລາວ
+
+lt:
+  english: Lithuanian
+  native: lietuvių kalba
+
+lu:
+  english: Luba-Katanga
+  native: 
+
+lv:
+  english: Latvian
+  native: latviešu valoda
+
+mg:
+  english: Malagasy
+  native: Malagasy fiteny
+
+mh:
+  english: Marshallese
+  native: Kajin M̧ajeļ
+
+mi:
+  english: Māori
+  native: te reo Māori
+
+mk:
+  english: Macedonian
+  native: македонски јазик
+
+ml:
+  english: Malayalam
+  native: മലയാളം
+
+mn:
+  english: Mongolian
+  native: Монгол
+
+mr:
+  english: Marathi
+  native: मराठी
+
+ms:
+  english: Malay
+  native: bahasa Melayu; بهاس ملايو‎
+
+mt:
+  english: Maltese
+  native: Malti
+
+my:
+  english: Burmese
+  native: ဗမာစာ
+
+na:
+  english: Nauru
+  native: Ekakairũ Naoero
+
+nb:
+  english: Norwegian Bokmål
+  native: Norsk bokmål
+
+nd:
+  english: North Ndebele
+  native: isiNdebele
+
+ne:
+  english: Nepali
+  native: नेपाली
+
+ng:
+  english: Ndonga
+  native: Owambo
+
+nl:
+  english: Dutch
+  native: Nederlands
+
+nn:
+  english: Norwegian Nynorsk
+  native: Norsk nynorsk
+
+no:
+  english: Norwegian
+  native: Norsk
+
+nr:
+  english: South Ndebele
+  native: isiNdebele
+
+nv:
+  english: Navajo
+  native: Diné bizaad; Dinékʼehǰí
+
+ny:
+  english: Chichewa
+  native: chiCheŵa; chinyanja
+
+oc:
+  english: Occitan
+  native: Occitan
+
+oj:
+  english: Ojibwa
+  native: ᐊᓂᔑᓈᐯᒧᐎᓐ
+
+om:
+  english: Oromo
+  native: Afaan Oromoo
+
+or:
+  english: Oriya
+  native: ଓଡ଼ିଆ
+
+os:
+  english: Ossetian
+  native: Ирон æвзаг
+
+pa:
+  english: Panjabi
+  native: ਪੰਜਾਬੀ; پنجابی‎
+
+pi:
+  english: Pāli
+  native: पाऴि
+
+pl:
+  english: Polish
+  native: polski
+
+ps:
+  english: Pashto
+  native: پښتو
+
+pt:
+  english: Portuguese
+  native: Português
+
+qu:
+  english: Quechua
+  native: Runa Simi; Kichwa
+
+rm:
+  english: Raeto-Romance
+  native: rumantsch grischun
+
+rn:
+  english: Kirundi
+  native: kiRundi
+
+ro:
+  english: Romanian
+  native: română
+
+ru:
+  english: Russian
+  native: русский язык
+
+rw:
+  english: Kinyarwanda
+  native: Ikinyarwanda
+
+sa:
+  english: Sanskrit
+  native: संस्कृतम्
+
+sc:
+  english: Sardinian
+  native: sardu
+
+sd:
+  english: Sindhi
+  native: सिन्धी; سنڌي، سندھی‎
+
+se:
+  english: Northern Sami
+  native: Davvisámegiella
+
+sg:
+  english: Sango
+  native: yângâ tî sängö
+
+si:
+  english: Sinhala
+  native: සිංහල
+
+sk:
+  english: Slovak
+  native: slovenčina
+
+sl:
+  english: Slovenian
+  native: slovenščina
+
+sm:
+  english: Samoan
+  native: gagana fa'a Samoa
+
+sn:
+  english: Shona
+  native: chiShona
+
+so:
+  english: Somali
+  native: Soomaaliga; af Soomaali
+
+sq:
+  english: Albanian
+  native: Shqip
+
+sr:
+  english: Serbian
+  native: српски језик
+
+ss:
+  english: Swati
+  native: SiSwati
+
+st:
+  english: Southern Sotho
+  native: Sesotho
+
+su:
+  english: Sundanese
+  native: Basa Sunda
+
+sv:
+  english: Swedish
+  native: svenska
+
+sw:
+  english: Swahili
+  native: Kiswahili
+
+ta:
+  english: Tamil
+  native: தமிழ்
+
+te:
+  english: Telugu
+  native: తెలుగు
+
+tg:
+  english: Tajik
+  native: тоҷикӣ; toğikī; تاجیکی‎
+
+th:
+  english: Thai
+  native: ไทย
+
+ti:
+  english: Tigrinya
+  native: ትግርኛ
+
+tk:
+  english: Turkmen
+  native: Türkmen; Түркмен
+
+tl:
+  english: Tagalog
+  native: Tagalog
+
+tn:
+  english: Tswana
+  native: Setswana
+
+to:
+  english: Tonga
+  native: faka Tonga
+
+tr:
+  english: Turkish
+  native: Türkçe
+
+ts:
+  english: Tsonga
+  native: Xitsonga
+
+tt:
+  english: Tatar
+  native: татарча; tatarça; تاتارچا‎
+
+tw:
+  english: Twi
+  native: Twi
+
+ty:
+  english: Tahitian
+  native: Reo Mā`ohi
+
+ug:
+  english: Uighur
+  native: Uyƣurqə; ئۇيغۇرچە‎
+
+uk:
+  english: Ukrainian
+  native: Українська
+
+ur:
+  english: Urdu
+  native: اردو
+
+uz:
+  english: Uzbek
+  native: O'zbek; Ўзбек; أۇزبېك‎
+
+ve:
+  english: Venda
+  native: Tshivenḓa
+
+vi:
+  english: Vietnamese
+  native: Tiếng Việt
+
+vo:
+  english: Volapük
+  native: Volapük
+
+wa:
+  english: Walloon
+  native: Walon
+
+wo:
+  english: Wolof
+  native: Wollof
+
+xh:
+  english: Xhosa
+  native: isiXhosa
+
+yi:
+  english: Yiddish
+  native: ייִדיש
+
+yo:
+  english: Yoruba
+  native: Yorùbá
+
+za:
+  english: Zhuang
+  native: Saɯ cueŋƅ; Saw cuengh
+
+zh:
+  english: Chinese
+  native: 中文 (Zhōngwén), 汉语, 漢語
+
+zu:
+  english: Zulu
+  native: isiZulu
index 4d00fc1..de36547 100644 (file)
@@ -1,6 +1,6 @@
 class AddUserLocale < ActiveRecord::Migration
   def self.up
-    add_column "users", "locale", :string, :default => "en", :null => false
+    add_column "users", "locale", :string
   end
 
   def self.down
index 7d4fa17..2ca8448 100644 (file)
@@ -1,9 +1,11 @@
 class ChangeDiaryEntriesLanguage < ActiveRecord::Migration
   def self.up
-    change_column "diary_entries", "language", :string, :default => "en", :null => false
+    remove_column "diary_entries", "language"
+    add_column "diary_entries", "language_code", :string
   end
 
   def self.down
-    change_column "diary_entries", "language", :string, :limit => 3, :default => nil, :null => true
+    remove_column "diary_entries", "language_code"
+    add_column "diary_entries", "language", :string, :limit => 3
   end
 end
index daaf219..cb6c392 100644 (file)
@@ -3,17 +3,19 @@ require 'lib/migrate'
 class CreateLanguages < ActiveRecord::Migration
   def self.up
     create_table :languages, innodb_table do |t|
-      t.string :code, :limit => 5, :null => false
-      t.string :name, :null => false
-      t.boolean :translation_available, :null => false, :default => false
+      t.string :code, :null => false
+      t.string :english_name, :null => false
+      t.string :native_name
     end
 
     add_primary_key :languages, [:code]
 
-    Language.create do |l|
-      l.code = 'en'
-      l.name = 'English'
-      l.translation_available = true
+    YAML.load(File.read(RAILS_ROOT + "/config/languages.yml")).each do |k,v|
+      Language.create do |l|
+        l.code = k
+        l.english_name = v["english"]
+        l.native_name = v["native"]
+      end
     end
 
     add_foreign_key :users, [:locale], :languages, [:code]