solidus_i18n 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.hound.yml +25 -0
  4. data/.rubocop.yml +7 -0
  5. data/.travis.yml +12 -0
  6. data/CONTRIBUTING.md +70 -0
  7. data/Gemfile +13 -0
  8. data/Guardfile +11 -0
  9. data/LICENSE.md +26 -0
  10. data/README.md +74 -0
  11. data/Rakefile +85 -0
  12. data/app/assets/javascripts/spree/backend/solidus_i18n.js +2 -0
  13. data/app/assets/javascripts/spree/backend/translations.js.coffee +5 -0
  14. data/app/assets/javascripts/spree/frontend/cart_decorator.js.coffee +5 -0
  15. data/app/assets/javascripts/spree/frontend/locale.js.coffee +3 -0
  16. data/app/assets/javascripts/spree/frontend/solidus_i18n.js +2 -0
  17. data/app/assets/stylesheets/spree/backend/solidus_i18n.css +8 -0
  18. data/app/assets/stylesheets/spree/frontend/solidus_i18n.css +8 -0
  19. data/app/controllers/spree/admin/general_settings_controller_decorator.rb +12 -0
  20. data/app/controllers/spree/api/base_controller_decorator.rb +3 -0
  21. data/app/controllers/spree/base_controller_decorator.rb +3 -0
  22. data/app/controllers/spree/locale_controller_decorator.rb +6 -0
  23. data/app/helpers/solidus_i18n/locale_helper.rb +31 -0
  24. data/app/overrides/spree/admin/general_settings/edit/localization_settings.html.erb.deface +20 -0
  25. data/app/overrides/spree/shared/_main_nav_bar/cart_link.html.erb.deface +9 -0
  26. data/app/overrides/spree/shared/_main_nav_bar/locale_selector.html.erb.deface +16 -0
  27. data/bin/rails +7 -0
  28. data/config/initializers/country_names.rb +51 -0
  29. data/config/initializers/routing_filter.rb +2 -0
  30. data/config/locales/bg.yml +1330 -0
  31. data/config/locales/ca.yml +1334 -0
  32. data/config/locales/cs.yml +1363 -0
  33. data/config/locales/da.yml +1336 -0
  34. data/config/locales/de-CH.yml +1288 -0
  35. data/config/locales/de.yml +1477 -0
  36. data/config/locales/en-AU.yml +1334 -0
  37. data/config/locales/en-GB.yml +1338 -0
  38. data/config/locales/en-IN.yml +1336 -0
  39. data/config/locales/en-NZ.yml +1334 -0
  40. data/config/locales/es-CL.yml +1398 -0
  41. data/config/locales/es-EC.yml +1338 -0
  42. data/config/locales/es-MX.yml +1337 -0
  43. data/config/locales/es.yml +1338 -0
  44. data/config/locales/et.yml +1316 -0
  45. data/config/locales/fa.yml +1163 -0
  46. data/config/locales/fi.yml +1352 -0
  47. data/config/locales/fr.yml +1588 -0
  48. data/config/locales/id.yml +1335 -0
  49. data/config/locales/it.yml +1395 -0
  50. data/config/locales/ja.yml +1336 -0
  51. data/config/locales/ko.yml +1294 -0
  52. data/config/locales/lv.yml +1328 -0
  53. data/config/locales/nb.yml +1339 -0
  54. data/config/locales/nl.yml +1338 -0
  55. data/config/locales/pl.yml +1345 -0
  56. data/config/locales/pt-BR.yml +1364 -0
  57. data/config/locales/pt.yml +1290 -0
  58. data/config/locales/ro.yml +1335 -0
  59. data/config/locales/ru.yml +1400 -0
  60. data/config/locales/sk.yml +1345 -0
  61. data/config/locales/sl-SI.yml +1288 -0
  62. data/config/locales/sv.yml +1372 -0
  63. data/config/locales/th.yml +1330 -0
  64. data/config/locales/tr.yml +1291 -0
  65. data/config/locales/uk.yml +1447 -0
  66. data/config/locales/vi.yml +1290 -0
  67. data/config/locales/zh-CN.yml +1345 -0
  68. data/config/locales/zh-TW.yml +1293 -0
  69. data/config/routes.rb +6 -0
  70. data/db/migrate/20150609154031_remove_translations_from_spree_tables.rb +65 -0
  71. data/lib/generators/solidus_i18n/install/install_generator.rb +27 -0
  72. data/lib/solidus_i18n/configuration.rb +9 -0
  73. data/lib/solidus_i18n/controller_locale_helper.rb +29 -0
  74. data/lib/solidus_i18n/engine.rb +45 -0
  75. data/lib/solidus_i18n/locale.rb +13 -0
  76. data/lib/solidus_i18n/utils.rb +56 -0
  77. data/lib/solidus_i18n/version.rb +18 -0
  78. data/lib/solidus_i18n.rb +8 -0
  79. data/lib/tasks/solidus_i18n/upgrade.rake +43 -0
  80. data/solidus_i18n.gemspec +46 -0
  81. data/spec/controllers/locales_controller_spec.rb +24 -0
  82. data/spec/features/admin/translations_spec.rb +33 -0
  83. data/spec/features/russian_errors_translation_spec.rb +17 -0
  84. data/spec/features/translation_spec.rb +31 -0
  85. data/spec/features/translations_spec.rb +28 -0
  86. data/spec/spec_helper.rb +31 -0
  87. data/spec/support/capybara.rb +11 -0
  88. data/spec/support/database_cleaner.rb +23 -0
  89. data/spec/support/factory_girl.rb +5 -0
  90. data/spec/support/i18n.rb +5 -0
  91. data/spec/support/spree.rb +12 -0
  92. metadata +411 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ed8e33f5b243d4064d181a50c9ddc3969cb8c7c1
