solidus_i18n 1.3.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +35 -50
- data/config/routes.rb +0 -14
- data/lib/solidus_i18n.rb +0 -5
- data/lib/solidus_i18n/engine.rb +0 -39
- data/lib/solidus_i18n/version.rb +2 -2
- data/solidus_i18n.gemspec +0 -13
- data/spec/{lib/solidus_i18n/locale_spec.rb → solidus_i18n_spec.rb} +16 -4
- data/spec/spec_helper.rb +0 -1
- metadata +3 -242
- data/app/assets/javascripts/spree/backend/edit_inline_locales.js.coffee.erb +0 -56
- data/app/assets/javascripts/spree/backend/helpers.js.coffee.erb +0 -14
- data/app/assets/javascripts/spree/backend/inline_table_locales.js.coffee +0 -16
- data/app/assets/javascripts/spree/backend/solidus_i18n.js +0 -2
- data/app/assets/javascripts/spree/backend/templates/available_locales.hbs.erb +0 -31
- data/app/assets/javascripts/spree/backend/translations.js.coffee +0 -3
- data/app/assets/javascripts/spree/frontend/locale.js.coffee +0 -3
- data/app/assets/javascripts/spree/frontend/solidus_i18n.js +0 -2
- data/app/assets/stylesheets/spree/backend/solidus_i18n.css +0 -8
- data/app/assets/stylesheets/spree/frontend/solidus_i18n.css +0 -8
- data/app/controllers/spree/admin/locales_controller.rb +0 -16
- data/app/controllers/spree/api/available_locales_controller.rb +0 -28
- data/app/controllers/spree/api/base_controller_decorator.rb +0 -3
- data/app/controllers/spree/base_controller_decorator.rb +0 -3
- data/app/controllers/spree/locale_controller_decorator.rb +0 -5
- data/app/helpers/solidus_i18n/locale_helper.rb +0 -29
- data/app/models/spree/store_decorator.rb +0 -13
- data/app/overrides/spree/admin/shared/_configuration_menu/add_i18n_tab.html.erb.deface +0 -2
- data/app/overrides/spree/shared/_main_nav_bar/locale_selector.html.erb.deface +0 -16
- data/app/views/spree/admin/locales/show.html.erb +0 -21
- data/app/views/spree/api/available_locales/show.json.jbuilder +0 -8
- data/config/initializers/country_names.rb +0 -51
- data/config/initializers/routing_filter.rb +0 -2
- data/db/migrate/20150609154031_remove_translations_from_spree_tables.rb +0 -65
- data/db/migrate/20170523151209_add_available_locales_on_store.rb +0 -14
- data/lib/generators/solidus_i18n/install/install_generator.rb +0 -27
- data/lib/solidus_i18n/configuration.rb +0 -9
- data/lib/solidus_i18n/controller_locale_helper.rb +0 -29
- data/lib/solidus_i18n/locale.rb +0 -9
- data/spec/controllers/locales_controller_spec.rb +0 -25
- data/spec/features/admin/translations_spec.rb +0 -56
- data/spec/features/russian_errors_translation_spec.rb +0 -17
- data/spec/features/translation_spec.rb +0 -31
- data/spec/features/translations_spec.rb +0 -30
- data/spec/helpers/locale_helper_spec.rb +0 -35
- data/spec/support/capybara.rb +0 -6
- data/spec/support/database_cleaner.rb +0 -23
- data/spec/support/factory_girl.rb +0 -5
- data/spec/support/i18n.rb +0 -5
- data/spec/support/spree.rb +0 -12
@@ -1,56 +0,0 @@
|
|
1
|
-
Spree.EditInlineLocales = Backbone.View.extend(
|
2
|
-
initialize: ->
|
3
|
-
@editing = false
|
4
|
-
@render()
|
5
|
-
|
6
|
-
events:
|
7
|
-
'click [data-action=edit]': 'onEdit'
|
8
|
-
'click [data-action=save]': 'onSave'
|
9
|
-
'click [data-action=cancel]': 'onCancel'
|
10
|
-
|
11
|
-
onEdit: (e) ->
|
12
|
-
return if @editing
|
13
|
-
@$el.addClass 'editing'
|
14
|
-
@editing = true
|
15
|
-
@render()
|
16
|
-
|
17
|
-
onCancel: (e) ->
|
18
|
-
e.preventDefault()
|
19
|
-
@$el.removeClass("editing")
|
20
|
-
@editing = false
|
21
|
-
@render()
|
22
|
-
|
23
|
-
onSave: (e) ->
|
24
|
-
e.preventDefault()
|
25
|
-
preferred_available_locales = $('#available-locales-store-' + @model.id)
|
26
|
-
Spree.ajax
|
27
|
-
type: 'PUT'
|
28
|
-
url: Spree.routes.available_locales_api + '/' + @model.id + '.json'
|
29
|
-
data:
|
30
|
-
store:
|
31
|
-
preferred_available_locales: preferred_available_locales.val()
|
32
|
-
success: (response) =>
|
33
|
-
@model = response.store
|
34
|
-
@editing = false
|
35
|
-
@$el.removeClass("editing")
|
36
|
-
@render()
|
37
|
-
error: (response) =>
|
38
|
-
show_flash 'error', response.responseJSON.error
|
39
|
-
|
40
|
-
render: ->
|
41
|
-
renderAttr =
|
42
|
-
availableLocales: <%= SolidusI18n::Locale.all.push(:en).to_json %>
|
43
|
-
availableLocalesPresentation: <%= Hash[(SolidusI18n::Locale.all + [:en]).map do |locale|
|
44
|
-
[locale, Spree.t(:'i18n.this_file_language', locale: locale)]
|
45
|
-
end].to_json %>
|
46
|
-
store: @model
|
47
|
-
editing: @editing
|
48
|
-
_.extend(renderAttr, @model.attributes)
|
49
|
-
|
50
|
-
@$el.html(HandlebarsTemplates['available_locales'](renderAttr))
|
51
|
-
$('.available-locales').select2({placeholder: Spree.translations['please_choose_language'], width: 'element'})
|
52
|
-
|
53
|
-
return @
|
54
|
-
)
|
55
|
-
|
56
|
-
Spree.routes.available_locales_api = Spree.pathFor('api/config/available_locales');
|
@@ -1,14 +0,0 @@
|
|
1
|
-
window.Handlebars.registerHelper 'locale-presentation', (locale, localePresentationHashmap, options) ->
|
2
|
-
localePresentationHashmap[locale]
|
3
|
-
|
4
|
-
window.Handlebars.registerHelper 'selected', (locale, store, options) ->
|
5
|
-
for k of store.preferences.available_locales
|
6
|
-
value = store.preferences.available_locales[k]
|
7
|
-
return 'selected="selected"' if value == locale
|
8
|
-
|
9
|
-
window.Handlebars.registerHelper 'store-available-locales', (store, options) ->
|
10
|
-
locales = for k of store.preferences.available_locales
|
11
|
-
locale = store.preferences.available_locales[k]
|
12
|
-
@availableLocalesPresentation[locale]
|
13
|
-
|
14
|
-
locales.join(',')
|
@@ -1,16 +0,0 @@
|
|
1
|
-
Spree.InlineTableLocales = Backbone.View.extend(
|
2
|
-
initialize: ->
|
3
|
-
if @$el.length
|
4
|
-
Spree.ajax({
|
5
|
-
type: 'GET'
|
6
|
-
url: "/api/config/available_locales"
|
7
|
-
success: (collection) =>
|
8
|
-
for store in collection
|
9
|
-
row = $("<tr id='store-id-#{store.id}'/>")
|
10
|
-
@$el.append(row)
|
11
|
-
new Spree.EditInlineLocales({
|
12
|
-
el: row
|
13
|
-
model: store
|
14
|
-
});
|
15
|
-
})
|
16
|
-
)
|
@@ -1,31 +0,0 @@
|
|
1
|
-
<td>
|
2
|
-
{{store.name}}
|
3
|
-
{{#if store.default}}
|
4
|
-
<span class="label label-default">default</span>
|
5
|
-
{{/if}}
|
6
|
-
</td>
|
7
|
-
<td>{{store.url}}</td>
|
8
|
-
<td>
|
9
|
-
{{#if editing}}
|
10
|
-
<select id='available-locales-store-{{store.id}}' class='available-locales select2 fullwidth' name='store[preferred_available_locales][]' multiple='true'>
|
11
|
-
{{#each availableLocales}}
|
12
|
-
<option value="{{ this }}" {{#selected this ../store}}{{/selected}}>
|
13
|
-
{{#locale-presentation this ../availableLocalesPresentation}}{{/locale-presentation}}
|
14
|
-
</option>
|
15
|
-
{{/each}}
|
16
|
-
</select>
|
17
|
-
{{else}}
|
18
|
-
{{store-available-locales store availableLocales}}
|
19
|
-
{{#each store.preferences.available_locales}}
|
20
|
-
{{locale-presentation this}}
|
21
|
-
{{/each}}
|
22
|
-
{{/if}}
|
23
|
-
</td>
|
24
|
-
<td class="actions">
|
25
|
-
{{#if editing}}
|
26
|
-
<a class="fa fa-check icon_link with-tip no-text" data-action="save" data-id="{{id}}" href="#"></a>
|
27
|
-
<a class="fa fa-cancel icon_link with-tip no-text" data-action="cancel" data-id="{{id}}" href="#"></a>
|
28
|
-
{{else}}
|
29
|
-
<a class="fa fa-edit icon_link with-tip no-text" data-action="edit" data-id="{{id}}" href="#"></a>
|
30
|
-
{{/if}}
|
31
|
-
</td>
|
@@ -1,8 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* This is a manifest file that'll automatically include all the stylesheets available in this directory
|
3
|
-
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
|
4
|
-
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
5
|
-
*
|
6
|
-
*= require spree/backend
|
7
|
-
*= require_tree .
|
8
|
-
*/
|
@@ -1,8 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* This is a manifest file that'll automatically include all the stylesheets available in this directory
|
3
|
-
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
|
4
|
-
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
5
|
-
*
|
6
|
-
*= require spree/frontend
|
7
|
-
*= require_tree .
|
8
|
-
*/
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Admin
|
3
|
-
class LocalesController < Spree::Admin::BaseController
|
4
|
-
def show
|
5
|
-
end
|
6
|
-
|
7
|
-
def update
|
8
|
-
params.each do |name, value|
|
9
|
-
next unless SolidusI18n::Config.has_preference? name
|
10
|
-
SolidusI18n::Config[name] = value.map(&:to_sym)
|
11
|
-
end
|
12
|
-
redirect_to admin_locale_path
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
class AvailableLocalesController < Spree::Api::BaseController
|
4
|
-
def index
|
5
|
-
respond_with Store.all
|
6
|
-
end
|
7
|
-
|
8
|
-
def update
|
9
|
-
authorize! :update, store
|
10
|
-
if store.update_attributes(store_params)
|
11
|
-
respond_with(store, status: 200, default_template: :show)
|
12
|
-
else
|
13
|
-
invalid_resource!(store)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def store_params
|
20
|
-
params.require(:store).permit(preferred_available_locales: [])
|
21
|
-
end
|
22
|
-
|
23
|
-
def store
|
24
|
-
@store ||= Store.find(params[:id])
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module SolidusI18n
|
2
|
-
module LocaleHelper
|
3
|
-
def select_available_locales(store = nil)
|
4
|
-
select_tag('store[preferred_available_locales][]',
|
5
|
-
options_for_select(
|
6
|
-
all_locales_options,
|
7
|
-
store.preferred_available_locales
|
8
|
-
), common_options)
|
9
|
-
end
|
10
|
-
|
11
|
-
def available_locales_options
|
12
|
-
current_store.preferred_available_locales.map { |locale| locale_presentation(locale) }
|
13
|
-
end
|
14
|
-
|
15
|
-
def all_locales_options
|
16
|
-
SolidusI18n::Locale.all.map { |locale| locale_presentation(locale) }
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def locale_presentation(locale)
|
22
|
-
[Spree.t(:'i18n.this_file_language', locale: locale), locale]
|
23
|
-
end
|
24
|
-
|
25
|
-
def common_options
|
26
|
-
{ class: 'fullwidth', multiple: 'true' }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module SolidusI18n
|
2
|
-
module AddAvailableLanguagesPreferenceToStore
|
3
|
-
def self.prepended(base)
|
4
|
-
base.preference :available_locales, :array, default: [:en]
|
5
|
-
end
|
6
|
-
|
7
|
-
def preferred_available_locales
|
8
|
-
super.map(&:to_sym)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
Spree::Store.prepend AddAvailableLanguagesPreferenceToStore
|
13
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
<!-- insert_bottom '#main-nav-bar' -->
|
2
|
-
<% if current_store.preferred_available_locales.many? %>
|
3
|
-
<li id="locale-select" data-hook>
|
4
|
-
<%= form_tag spree.set_locale_path, class: 'navbar-form' do %>
|
5
|
-
<div class="form-group">
|
6
|
-
<label for="switch_to_locale" class="sr-only">
|
7
|
-
<%= Spree.t(:'i18n.language') %>
|
8
|
-
</label>
|
9
|
-
<%= select_tag(:switch_to_locale,
|
10
|
-
options_for_select(available_locales_options, I18n.locale),
|
11
|
-
class: 'form-control') %>
|
12
|
-
<noscript><%= submit_tag %></noscript>
|
13
|
-
</div>
|
14
|
-
<% end %>
|
15
|
-
</li>
|
16
|
-
<% end %>
|
@@ -1,21 +0,0 @@
|
|
1
|
-
<%= render 'spree/admin/shared/configuration_menu' %>
|
2
|
-
|
3
|
-
<table class="index locales-settings">
|
4
|
-
<thead>
|
5
|
-
<tr>
|
6
|
-
<th><%= Spree::Store.human_attribute_name(:name) %></th>
|
7
|
-
<th><%= Spree::Store.human_attribute_name(:url) %></th>
|
8
|
-
<th><%= Spree.t(:'i18n.locales_displayed_on_frontend_select_box') %></th>
|
9
|
-
<th class="actions"></th>
|
10
|
-
</tr>
|
11
|
-
</thead>
|
12
|
-
<tbody>
|
13
|
-
<%# Rendered by JS %>
|
14
|
-
</tbody>
|
15
|
-
</table>
|
16
|
-
|
17
|
-
<script>
|
18
|
-
Spree.ready(function(){
|
19
|
-
new Spree.InlineTableLocales({ el: $("table.locales-settings > tbody") });
|
20
|
-
})
|
21
|
-
</script>
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'i18n_data'
|
2
|
-
|
3
|
-
module I18n
|
4
|
-
module Backend
|
5
|
-
class I18nDataBackend
|
6
|
-
module Implementation
|
7
|
-
include Base, Flatten
|
8
|
-
|
9
|
-
def available_locales
|
10
|
-
I18nData.languages.keys.map(&:to_sym)
|
11
|
-
end
|
12
|
-
|
13
|
-
def lookup(locale, key, scope = [], options = {})
|
14
|
-
I18nData.countries(locale)[key]
|
15
|
-
rescue I18nData::NoTranslationAvailable
|
16
|
-
# rescue failed lookup to fall back to this extensions locale files.
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
include Implementation
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
I18n.backend = I18n::Backend::Chain.new(I18n::Backend::I18nDataBackend.new, I18n.backend)
|
26
|
-
|
27
|
-
module I18nData
|
28
|
-
private
|
29
|
-
|
30
|
-
def self.normal_to_region_code(normal)
|
31
|
-
country_mappings = {
|
32
|
-
'DE-CH' => 'de',
|
33
|
-
'FR-CH' => 'fr',
|
34
|
-
'EN-AU' => 'en',
|
35
|
-
'EN-GB' => 'en',
|
36
|
-
'EN-US' => 'en',
|
37
|
-
'EN-IN' => 'en',
|
38
|
-
'EN-NZ' => 'en',
|
39
|
-
'ES-CL' => 'es',
|
40
|
-
'ES-EC' => 'es',
|
41
|
-
'ES-MX' => 'es',
|
42
|
-
'PT-BR' => 'pt',
|
43
|
-
'SL-SI' => 'sl',
|
44
|
-
'ZH-TW' => 'zh_TW',
|
45
|
-
'ZH-CN' => 'zh_CN',
|
46
|
-
'ZH' => 'zh_CN',
|
47
|
-
'BN' => 'bn_IN'
|
48
|
-
}
|
49
|
-
country_mappings[normal] || normal
|
50
|
-
end
|
51
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
class RemoveTranslationsFromSpreeTables < SolidusSupport::Migration[4.2]
|
2
|
-
def up
|
3
|
-
# Don't migrate if we still use Globalize, i.e. through spree_globalize Gem
|
4
|
-
return if defined?(Globalize)
|
5
|
-
|
6
|
-
%w(
|
7
|
-
OptionType
|
8
|
-
OptionValue
|
9
|
-
ProductProperty
|
10
|
-
Product
|
11
|
-
Promotion
|
12
|
-
Property
|
13
|
-
Store
|
14
|
-
Taxon
|
15
|
-
Taxonomy
|
16
|
-
).each do |class_name|
|
17
|
-
migrate_translation_data!(class_name)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def down
|
22
|
-
return if defined?(Globalize)
|
23
|
-
raise ActiveRecord::IrreversibleMigration
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def current_locale
|
29
|
-
I18n.default_locale || 'en'
|
30
|
-
end
|
31
|
-
|
32
|
-
def migrate_translation_data!(class_name)
|
33
|
-
klass = "Spree::#{class_name}".constantize
|
34
|
-
table_name = klass.table_name
|
35
|
-
singular_table_name = table_name.singularize
|
36
|
-
|
37
|
-
return if !table_exists?(table_name) || !table_exists?("#{singular_table_name}_translations")
|
38
|
-
|
39
|
-
# We can't rely on Globalize drop_translation_table! here,
|
40
|
-
# because the Gem has been already removed, so we need to run custom SQL
|
41
|
-
records = exec_query("SELECT * FROM #{singular_table_name}_translations WHERE locale = '#{current_locale}';")
|
42
|
-
|
43
|
-
records.each do |record|
|
44
|
-
id = record["#{singular_table_name}_id"]
|
45
|
-
attributes = record.except(
|
46
|
-
'id',
|
47
|
-
"#{singular_table_name}_id",
|
48
|
-
'locale',
|
49
|
-
'deleted_at',
|
50
|
-
'created_at',
|
51
|
-
'updated_at'
|
52
|
-
)
|
53
|
-
object = if klass.respond_to?(:with_deleted)
|
54
|
-
klass.with_deleted.find(id)
|
55
|
-
else
|
56
|
-
klass.find(id)
|
57
|
-
end
|
58
|
-
object.update_columns(attributes)
|
59
|
-
end
|
60
|
-
|
61
|
-
say "Migrated #{current_locale} translation for #{class_name} back into original table."
|
62
|
-
|
63
|
-
drop_table "#{singular_table_name}_translations"
|
64
|
-
end
|
65
|
-
end
|