OSDN Git Service

ActiveLdap 1.2.4
[redminele/redminele.git] / ruby / lib / ruby / gems / 1.8 / gems / fast_gettext-0.5.8 / lib / fast_gettext / translation_repository / db_models / translation_key.rb
diff --git a/ruby/lib/ruby/gems/1.8/gems/fast_gettext-0.5.8/lib/fast_gettext/translation_repository/db_models/translation_key.rb b/ruby/lib/ruby/gems/1.8/gems/fast_gettext-0.5.8/lib/fast_gettext/translation_repository/db_models/translation_key.rb
new file mode 100644 (file)
index 0000000..3fcc638
--- /dev/null
@@ -0,0 +1,18 @@
+class TranslationKey < ActiveRecord::Base
+  has_many :translations, :class_name => 'TranslationText'
+
+  accepts_nested_attributes_for :translations, :allow_destroy => true
+
+  validates_uniqueness_of :key
+  validates_presence_of :key
+
+  def self.translation(key, locale)
+    return unless translation_key = find_by_key(key)
+    return unless translation_text = translation_key.translations.find_by_locale(locale)
+    translation_text.text
+  end
+
+  def self.available_locales
+    @@available_locales ||= TranslationText.count(:group=>:locale).keys.sort
+  end
+end
\ No newline at end of file