solidus_i18n 1.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +35 -0
- data/.gem_release.yml +5 -0
- data/.github/stale.yml +17 -0
- data/.gitignore +4 -8
- data/.hound.yml +1 -1
- data/.rspec +2 -0
- data/.rubocop.yml +3 -6
- data/.rubocop_todo.yml +18 -0
- data/Gemfile +24 -6
- data/{LICENSE.md → LICENSE} +2 -2
- data/README.md +63 -29
- data/Rakefile +10 -73
- data/bin/console +17 -0
- data/bin/rails +12 -4
- data/bin/setup +8 -0
- data/config/locales/bg.yml +1 -47
- data/config/locales/ca.yml +12 -49
- data/config/locales/cs.yml +1 -48
- data/config/locales/da.yml +238 -139
- data/config/locales/de-CH.yml +0 -48
- data/config/locales/de.yml +476 -102
- data/config/locales/en-AU.yml +0 -48
- data/config/locales/en-GB.yml +1 -47
- data/config/locales/en-IN.yml +2 -48
- data/config/locales/en-NZ.yml +0 -48
- data/config/locales/es-CL.yml +1 -49
- data/config/locales/es-EC.yml +1 -47
- data/config/locales/es-MX.yml +417 -111
- data/config/locales/es.yml +1525 -797
- data/config/locales/et.yml +0 -50
- data/config/locales/fa.yml +0 -48
- data/config/locales/fi.yml +1 -47
- data/config/locales/fr.yml +677 -275
- data/config/locales/id.yml +2 -46
- data/config/locales/it.yml +1303 -445
- data/config/locales/ja.yml +598 -536
- data/config/locales/ko.yml +0 -48
- data/config/locales/lv.yml +0 -48
- data/config/locales/nb.yml +0 -48
- data/config/locales/nl.yml +1 -47
- data/config/locales/pl.yml +1 -47
- data/config/locales/pt-BR.yml +1101 -249
- data/config/locales/pt.yml +0 -48
- data/config/locales/ro.yml +3 -48
- data/config/locales/ru.yml +1884 -1237
- data/config/locales/sk.yml +722 -577
- data/config/locales/sl-SI.yml +0 -48
- data/config/locales/sv.yml +1 -47
- data/config/locales/th.yml +1 -45
- data/config/locales/tr.yml +1 -45
- data/config/locales/uk.yml +370 -381
- data/config/locales/vi.yml +1 -45
- data/config/locales/zh-CN.yml +1 -45
- data/config/locales/zh-TW.yml +1 -45
- data/config/routes.rb +2 -4
- data/i18n-tasks.yml +4 -0
- data/lib/generators/solidus_i18n/install/install_generator.rb +10 -13
- data/lib/solidus_i18n.rb +5 -6
- data/lib/solidus_i18n/engine.rb +9 -36
- data/lib/solidus_i18n/factories.rb +4 -0
- data/lib/solidus_i18n/version.rb +3 -16
- data/lib/tasks/solidus_i18n/upgrade.rake +13 -11
- data/solidus_i18n.gemspec +29 -39
- data/spec/solidus_i18n_spec.rb +67 -0
- data/spec/spec_helper.rb +15 -13
- metadata +231 -292
- data/.travis.yml +0 -12
- data/Guardfile +0 -11
- data/app/assets/javascripts/spree/backend/solidus_i18n.js +0 -2
- data/app/assets/javascripts/spree/backend/translations.js.coffee +0 -5
- data/app/assets/javascripts/spree/frontend/cart_decorator.js.coffee +0 -5
- 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/general_settings_controller_decorator.rb +0 -12
- 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 -6
- data/app/helpers/solidus_i18n/locale_helper.rb +0 -31
- data/app/overrides/spree/admin/general_settings/edit/localization_settings.html.erb.deface +0 -20
- data/app/overrides/spree/shared/_main_nav_bar/cart_link.html.erb.deface +0 -9
- data/app/overrides/spree/shared/_main_nav_bar/locale_selector.html.erb.deface +0 -16
- 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/lib/solidus_i18n/configuration.rb +0 -9
- data/lib/solidus_i18n/controller_locale_helper.rb +0 -29
- data/lib/solidus_i18n/locale.rb +0 -13
- data/lib/solidus_i18n/utils.rb +0 -56
- data/spec/controllers/locales_controller_spec.rb +0 -24
- data/spec/features/admin/translations_spec.rb +0 -33
- 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 -28
- data/spec/support/capybara.rb +0 -11
- 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
data/.travis.yml
DELETED
data/Guardfile
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
group :red_green_refactor, halt_on_fail: true do
|
2
|
-
guard 'rspec', cmd: 'bundle exec rspec' do
|
3
|
-
watch('spec/spec_helper.rb') { 'spec' }
|
4
|
-
watch('config/routes.rb') { 'spec/controllers' }
|
5
|
-
watch(%r{^spec/(.+)_spec\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
6
|
-
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
7
|
-
watch(%r{^app/(.*)(\.erb)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
8
|
-
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
9
|
-
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb" }
|
10
|
-
end
|
11
|
-
end
|
@@ -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,12 +0,0 @@
|
|
1
|
-
Spree::Admin::GeneralSettingsController.class_eval do
|
2
|
-
before_filter :update_i18n_settings, only: :update
|
3
|
-
|
4
|
-
private
|
5
|
-
|
6
|
-
def update_i18n_settings
|
7
|
-
params.each do |name, value|
|
8
|
-
next unless SolidusI18n::Config.has_preference? name
|
9
|
-
SolidusI18n::Config[name] = value.map(&:to_sym)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module SolidusI18n
|
2
|
-
module LocaleHelper
|
3
|
-
|
4
|
-
def select_available_locales
|
5
|
-
select_tag('available_locales[]', options_for_select(
|
6
|
-
all_locales_options,
|
7
|
-
Config.available_locales
|
8
|
-
), common_options)
|
9
|
-
end
|
10
|
-
|
11
|
-
def available_locales_options
|
12
|
-
Config.available_locales.map { |locale| locale_presentation(locale) }
|
13
|
-
end
|
14
|
-
|
15
|
-
# Need to manually add en to the array because the en.yml was moved from
|
16
|
-
# this project. solidusio/solidus now has those keys.
|
17
|
-
def all_locales_options
|
18
|
-
Locale.all.map { |locale| locale_presentation(locale) }.push(['English (EN)', :en])
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def locale_presentation(locale)
|
24
|
-
[Spree.t(:'i18n.this_file_language', locale: locale), locale]
|
25
|
-
end
|
26
|
-
|
27
|
-
def common_options
|
28
|
-
{ class: 'fullwidth', multiple: 'true' }
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
<!-- insert_after '[data-hook=admin_general_setting_mail_from_address]'-->
|
2
|
-
<div class="panel panel-default panel-localization">
|
3
|
-
<div class="panel-heading">
|
4
|
-
<h1 class="panel-title">
|
5
|
-
<%= Spree.t(:'i18n.localization_settings') %>
|
6
|
-
</h1>
|
7
|
-
</div>
|
8
|
-
|
9
|
-
<div class="panel-body" data-hook="localization_settings_body">
|
10
|
-
<div class="form-group">
|
11
|
-
<label for="available_locales_">
|
12
|
-
<%= Spree.t(:'i18n.available_locales') %>
|
13
|
-
</label>
|
14
|
-
<%= select_available_locales %>
|
15
|
-
<p class="help-block">
|
16
|
-
<%= Spree.t(:'i18n.locales_displayed_on_frontend_select_box') %>
|
17
|
-
</p>
|
18
|
-
</div>
|
19
|
-
</div>
|
20
|
-
</div>
|
@@ -1,9 +0,0 @@
|
|
1
|
-
<!-- replace_contents '#main-nav-bar' -->
|
2
|
-
<li id="home-link" data-hook><%= link_to Spree.t(:home), spree.root_path %></li>
|
3
|
-
<li id="link-to-cart" data-hook>
|
4
|
-
<noscript>
|
5
|
-
<%= link_to Spree.t(:cart), '/cart' %>
|
6
|
-
</noscript>
|
7
|
-
|
8
|
-
</li>
|
9
|
-
<script>Spree.fetch_cart('<%= j cart_link_url %>')</script>
|
@@ -1,16 +0,0 @@
|
|
1
|
-
<!-- insert_bottom '#main-nav-bar' -->
|
2
|
-
<% if SolidusI18n::Config.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,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 < ActiveRecord::Migration
|
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
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module SolidusI18n
|
2
|
-
# The fact this logic is in a single module also helps to apply a custom
|
3
|
-
# locale on the spree/api context since api base controller inherits from
|
4
|
-
# MetalController instead of Spree::BaseController
|
5
|
-
module ControllerLocaleHelper
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do
|
9
|
-
prepend_before_filter :set_user_language
|
10
|
-
|
11
|
-
private
|
12
|
-
|
13
|
-
# Overrides the Spree::Core::ControllerHelpers::Common logic so that only
|
14
|
-
# supported locales defined by SolidusI18n::Config.supported_locales can
|
15
|
-
# actually be set
|
16
|
-
def set_user_language
|
17
|
-
# params[:locale] can be added by routing-filter gem
|
18
|
-
I18n.locale = \
|
19
|
-
if params[:locale] && Config.available_locales.include?(params[:locale].to_sym)
|
20
|
-
params[:locale]
|
21
|
-
elsif respond_to?(:config_locale, true) && !config_locale.blank?
|
22
|
-
config_locale
|
23
|
-
else
|
24
|
-
Rails.application.config.i18n.default_locale || I18n.default_locale
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/lib/solidus_i18n/locale.rb
DELETED
data/lib/solidus_i18n/utils.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext'
|
2
|
-
|
3
|
-
module SolidusI18n
|
4
|
-
module Utils
|
5
|
-
# Retrieve comments, translation data in hash form
|
6
|
-
def read_file(filename, basename)
|
7
|
-
# Add error checking for failed file read?
|
8
|
-
(comments, data) = IO.read(filename).split(/#{basename}:\s*\n/)
|
9
|
-
return comments, create_hash(data)
|
10
|
-
end
|
11
|
-
module_function :read_file
|
12
|
-
|
13
|
-
# Creates hash of translation data
|
14
|
-
def create_hash(data)
|
15
|
-
words = {}
|
16
|
-
return words unless data
|
17
|
-
parent = []
|
18
|
-
previous_key = 'base'
|
19
|
-
data.split("\n").each do |w|
|
20
|
-
next if w.strip.blank? || w.strip[0] == '#'
|
21
|
-
(key, value) = w.split(':', 2)
|
22
|
-
value ||= ''
|
23
|
-
# Determine level of current key in comparison to parent array
|
24
|
-
shift = (key =~ /\w/) / 2 - parent.size
|
25
|
-
key = key.sub(/^\s+/, '')
|
26
|
-
# If key is child of previous key, add previous key as parent
|
27
|
-
parent << previous_key if shift > 0
|
28
|
-
# If key is not related to previous key, remove parent keys
|
29
|
-
(shift*-1).times { parent.pop } if shift < 0
|
30
|
-
# Track key in case next key is child of this key
|
31
|
-
previous_key = key
|
32
|
-
words[parent.join(':') + ':' + key] = value
|
33
|
-
end
|
34
|
-
words
|
35
|
-
end
|
36
|
-
module_function :create_hash
|
37
|
-
|
38
|
-
# Writes to file from translation data hash structure
|
39
|
-
def write_file(filename, basename, _comments, words, comment_values = true, _fallback_values = {})
|
40
|
-
File.open(filename, 'w') do |log|
|
41
|
-
log.puts(basename + ": \n")
|
42
|
-
words.sort.each do |k, v|
|
43
|
-
keys = k.split(':')
|
44
|
-
# Add indentation for children keys
|
45
|
-
(keys.size - 1).times do
|
46
|
-
keys[keys.size - 1] = ' ' + keys[keys.size - 1]
|
47
|
-
end
|
48
|
-
value = v.strip
|
49
|
-
value = ('#' + value) if comment_values && !value.blank?
|
50
|
-
log.puts "#{keys[keys.size - 1]}: #{value}\n"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
module_function :write_file
|
55
|
-
end
|
56
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Spree::HomeController, type: :controller do
|
4
|
-
routes { Spree::Core::Engine.routes }
|
5
|
-
|
6
|
-
before do
|
7
|
-
reset_spree_preferences
|
8
|
-
SolidusI18n::Config.available_locales = [:en, :es]
|
9
|
-
end
|
10
|
-
|
11
|
-
context 'tries not supported fr locale' do
|
12
|
-
it 'falls back do default locale' do
|
13
|
-
get :index, locale: 'fr'
|
14
|
-
expect(I18n.locale).to eq :en
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'tries supported es locale' do
|
19
|
-
it 'takes this locale' do
|
20
|
-
get :index, locale: 'es'
|
21
|
-
expect(I18n.locale).to eq :es
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|