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.
Files changed (101) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +35 -0
  3. data/.gem_release.yml +5 -0
  4. data/.github/stale.yml +17 -0
  5. data/.gitignore +4 -8
  6. data/.hound.yml +1 -1
  7. data/.rspec +2 -0
  8. data/.rubocop.yml +3 -6
  9. data/.rubocop_todo.yml +18 -0
  10. data/Gemfile +24 -6
  11. data/{LICENSE.md → LICENSE} +2 -2
  12. data/README.md +63 -29
  13. data/Rakefile +10 -73
  14. data/bin/console +17 -0
  15. data/bin/rails +12 -4
  16. data/bin/setup +8 -0
  17. data/config/locales/bg.yml +1 -47
  18. data/config/locales/ca.yml +12 -49
  19. data/config/locales/cs.yml +1 -48
  20. data/config/locales/da.yml +238 -139
  21. data/config/locales/de-CH.yml +0 -48
  22. data/config/locales/de.yml +476 -102
  23. data/config/locales/en-AU.yml +0 -48
  24. data/config/locales/en-GB.yml +1 -47
  25. data/config/locales/en-IN.yml +2 -48
  26. data/config/locales/en-NZ.yml +0 -48
  27. data/config/locales/es-CL.yml +1 -49
  28. data/config/locales/es-EC.yml +1 -47
  29. data/config/locales/es-MX.yml +417 -111
  30. data/config/locales/es.yml +1525 -797
  31. data/config/locales/et.yml +0 -50
  32. data/config/locales/fa.yml +0 -48
  33. data/config/locales/fi.yml +1 -47
  34. data/config/locales/fr.yml +677 -275
  35. data/config/locales/id.yml +2 -46
  36. data/config/locales/it.yml +1303 -445
  37. data/config/locales/ja.yml +598 -536
  38. data/config/locales/ko.yml +0 -48
  39. data/config/locales/lv.yml +0 -48
  40. data/config/locales/nb.yml +0 -48
  41. data/config/locales/nl.yml +1 -47
  42. data/config/locales/pl.yml +1 -47
  43. data/config/locales/pt-BR.yml +1101 -249
  44. data/config/locales/pt.yml +0 -48
  45. data/config/locales/ro.yml +3 -48
  46. data/config/locales/ru.yml +1884 -1237
  47. data/config/locales/sk.yml +722 -577
  48. data/config/locales/sl-SI.yml +0 -48
  49. data/config/locales/sv.yml +1 -47
  50. data/config/locales/th.yml +1 -45
  51. data/config/locales/tr.yml +1 -45
  52. data/config/locales/uk.yml +370 -381
  53. data/config/locales/vi.yml +1 -45
  54. data/config/locales/zh-CN.yml +1 -45
  55. data/config/locales/zh-TW.yml +1 -45
  56. data/config/routes.rb +2 -4
  57. data/i18n-tasks.yml +4 -0
  58. data/lib/generators/solidus_i18n/install/install_generator.rb +10 -13
  59. data/lib/solidus_i18n.rb +5 -6
  60. data/lib/solidus_i18n/engine.rb +9 -36
  61. data/lib/solidus_i18n/factories.rb +4 -0
  62. data/lib/solidus_i18n/version.rb +3 -16
  63. data/lib/tasks/solidus_i18n/upgrade.rake +13 -11
  64. data/solidus_i18n.gemspec +29 -39
  65. data/spec/solidus_i18n_spec.rb +67 -0
  66. data/spec/spec_helper.rb +15 -13
  67. metadata +231 -292
  68. data/.travis.yml +0 -12
  69. data/Guardfile +0 -11
  70. data/app/assets/javascripts/spree/backend/solidus_i18n.js +0 -2
  71. data/app/assets/javascripts/spree/backend/translations.js.coffee +0 -5
  72. data/app/assets/javascripts/spree/frontend/cart_decorator.js.coffee +0 -5
  73. data/app/assets/javascripts/spree/frontend/locale.js.coffee +0 -3
  74. data/app/assets/javascripts/spree/frontend/solidus_i18n.js +0 -2
  75. data/app/assets/stylesheets/spree/backend/solidus_i18n.css +0 -8
  76. data/app/assets/stylesheets/spree/frontend/solidus_i18n.css +0 -8
  77. data/app/controllers/spree/admin/general_settings_controller_decorator.rb +0 -12
  78. data/app/controllers/spree/api/base_controller_decorator.rb +0 -3
  79. data/app/controllers/spree/base_controller_decorator.rb +0 -3
  80. data/app/controllers/spree/locale_controller_decorator.rb +0 -6
  81. data/app/helpers/solidus_i18n/locale_helper.rb +0 -31
  82. data/app/overrides/spree/admin/general_settings/edit/localization_settings.html.erb.deface +0 -20
  83. data/app/overrides/spree/shared/_main_nav_bar/cart_link.html.erb.deface +0 -9
  84. data/app/overrides/spree/shared/_main_nav_bar/locale_selector.html.erb.deface +0 -16
  85. data/config/initializers/country_names.rb +0 -51
  86. data/config/initializers/routing_filter.rb +0 -2
  87. data/db/migrate/20150609154031_remove_translations_from_spree_tables.rb +0 -65
  88. data/lib/solidus_i18n/configuration.rb +0 -9
  89. data/lib/solidus_i18n/controller_locale_helper.rb +0 -29
  90. data/lib/solidus_i18n/locale.rb +0 -13
  91. data/lib/solidus_i18n/utils.rb +0 -56
  92. data/spec/controllers/locales_controller_spec.rb +0 -24
  93. data/spec/features/admin/translations_spec.rb +0 -33
  94. data/spec/features/russian_errors_translation_spec.rb +0 -17
  95. data/spec/features/translation_spec.rb +0 -31
  96. data/spec/features/translations_spec.rb +0 -28
  97. data/spec/support/capybara.rb +0 -11
  98. data/spec/support/database_cleaner.rb +0 -23
  99. data/spec/support/factory_girl.rb +0 -5
  100. data/spec/support/i18n.rb +0 -5
  101. data/spec/support/spree.rb +0 -12
