Skip to content

Commit

Permalink
Add i18n support for field name and actions name
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Wernimont authored and jgdavey committed Nov 25, 2010
1 parent 116076e commit 087b17c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
17 changes: 17 additions & 0 deletions README.rdoc
Expand Up @@ -239,6 +239,23 @@ will product html like:

If it _still_ isn't flexible enough for your needs, it might be time to return to static html/erb.

== Internationalization (I18n)

Tabletastic has some i18n-features enabled by default.

Here is an example of locales:

en:
tabletastic:
actions:
show: "See"
edit: "Edit"
destroy: "Remove"
are_you_sure?: "Are you sure ?"
models:
comment:
title: "Title"

== Default Options and Tabletastic initializer

As of version 0.2.0, you can now setup some of your own defaults in an initializer file.
Expand Down
17 changes: 12 additions & 5 deletions lib/tabletastic/table_builder.rb
Expand Up @@ -3,13 +3,13 @@
module Tabletastic
class TableBuilder
@@default_hidden_columns = %w[created_at updated_at created_on updated_on lock_version version]
@@destroy_confirm_message = "Are you sure?"

attr_reader :collection, :klass, :table_fields

def initialize(collection, klass, template)
@collection, @klass, @template = collection, klass, template
@table_fields = []
@@destroy_confirm_message = I18n.translate("tabletastic.actions.are_you_sure?", :default => "Are you sure?")
end

# builds up the fields that the table will include,
Expand Down Expand Up @@ -68,7 +68,11 @@ def head
content_tag(:thead) do
content_tag(:tr) do
@table_fields.inject("") do |result,field|
result + content_tag(:th, field.heading, field.heading_html)
field_heading = field.heading.to_s.downcase
localised_heading = I18n.translate(field_heading,
:scope => [:tabletastic, :models, klass.model_name.collection.singularize],
:default => field.heading) unless(field.heading.empty?)
result + content_tag(:th, localised_heading, field.heading_html)
end.html_safe
end
end
Expand Down Expand Up @@ -109,12 +113,15 @@ def action_link(action, prefix)
compound_resource.flatten! if prefix.kind_of?(Array)
case action
when :show
@template.link_to("Show", compound_resource)
link_title = I18n.translate("tabletastic.actions.show", :default => "Show")
@template.link_to(link_title, compound_resource)
when :destroy
@template.link_to("Destroy", compound_resource,
link_title = I18n.translate("tabletastic.actions.destroy", :default => "Destroy")
@template.link_to(link_title, compound_resource,
:method => :delete, :confirm => @@destroy_confirm_message)
else # edit, other resource GET actions
@template.link_to(action.to_s.titleize,
link_title = I18n.translate(action, :scope => "tabletastic.actions", :default => action.to_s.titleize)
@template.link_to(link_title,
@template.polymorphic_path(compound_resource, :action => action))
end
end
Expand Down

0 comments on commit 087b17c

Please sign in to comment.