4
+ data.tar.gz: d44330025193250d62aabf963178adaaffc5d510
5
+ SHA512:
6
+ metadata.gz: 60b20095c44e83638e94d8fc409ec76cfd6d1a64e2123c2f747e7388a3ce0ee3bc7d4fc704ac29ee041c57f875d41f0d4756d8091a56c4baa6a494da29176e02
7
+ data.tar.gz: e80049c2f3faa448c391ed4a8ebca5c272cf6fd7769b3f5e7ef61377746cd981df8fba5f1559023276b9aecdcec5852a9e235624b2da93d5c73bdbd2504d7947
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ .idea
6
+ .localeapp/locales
7
+ .project
8
+ coverage
9
+ default
10
+ Gemfile.lock
11
+ tmp
12
+ nbproject
13
+ pkg
14
+ *.sw?
15
+ spec/dummy
16
+ .rvmrc
17
+ .sass-cache
18
+ public/spree
19
+ .ruby-version
20
+ .ruby-gemset
data/.hound.yml ADDED
@@ -0,0 +1,25 @@
1
+ ---
2
+ # Keep it high to avoid spam.
3
+ Metrics/LineLength:
4
+ Max: 140
5
+
6
+ # This should truly be on for well documented gems.
7
+ Style/Documentation:
8
+ Enabled: false
9
+
10
+ # Neatly aligned code is too swell.
11
+ Style/SingleSpaceBeforeFirstArg:
12
+ Enabled: false
13
+
14
+ # Don't mess with RSpec DSL.
15
+ Style/BlockDelimiters:
16
+ Exclude:
17
+ - 'spec/**/*'
18
+
19
+ # Avoid contradictory style rules by enforce single quotes.
20
+ Style/StringLiterals:
21
+ EnforcedStyle: single_quotes
22
+
23
+ # It say we should use fail over raise..yeah right
24
+ Style/SignalException:
25
+ Enabled: false
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ inherit_from: .hound.yml
3
+
4
+ AllCops:
5
+ Exclude:
6
+ - spec/dummy/**/*
7
+ - bin/*
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
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/CONTRIBUTING.md ADDED
@@ -0,0 +1,70 @@
1
+ ## Filing an issue
2
+
3
+ When filing an issue on the Solidus project, please provide these details:
4
+
5
+ * A comprehensive list of steps to reproduce the issue.
6
+ * What you're *expecting* to happen compared with what's *actually* happening.
7
+ * Your application's complete `Gemfile.lock`, and `Gemfile.lock` as text in a [Gist](https://gist.github.com) (*not as an image*)
8
+ * Any relevant stack traces ("Full trace" preferred)
9
+
10
+ In 99% of cases, this information is enough to determine the cause and solution
11
+ to the problem that is being described.
12
+
13
+ Please remember to format code using triple backticks (\`) so that it is neatly
14
+ formatted when the issue is posted.
15
+
16
+ Any issue that is open for 14 days without actionable information or activity
17
+ will be marked as "stalled" and then closed. Stalled issues can be re-opened if
18
+ the information requested is provided.
19
+
20
+ ## Pull requests
21
+
22
+ We gladly accept pull requests to add documentation, fix bugs and, in some circumstances,
23
+ add new features to Solidus.
24
+
25
+ Here's a quick guide:
26
+
27
+ 1. Fork the repo.
28
+
29
+ 2. Run the tests. We only take pull requests with passing tests, and it's great
30
+ to know that you have a clean slate:
31
+
32
+ $ bash build.sh
33
+
34
+ 3. Create new branch then make changes and add tests for your changes. Only
35
+ refactoring and documentation changes require no new tests. If you are adding
36
+ functionality or fixing a bug, we need tests!
37
+
38
+ 4. Push to your fork and submit a pull request. If the changes will apply cleanly
39
+ to the latest stable branches and master branch, you will only need to submit one
40
+ pull request.
41
+
42
+ 5. If a PR does not apply cleanly to one of its targeted branches, then a separate
43
+ PR should be created that does. For instance, if a PR applied to master & 2-1-stable but not 2-0-stable, then there should be one PR for master & 2-1-stable and another, separate PR for 2-0-stable.
44
+
45
+ At this point you're waiting on us. We like to at least comment on, if not
46
+ accept, pull requests within three business days (and, typically, one business
47
+ day). We may suggest some changes or improvements or alternatives.
48
+
49
+ Some things that will increase the chance that your pull request is accepted,
50
+ taken straight from the Ruby on Rails guide:
51
+
52
+ * Use Rails idioms and helpers
53
+ * Include tests that fail without your code, and pass with it
54
+ * Update the documentation, the surrounding one, examples elsewhere, guides,
55
+ whatever is affected by your contribution
56
+
57
+ Syntax:
58
+
59
+ * Two spaces, no tabs.
60
+ * No trailing whitespace. Blank lines should not have any space.
61
+ * Prefer &&/|| over and/or.
62
+ * `MyClass.my_method(my_arg)` not `my_method( my_arg )` or `my_method my_arg`.
63
+ * `a = b` and not `a=b`.
64
+ * `a_method { |block| ... }` and not `a_method { | block | ... }`
65
+ * Follow the conventions you see used in the source already.
66
+ * -> symbol over lambda
67
+ * Ruby 1.9 hash syntax `{ key: value }` over Ruby 1.8 hash syntax `{ :key => value }`
68
+ * Alphabetize the class methods to keep them organized
69
+
70
+ And in case we didn't emphasize it enough: we love tests!
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'solidus', github: 'solidusio/solidus', branch: 'v1.0'
6
+
7
+ if ENV['DB'] == 'mysql'
8
+ gem 'mysql2', '~> 0.3.20'
9
+ elsif ENV['DB'] == 'postgres'
10
+ gem 'pg'
11
+ else
12
+ gem 'sqlite3', '~> 1.3.10'
13
+ end
data/Guardfile ADDED
@@ -0,0 +1,11 @@
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
data/LICENSE.md ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2011-2015 Spree Commerce Inc., and other contributors.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Spree nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # Solidus Internationalization
2
+
3
+ [![Build Status](https://travis-ci.org/solidusio-contrib/solidus_i18n.svg?branch=master)](https://travis-ci.org/solidusio-contrib/solidus_i18n)
4
+ [![Code Climate](https://codeclimate.com/github/solidusio-contrib/solidus_i18n/badges/gpa.svg)](https://codeclimate.com/github/solidusio-contrib/solidus_i18n)
5
+
6
+ This is the Internationalization project for [Solidus](https://solidus.io)
7
+
8
+ ---
9
+
10
+ ## Installation
11
+
12
+ Add the following to your `Gemfile`:
13
+
14
+ ```ruby
15
+ gem 'solidus_i18n', github: 'solidusio-contrib/solidus_i18n', branch: 'master'
16
+ ```
17
+
18
+ Run `bundle install`
19
+
20
+ You can use the generator to install migrations and append solidus_i18n assets to
21
+ your app solidus manifest file.
22
+
23
+ bin/rails g solidus_i18n:install
24
+
25
+ This will insert these lines into your Spree assets manifests:
26
+
27
+ In `vendor/assets/javascripts/spree/frontend/all.js`
28
+
29
+ ```
30
+ //= require spree/frontend/solidus_i18n
31
+ ```
32
+
33
+ In `vendor/assets/javascripts/spree/backend/all.js`
34
+
35
+ ```
36
+ //= require spree/backend/solidus_i18n
37
+ ```
38
+
39
+ ---
40
+
41
+ ## Model Translations
42
+
43
+ We **removed** support for translating models into [a separate Gem](https://github.com/solidusio-contrib/solidus_globalize).
44
+
45
+ Please update your `Gemfile` if you still need the model translations.
46
+
47
+ ```ruby
48
+ # Gemfile
49
+ gem 'solidus_globalize', github: 'solidusio-contrib/solidus_globalize', branch: 'master'
50
+ ```
51
+
52
+ ---
53
+
54
+ ## Upgrading
55
+
56
+ **WARNING**: If you want to keep your model translations, be sure to add the `solidus_globalize` gem to your `Gemfile` **before** migrating the database. Otherwise **you will loose your translations**!
57
+
58
+ ### 1. Migrate your database
59
+
60
+ bin/rake solidus:i18n:upgrade
61
+ bin/rake db:migrate
62
+
63
+ *Note:* The migration automatically skips the removal of the translations tables. So it's safe to run the migration without data loss. But be sure to have the `solidus_globalize` gem in your `Gemfile`, if you want to keep them.
64
+
65
+ ### 2. Remove Configuration
66
+
67
+ Remove all occurrences of `SolidusI18n::Config.supported_locales` from your code.
68
+
69
+
70
+ Contributing
71
+ ------------
72
+
73
+ Solidus is an open source project and we encourage contributions. Please read
74
+ [CONTRIBUTING.md](CONTRIBUTING.md) before contributing.
data/Rakefile ADDED
@@ -0,0 +1,85 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/packagetask'
5
+ require 'rubygems/package_task'
6
+ require 'rspec/core/rake_task'
7
+ require 'spree/testing_support/common_rake'
8
+ require 'solidus_i18n'
9
+
10
+ Bundler::GemHelper.install_tasks
11
+ RSpec::Core::RakeTask.new
12
+
13
+ task default: :spec
14
+
15
+ spec = eval(File.read('solidus_i18n.gemspec'))
16
+
17
+ Gem::PackageTask.new(spec) do |p|
18
+ p.gem_spec = spec
19
+ end
20
+
21
+ desc 'Generates a dummy app for testing'
22
+ task :test_app do
23
+ ENV['LIB_NAME'] = 'solidus_i18n'
24
+ Rake::Task['common:test_app'].invoke
25
+ end
26
+
27
+ namespace :solidus_i18n do
28
+ desc 'Update by retrieving the latest Solidus locale files'
29
+ task :update_default do
30
+ puts "Fetching latest Solidus locale file to #{locales_dir}"
31
+ require 'uri'
32
+ require 'net/https'
33
+
34
+ location = 'https://raw.github.com/solidusio/solidus/master/core/config/locales/en.yml'
35
+ begin
36
+ uri = URI.parse(location)
37
+ http = Net::HTTP.new(uri.host, uri.port)
38
+ http.use_ssl = true
39
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
40
+ puts "Getting from #{uri}"
41
+ request = Net::HTTP::Get.new(uri.request_uri)
42
+ case response = http.request(request)
43
+ when Net::HTTPRedirection then location = response['location']
44
+ when Net::HTTPClientError, Net::HTTPServerError then response.error!
45
+ end
46
+ end until Net::HTTPSuccess == response
47
+
48
+ FileUtils.mkdir_p(default_dir) unless File.directory?(default_dir)
49
+
50
+ File.open("#{default_dir}/solidus_core.yml", 'w') { |file| file << response.body }
51
+ end
52
+
53
+ desc 'Syncronize translation files with latest en (adds comments with fallback en value)'
54
+ task :sync do
55
+ puts 'Starting syncronization...'
56
+ words = translation_keys
57
+
58
+ Dir["#{locales_dir}/*.yml"].each do |filename|
59
+ basename = File.basename(filename, '.yml')
60
+ (comments, other) = SolidusI18n::Utils.read_file(filename, basename)
61
+ # Initializing hash variable as en fallback if it does not exist
62
+ words.each { |k, _v| other[k] ||= "#{words[k]}" }
63
+ # Remove if not defined in en locale
64
+ other.delete_if { |k, _v| !words[k] }
65
+ SolidusI18n::Utils.write_file(filename, basename, comments, other, false)
66
+ end
67
+ end
68
+
69
+ def translation_keys
70
+ (dummy_comments, words) = SolidusI18n::Utils.read_file(File.dirname(__FILE__) + '/default/solidus_core.yml', 'en')
71
+ words
72
+ end
73
+
74
+ def locales_dir
75
+ File.join File.dirname(__FILE__), 'config/locales'
76
+ end
77
+
78
+ def default_dir
79
+ File.join File.dirname(__FILE__), 'default'
80
+ end
81
+
82
+ def env_locale
83
+ ENV['LOCALE'].presence
84
+ end
85
+ end
@@ -0,0 +1,2 @@
1
+ //= require spree/backend
2
+ //= require_tree .
@@ -0,0 +1,5 @@
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']})
@@ -0,0 +1,5 @@
1
+ Spree.fetch_cart = (cartLinkUrl) ->
2
+ Spree.ajax
3
+ url: cartLinkUrl || Spree.pathFor("cart_link"),
4
+ success: (data) ->
5
+ $('#link-to-cart').html data
@@ -0,0 +1,3 @@
1
+ $ ->
2
+ $('#locale-select select').change ->
3
+ @form.submit()
@@ -0,0 +1,2 @@
1
+ //= require spree/frontend
2
+ //= require_tree .
@@ -0,0 +1,8 @@
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
+ */
@@ -0,0 +1,8 @@
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
+ */
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,3 @@
1
+ Spree::Api::BaseController.class_eval do
2
+ include SolidusI18n::ControllerLocaleHelper
3
+ end
@@ -0,0 +1,3 @@
1
+ Spree::BaseController.class_eval do
2
+ include SolidusI18n::ControllerLocaleHelper
3
+ end
@@ -0,0 +1,6 @@
1
+ Spree::LocaleController.class_eval do
2
+ def set
3
+ redirect_to root_path(locale: params[:switch_to_locale])
4
+ end
5
+ end
6
+
@@ -0,0 +1,31 @@
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
@@ -0,0 +1,20 @@
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>
@@ -0,0 +1,9 @@
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>
@@ -0,0 +1,16 @@
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 %>
data/bin/rails ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
4
+ ENGINE_PATH = File.expand_path('../../lib/solidus_i18n/engine', __FILE__)
5
+
6
+ require 'rails/all'
7
+ require 'rails/engine/commands'
@@ -0,0 +1,51 @@
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
@@ -0,0 +1,2 @@
1
+ # do not include the default locale in the URL
2
+ RoutingFilter::Locale.include_default_locale = false