data/.travis.yml DELETED
@@ -1,12 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.1
4
- - 2.2
5
- env:
6
- - DB=mysql
7
- - DB=postgres
8
- sudo: false
9
- cache: bundler
10
- before_script:
11
- - bundle exec rake test_app
12
- script: bundle exec rspec spec
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,2 +0,0 @@
1
- //= require spree/backend
2
- //= require_tree .
@@ -1,5 +0,0 @@
1
- $ ->
2
- _.extend (Spree.translations),
3
- please_choose_language: "<%= Spree.t(:'i18n.choose_language') %>"
4
-
5
- $('#available_locales_').select2({placeholder: Spree.translations['please_choose_language']})
@@ -1,5 +0,0 @@
1
- Spree.fetch_cart = (cartLinkUrl) ->
2
- Spree.ajax
3
- url: cartLinkUrl || Spree.pathFor("cart_link"),
4
- success: (data) ->
5
- $('#link-to-cart').html data
@@ -1,3 +0,0 @@
1
- $ ->
2
- $('#locale-select select').change ->
3
- @form.submit()
@@ -1,2 +0,0 @@
1
- //= require spree/frontend
2
- //= require_tree .
@@ -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,3 +0,0 @@
1
- Spree::Api::BaseController.class_eval do
2
- include SolidusI18n::ControllerLocaleHelper
3
- end
@@ -1,3 +0,0 @@
1
- Spree::BaseController.class_eval do
2
- include SolidusI18n::ControllerLocaleHelper
3
- end
@@ -1,6 +0,0 @@
1
- Spree::LocaleController.class_eval do
2
- def set
3
- redirect_to root_path(locale: params[:switch_to_locale])
4
- end
5
- end
6
-
@@ -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
- &nbsp;
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,2 +0,0 @@
1
- # do not include the default locale in the URL
2
- RoutingFilter::Locale.include_default_locale = false
@@ -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,9 +0,0 @@
1
- module SolidusI18n
2
- class Configuration < Spree::Preferences::Configuration
3
- # These configs intend to, respectively:
4
- #
5
- # Set locales that should be available for end users
6
- #
7
- preference :available_locales, :array, default: [:en]
8
- end
9
- 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
@@ -1,13 +0,0 @@
1
- module SolidusI18n
2
- class Locale
3
- class << self
4
- def all
5
- Dir["#{dir}/*.yml"].map { |f| File.basename(f, '.yml').to_sym }
6
- end
7
-
8
- def dir
9
- File.join(File.dirname(__FILE__), '/../../config/locales')
10
- end
11
- end
12
- end
13
- end
@@ -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