Skip to content

Commit

Permalink
Working on the internationalization
Browse files Browse the repository at this point in the history
  • Loading branch information
ashrafuzzaman committed Jun 20, 2012
1 parent c57fa2f commit eb652f9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
23 changes: 17 additions & 6 deletions lib/generators/i18ize/i18ize_generator.rb
Expand Up @@ -3,20 +3,31 @@ class I18izeGenerator < Rails::Generators::NamedBase

def replace
files.each do |file|
replace_hash.each_pair { |replace_with, replace_str| }
gsub_file file, Regexp.new(replace_str) do |match|
replace_with
replace_hash.each do |replace_with, replace_str|
gsub_file file, Regexp.new(replace_str) do |match|
replace_with
end
end
end
end

private
def files
["app/controllers/#{plural_table_name}_controller.rb"]
@files ||= ["app/controllers/#{plural_table_name}_controller.rb",
"app/views/#{plural_table_name}/edit.html.erb",
"app/views/#{plural_table_name}/_form.html.erb",
"app/views/#{plural_table_name}/index.html.erb",
"app/views/#{plural_table_name}/new.html.erb",
"app/views/#{plural_table_name}/show.html.erb",]
end

def replace_hash
{ "t(:'msg.#{singular_table_name}.created')" => "'#{human_name} was successfully created.'"
}
{"t(:'msg.#{singular_table_name}.created')" => "'#{human_name} was successfully created.'",
"t(:'msg.#{singular_table_name}.updated')" => "'#{human_name} was successfully updated.'",
"t(:'link.#{singular_table_name}.show')" => "'Show'",
"t(:'link.#{singular_table_name}.edit')" => "'Edit'",
"t(:'link.#{singular_table_name}.back')" => "'Back'",
"t(:'link.#{singular_table_name}.destroy')" => "'Destroy'",
"t(:'link.#{singular_table_name}.new')" => "'New #{human_name}'"}
end
end
Expand Up @@ -26,6 +26,6 @@
</fieldset>
<div class="form-actions">
<%%= f.submit class: 'btn btn-primary' %>
<%%= link_to t(:'links.back'), <%= index_helper %>_path, :class => 'btn' %>
<%%= link_to 'Back', <%= index_helper %>_path, :class => 'btn' %>
</div>
<%% end %>
@@ -1,4 +1,4 @@
<%%= render 'form' %>

<%%= link_to t(:'links.show'), @<%= singular_table_name %> %> |
<%%= link_to t(:'links.back'), <%= index_helper %>_path %>
<%%= link_to 'Show', @<%= singular_table_name %> %> |
<%%= link_to 'Back', <%= index_helper %>_path %>
Expand Up @@ -16,9 +16,9 @@
<td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
<% end -%>
<td>
<%%= link_to t(:'links.show'), <%= singular_table_name %>, class: 'btn btn-mini' %>
<%%= link_to t(:'links.edit'), edit_<%= singular_table_name %>_path(<%= singular_table_name %>), class: 'btn btn-mini' %>
<%%= link_to t(:'links.destroy'), <%= singular_table_name %>, confirm: t(:'msg.destroy.confirm'), method: :delete, class: 'btn btn-mini btn-danger' %>
<%%= link_to 'Show', <%= singular_table_name %>, class: 'btn btn-mini' %>
<%%= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>), class: 'btn btn-mini' %>
<%%= link_to 'Destroy', <%= singular_table_name %>, confirm: t(:'msg.destroy.confirm'), method: :delete, class: 'btn btn-mini btn-danger' %>
</td>
<%% end %>
</tbody>
Expand All @@ -27,5 +27,5 @@
<br />

<div class="form-actions">
<%%= link_to t(:'links.new_<%= human_name %>'), new_<%= singular_table_name %>_path, class: 'btn btn-primary' %>
<%%= link_to 'New <%= human_name %>', new_<%= singular_table_name %>_path, class: 'btn btn-primary' %>
</div>
Expand Up @@ -27,7 +27,7 @@ def create
if @<%= orm_instance.save %>
format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %> }
format.json { render json: <%= "@#{singular_table_name}" %>, status: :created, location: <%= "@#{singular_table_name}" %> }
format.js { flash[:notice] = t(:'<%= "msg.#{singular_table_name}.created" %>') }
format.js { flash[:notice] = <%= "'#{human_name} was successfully created.'" %> }
else
format.html { render action: "new" }
format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
Expand All @@ -41,9 +41,9 @@ def update

respond_to do |format|
if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %>
format.html { redirect_to @<%= singular_table_name %>, notice: t(:'<%= "msg.#{singular_table_name}.updated" %>') }
format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %> }
format.json { head :no_content }
format.js { flash[:notice] = t(:'<%= "msg.#{singular_table_name}.updated" %>') }
format.js { flash[:notice] = <%= "'#{human_name} was successfully updated.'" %> }
else
format.html { render action: "edit" }
format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
Expand Down

0 comments on commit eb652f9

Please sign in to comment.