Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add .translatable_columns.

  • Loading branch information...
commit f93c0cc9ea5bad39394bfa0f6a687952fb388828 1 parent b135a7a
@henrik henrik authored
View
2  README.markdown
@@ -27,6 +27,8 @@ Now, you can still use the `title_sv` accessors in forms, validations and other
`.human_attribute_name(:title_sv)`: Extends this standard method to return "Title (Swedish)" if you have a translation key `i18n.languages.sv = "Swedish"` and "Title (SV)" otherwise. Rails uses this method to build validation error messages and form labels.
+`.translatable_columns`: Returns an array like `[:title, :body]`.
+
`.locales_for_column(:title)`: Returns an array like `[:sv, :en]` sorted with default locale first and then alphabetically. Suitable for looping in forms:
<% locales_for_column(:title) do |locale| %>
View
6 lib/traco/class_methods.rb
@@ -1,6 +1,10 @@
module Traco
module ClassMethods
+ def translatable_columns
+ @translatable_columns
+ end
+
def locales_for_column(column)
column_names.grep(/\A#{column}_([a-z]{2})\z/) {
$1.to_sym
@@ -27,7 +31,7 @@ def human_attribute_name(attribute, options={})
private
def translates?(column)
- @translates_columns.include?(column.to_sym)
+ translatable_columns.include?(column.to_sym)
end
def locale_name(locale)
View
4 lib/traco/translates.rb
@@ -5,8 +5,8 @@ def translates(*columns)
extend Traco::ClassMethods
include Traco::InstanceMethods
- @translates_columns ||= []
- @translates_columns |= columns.map(&:to_sym)
+ @translatable_columns ||= []
+ @translatable_columns |= columns.map(&:to_sym)
columns.each do |column|
View
2  lib/traco/version.rb
@@ -1,3 +1,3 @@
module Traco
- VERSION = "0.1.1"
+ VERSION = "0.2.0"
end
View
12 spec/traco_spec.rb
@@ -22,6 +22,18 @@
end
+describe Post, ".translatable_columns" do
+
+ before do
+ Post.translates :title
+ end
+
+ it "should list the translatable columns" do
+ Post.translatable_columns.should == [ :title ]
+ end
+
+end
+
describe Post, ".locales_for_column" do
before do
Please sign in to comment.
Something went wrong with that request. Please try again.