Override view=admin/pages/_locale_picker
; copy it into app/views/shared/admin/
(may need to mkdir -p
here)
-
-
Save robyurkowski/3649d08ab3c84b24ab52 to your computer and use it in GitHub Desktop.
Translating a Refinery 1.0.9 Engine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 1: Migration. | |
# db/create_<model>_translations | |
class Create<Model>Translations < ActiveRecord::Migration | |
def self.up | |
<Model>.create_translation_table!({ | |
:title => :string, | |
:body => :text | |
}, :migrate_data => true) | |
drop_column :<model>, :title | |
drop_column :<model>, :body | |
end | |
def self.down | |
add_column :<model>, :title, :string | |
add_column :<model>, :body, :text | |
<Model>.drop_translation_table! :migrate_data => true | |
end | |
end | |
# Don't forget to run `rake db:migrate`! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 2: Add required translation stuff inside your model. | |
# app/models/<model>.rb | |
class <Model> < ActiveRecord::Base | |
translates :title, :body | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Override view=admin/<model>/_form and edit it. After the following: | |
<%= form_for [:admin, @<model>], url_opts do |f| %> | |
<%= render :partial => "/shared/admin/error_messages", | |
:locals => { | |
:object => @<model>, | |
:include_object_name => true | |
} %> | |
# Insert... | |
<%= render :partial => "/shared/admin/locale_picker", | |
:locals => { | |
:current_locale => Thread.current[:globalize_locale] | |
} if ::Refinery.i18n_enabled? %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Override view=admin/<model>/_<model> and edit it. Change the top bit to look something like this: | |
<span class='title'> | |
<%= <model>.name %> | |
<% if ::Refinery.i18n_enabled? and ::Refinery::I18n.frontend_locales.many? and (locales = <model>.translations.map(&:locale)).present? %> | |
<span class='preview'> | |
<% ([<model>.translation.try(:locale)] | locales).each do |locale| %> | |
<%= link_to refinery_icon_tag("flags/#{locale}.png", :size => '16x11'), edit_admin_<model>_path(<model>, :switch_locale => locale), :class => 'locale' %> | |
<% end %> | |
</span> | |
<% end %> | |
</span> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some notes for Refinery 2.0.x
Step 1 - drop_column isn't valid - should be remove_column
Step 2 - model needs: