-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add globalize3 dependency * Include UI to translate product fields
- Loading branch information
Showing
25 changed files
with
380 additions
and
9 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ pkg | |
*.sw? | ||
spec/dummy | ||
.rvmrc | ||
.sass-cache |
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
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
38 changes: 38 additions & 0 deletions
38
app/assets/javascripts/admin/product_translations.js.coffee
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
display_locale_fields = () -> | ||
attr = $('#attr_list li.active a').data('attr') | ||
locales = $('select#locale').val() | ||
show = $("input[name='show-only']:checked").val() | ||
|
||
$('table#attr_fields tr').hide() | ||
|
||
for locale in locales | ||
do (locale) -> | ||
value = $('table#attr_fields tr.' + attr + '.' + locale + ' td.translation :input').val().replace /^\s+|\s+$/g, "" | ||
|
||
if show == 'incomplete' | ||
display = value == '' | ||
else if show == 'complete' | ||
display = value != '' | ||
else | ||
display = true | ||
|
||
if display | ||
$('table#attr_fields tr.' + attr + '.' + locale).show() | ||
|
||
if $('table#attr_fields tr:visible').length == 0 and show != 'all' | ||
$('table#attr_fields tfoot tr').show() | ||
$('table#attr_fields tfoot td').html('No <strong>' + show + '</strong> translations for <strong>' + attr + '</strong>.') | ||
|
||
|
||
$ -> | ||
$('#attr_list a').click -> | ||
$('#attr_list li').removeClass('active') | ||
$(this).parent().addClass('active') | ||
|
||
display_locale_fields() | ||
false | ||
|
||
$('select#locale').select2({placeholder: 'Please select a language.'}) | ||
$('select#locale').change display_locale_fields | ||
$("input[name='show-only']").change display_locale_fields | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
//= require_tree . |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
$ -> | ||
$('#locale-select select').change -> | ||
$.ajax( | ||
type: 'POST' | ||
url: $(this).data('href') | ||
data: | ||
locale: $(this).val() | ||
).done -> | ||
window.location.reload() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
//= require_tree . |
Empty file.
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Spree | ||
class Admin::TranslationsController < Admin::BaseController | ||
before_filter :load_parent | ||
|
||
helper_method :collection_url | ||
helper 'spree/locale' | ||
|
||
private | ||
|
||
def load_parent | ||
@product ||= Spree::Product.find_by_permalink(params[:product_id]) | ||
end | ||
|
||
def collection_url | ||
admin_product_url(load_parent) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Spree | ||
class LocaleController < Spree::StoreController | ||
def set | ||
session[:locale] = params[:locale] | ||
|
||
respond_to do |format| | ||
format.json { render :json => true } | ||
format.html { redirect_to root_path } | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Spree | ||
module LocaleHelper | ||
|
||
def options_for_locale_select() | ||
Spree::Config.supported_locales.map do |locale| | ||
[I18n.t(:this_file_language, :locale => locale), locale] | ||
end | ||
end | ||
|
||
def admin_options_for_locale_select() | ||
Spree::Config.all_locales.map do |locale| | ||
[I18n.t(:this_file_language, :locale => locale), locale] | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Spree::AppConfiguration.class_eval do | ||
preference :all_locales, :array, :default => ['en', 'es', 'de', 'pt-BR'] | ||
preference :supported_locales, :array, :default => ['en', 'es', 'de', 'pt-BR'] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Spree | ||
Product.class_eval do | ||
translates :name, :description, :meta_description, :meta_keywords | ||
|
||
attr_accessible :translations_attributes | ||
|
||
accepts_nested_attributes_for :translations | ||
end | ||
end |
13 changes: 13 additions & 0 deletions
13
app/overrides/spree/shared/_main_nav_bar/locale_selector.html.erb.deface
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- insert_bottom '#main-nav-bar' --> | ||
<% if Spree::Config.supported_locales.size > 1 %> | ||
<li id="locale-select" style="float: right; margin-right: 10px;" data-hook> | ||
<%= form_tag(set_locale_path(:format => :html)) do %> | ||
<label for="locale"><%= t(:language) %>:</label> | ||
<%= select_tag(:locale, options_for_select(options_for_locale_select, I18n.locale), | ||
:data => { :href => set_locale_path(:format => :json) }) %> | ||
<noscript> | ||
<%= submit_tag %> | ||
</noscript> | ||
<% end %> | ||
</li> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<%= render :partial => 'spree/admin/shared/product_sub_menu' %> | ||
<%= render :partial => 'spree/admin/shared/product_tabs', :locals => { :current => 'Translations' } %> | ||
<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @product } %> | ||
<% content_for :page_actions do %> | ||
<li> | ||
<%= link_to_add_fields t(:add_product_translations), 'tbody#product_properties', :class => 'icon-plus button' %> | ||
</li> | ||
<% end %> | ||
|
||
<div class="row"> | ||
<fieldset class="no-border-top"> | ||
<fieldset class="no-border-bottom"> | ||
<legend>Settings</legend> | ||
|
||
<div class="alpha six columns field"> | ||
<label for="show-only">Show only: </label> | ||
<ul> | ||
<li><input type="radio" name="show-only" value="all" checked> <label>All Translations</label></li> | ||
<li><input type="radio" name="show-only" value="incomplete"> <label>Only Incomplete</label></li> | ||
<li><input type="radio" name="show-only"value="complete"> <label>Only Complete</label></li> | ||
</ul> | ||
</div> | ||
|
||
<div class="omega six columns"> | ||
<label for="locale">Select locale: </label> | ||
<%= select_tag(:locale, options_for_select(admin_options_for_locale_select, Spree::Config.all_locales), :class => 'fullwidth' , :multiple => 'true') %> | ||
</div> | ||
</fieldset> | ||
|
||
<fieldset class="alpha four columns no-border-bottom"> | ||
<legend>Product fields</legend> | ||
<nav class="menu"> | ||
<ul id="attr_list"> | ||
<% @product.class.translates.each_with_index do |attr,i| %> | ||
<li class="<%= 'active' if i == 0 %>"> | ||
<a data-attr="<%= attr %>" href="#"><%= attr %></a> | ||
</li> | ||
<% end %> | ||
</ul> | ||
</nav> | ||
</fieldset> | ||
|
||
<%= form_for [:admin, @product], :method => :put, :html => { :multipart => true } do |f| %> | ||
<fieldset class="omega eight columns no-border-bottom"> | ||
<legend>Translations</legend> | ||
<table id="attr_fields" class="no-borders"> | ||
<colgroup> | ||
<col style="width: 10%" /> | ||
<col style="width: 90%" /> | ||
</colgroup> | ||
<tbody> | ||
<% Spree::Config.all_locales.each do |locale| %> | ||
<%= f.globalize_fields_for locale.to_sym do |g| %> | ||
<% @product.class.translates.each_with_index do |attr,i| %> | ||
<tr style="display:<%= i == 0 ? 'auto' : 'none' %>;" class="<%= attr %> <%= locale %> even"> | ||
<td style="padding:4px;" colspan="2"> | ||
<%= t(:this_file_language, :locale => locale) %> - | ||
<%= t(attr, :locale => locale ) %> | ||
</td> | ||
</tr> | ||
<tr style="display:<%= i == 0 ? 'auto' : 'none' %>;" class="<%= attr %> <%= locale %> odd"> | ||
<td class="flag table-column"> | ||
<% if locale.include?('-') %> | ||
<img src="http://www.localeapp.com/assets/flags/regions/<%= locale.split('-').last %>.png"> | ||
<% else %> | ||
<img src="http://www.localeapp.com/assets/flags/languages/<%= locale %>.png"> | ||
<% end %> | ||
</td> | ||
<td class="translation table-column"> | ||
<% if @product.class.columns_hash[attr.to_s].type == :text %> | ||
<%= g.text_area attr, :class => "fullwidth", :rows => 4 %> | ||
<% else %> | ||
<%= g.text_field attr, :class => "fullwidth" %> | ||
<% end %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
</tbody> | ||
<tfoot> | ||
<tr style="display:none;"> | ||
<td colspan="2"></td> | ||
</tr> | ||
</tfoot> | ||
</table> | ||
|
||
</fieldset> | ||
<%= render :partial => 'spree/admin/shared/edit_resource_links' %> | ||
<% end %> | ||
</fieldset> | ||
</div> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module ActionView | ||
module Helpers | ||
class FormBuilder | ||
# | ||
# Helper that renders globalize_translations fields | ||
# on a per-locale basis, so you can use them separately | ||
# in the same form and still saving them all at once | ||
# in the same request. | ||
# | ||
# Use it like this: | ||
# | ||
# <h1>Editing post</h1> | ||
# | ||
# <% form_for(@post) do |f| %> | ||
# <%= f.error_messages %> | ||
# | ||
# <h2>English (default locale)</h2> | ||
# <p><%= f.text_field :title %></p> | ||
# <p><%= f.text_field :teaser %></p> | ||
# <p><%= f.text_field :body %></p> | ||
# | ||
# <hr/> | ||
# | ||
# <h2>Spanish translation</h2> | ||
# <% f.globalize_fields_for :es do |g| %> | ||
# <p><%= g.text_field :title %></p> | ||
# <p><%= g.text_field :teaser %></p> | ||
# <p><%= g.text_field :body %></p> | ||
# <% end %> | ||
# | ||
# <hr/> | ||
# | ||
# <h2>French translation</h2> | ||
# <% f.globalize_fields_for :fr do |g| %> | ||
# <p><%= g.text_field :title %></p> | ||
# <p><%= g.text_field :teaser %></p> | ||
# <p><%= g.text_field :body %></p> | ||
# <% end %> | ||
# | ||
# <% end %> | ||
# | ||
def globalize_fields_for(locale, *args, &proc) | ||
raise ArgumentError, "Missing block" unless block_given? | ||
@index = @index ? @index + 1 : 1 | ||
object_name = "#{@object_name}[translations_attributes][#{@index}]" | ||
object = @object.translation_for(locale) | ||
@template.concat @template.hidden_field_tag("#{object_name}[id]", object ? object.id : "") | ||
@template.concat @template.hidden_field_tag("#{object_name}[locale]", locale) | ||
@template.fields_for(object_name, object, *args, &proc) | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Sample localization file for English. Add more files in this directory for other locales. | ||
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. | ||
|
||
en: | ||
this_file_language: "English (US)" |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class AddTranslationsToProducts < ActiveRecord::Migration | ||
def up | ||
params = { :name => :string, | ||
:description => :text, | ||
:meta_description => :string, | ||
:meta_keywords => :string } | ||
Spree::Product.create_translation_table!(params, { :migrate_data => true }) | ||
end | ||
|
||
def down | ||
Spree::Product.drop_translation_table! :migrate_data => true | ||
end | ||
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
Oops, something went wrong.