spree_i18n 1.0.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +7 -0
  5. data/.travis.yml +44 -0
  6. data/Appraisals +9 -0
  7. data/CONTRIBUTING.md +81 -0
  8. data/Gemfile +6 -0
  9. data/LICENSE.md +26 -0
  10. data/README.md +95 -9
  11. data/Rakefile +86 -0
  12. data/bin/rails +7 -0
  13. data/config/initializers/country_names.rb +51 -0
  14. data/config/locales/ar.yml +1341 -0
  15. data/config/locales/be.yml +1419 -0
  16. data/config/locales/bg.yml +1441 -0
  17. data/config/locales/ca.yml +1253 -1126
  18. data/config/locales/cs.yml +1363 -0
  19. data/config/locales/da.yml +1330 -1191
  20. data/config/locales/de-CH.yml +1284 -1202
  21. data/config/locales/de.yml +1928 -1113
  22. data/config/locales/en-AU.yml +1241 -1113
  23. data/config/locales/en-GB.yml +1249 -1117
  24. data/config/locales/en-IN.yml +1241 -1111
  25. data/config/locales/en-NZ.yml +1248 -1120
  26. data/config/locales/es-CL.yml +1398 -0
  27. data/config/locales/es-EC.yml +1338 -0
  28. data/config/locales/es-MX.yml +1327 -1196
  29. data/config/locales/es.yml +1785 -1195
  30. data/config/locales/et.yml +1246 -1136
  31. data/config/locales/fa.yml +1139 -1185
  32. data/config/locales/fi.yml +1362 -1200
  33. data/config/locales/fr.yml +1952 -1142
  34. data/config/locales/gr.yml +1336 -0
  35. data/config/locales/id.yml +1335 -0
  36. data/config/locales/it.yml +1391 -1187
  37. data/config/locales/ja.yml +1336 -0
  38. data/config/locales/km.yml +1358 -0
  39. data/config/locales/ko.yml +1292 -1204
  40. data/config/locales/ku.yml +1338 -0
  41. data/config/locales/lt.yml +1497 -1199
  42. data/config/locales/lv.yml +1319 -1194
  43. data/config/locales/nb.yml +1339 -0
  44. data/config/locales/nl.yml +1361 -1124
  45. data/config/locales/pl.yml +1640 -1139
  46. data/config/locales/pt-BR.yml +1512 -1196
  47. data/config/locales/pt.yml +1290 -0
  48. data/config/locales/ro.yml +1335 -0
  49. data/config/locales/ru.yml +1396 -1115
  50. data/config/locales/sk.yml +1339 -1200
  51. data/config/locales/sl-SI.yml +1286 -1204
  52. data/config/locales/sv.yml +1559 -0
  53. data/config/locales/th.yml +1319 -1195
  54. data/config/locales/tr.yml +1291 -0
  55. data/config/locales/uk.yml +1316 -1075
  56. data/config/locales/vi.yml +1296 -0
  57. data/config/locales/zh-CN.yml +1367 -1199
  58. data/config/locales/zh-TW.yml +1821 -1199
  59. data/gemfiles/spree_4_2.gemfile +8 -0
  60. data/gemfiles/spree_master.gemfile +8 -0
  61. data/lib/generators/spree_i18n/install/install_generator.rb +6 -0
  62. data/lib/spree/i18n_utils.rb +26 -20
  63. data/lib/spree_i18n.rb +6 -1
  64. data/lib/spree_i18n/engine.rb +43 -0
  65. data/lib/spree_i18n/locale.rb +13 -0
  66. data/lib/spree_i18n/version.rb +17 -0
  67. data/lib/tasks/spree_i18n/upgrade.rake +43 -0
  68. data/spec/features/russian_errors_translation_spec.rb +16 -0
  69. data/spec/features/translation_spec.rb +38 -0
  70. data/spec/spec_helper.rb +10 -0
  71. data/spec/support/i18n.rb +5 -0
  72. data/spree_i18n.gemspec +31 -0
  73. metadata +94 -110
  74. data/config/locales/cs-CZ.yml +0 -1206
  75. data/config/locales/il.yml +0 -1206
  76. data/config/locales/ja/spree_api.yml +0 -14
  77. data/config/locales/ja/spree_auth.yml +0 -46
  78. data/config/locales/ja/spree_core.rb +0 -16
  79. data/config/locales/ja/spree_core.yml +0 -1071
  80. data/config/locales/ja/spree_dash.yml +0 -5
  81. data/config/locales/ja/spree_promo.yml +0 -88
  82. data/config/locales/nb-NO.yml +0 -1206
  83. data/config/locales/nl-BE.yml +0 -1206
  84. data/config/locales/pt-PT.yml +0 -1206
  85. data/config/locales/sv-SE.yml +0 -1210
  86. data/config/locales/vn.yml +0 -1206
  87. data/default/spree_api.yml +0 -21
  88. data/default/spree_auth.yml +0 -46
  89. data/default/spree_core.yml +0 -1123
  90. data/default/spree_dash.yml +0 -11
  91. data/default/spree_promo.yml +0 -92
  92. data/lib/spree_i18n/railtie.rb +0 -24
  93. data/lib/tasks/i18n.rake +0 -107
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 696882ad0b7373285e774b45f716cf3015fb0563acab159eca36c3aad6f95c52
4
+ data.tar.gz: 684ce56b0a2ff1c187bc1b6adb941bfc21d0b18d759ba16378c605a9e6cc7cdf
5
+ SHA512:
6
+ metadata.gz: 03752aea7bf8cde010625b47e2d27ff537272dd49e8b6ef656f76c9b487878d2813c78d6546dcc8a0814e905af35190ba689ecea7a55685ef1a7c970b742f57e
7
+ data.tar.gz: d397920b4e4f41707107891b15ba2cddcb511864d0f4dcb24acf090261014088526f780089c83bb28b8a2c45fde3d0fd0fca6e47bec7833150a61c6d92a105c0
@@ -0,0 +1,22 @@
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
21
+ gemfiles/*.gemfile.lock
22
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ -r spec_helper
3
+ -f documentation
@@ -0,0 +1,7 @@
1
+ ---
2
+ inherit_from: .hound.yml
3
+
4
+ AllCops:
5
+ Exclude:
6
+ - spec/dummy/**/*
7
+ - bin/*
@@ -0,0 +1,44 @@
1
+ os: linux
2
+ dist: bionic
3
+
4
+ addons:
5
+ apt:
6
+ sources:
7
+ - google-chrome
8
+ packages:
9
+ - google-chrome-stable
10
+
11
+ services:
12
+ - mysql
13
+ - postgresql
14
+
15
+ language: ruby
16
+
17
+ rvm:
18
+ - 2.7
19
+ - 3.0
20
+
21
+ env:
22
+ - DB=mysql
23
+ - DB=postgres
24
+
25
+ gemfile:
26
+ - gemfiles/spree_4_2.gemfile
27
+ - gemfiles/spree_master.gemfile
28
+
29
+ jobs:
30
+ allow_failures:
31
+ - gemfile: gemfiles/spree_master.gemfile
32
+
33
+ before_install:
34
+ - mysql -u root -e "GRANT ALL ON *.* TO 'travis'@'%';"
35
+
36
+ before_script:
37
+ - CHROME_MAIN_VERSION=`google-chrome-stable --version | sed -E 's/(^Google Chrome |\.[0-9]+ )//g'`
38
+ - CHROMEDRIVER_VERSION=`curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_MAIN_VERSION"`
39
+ - curl "https://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip" -O
40
+ - unzip chromedriver_linux64.zip -d ~/bin
41
+
42
+ script:
43
+ - bundle exec rake test_app
44
+ - bundle exec rake spec
@@ -0,0 +1,9 @@
1
+ appraise 'spree-4-2' do
2
+ gem 'spree', '~> 4.2.0.rc3'
3
+ gem 'rails-controller-testing'
4
+ end
5
+
6
+ appraise 'spree-master' do
7
+ gem 'spree', github: 'spree/spree', branch: 'master'
8
+ gem 'rails-controller-testing'
9
+ end
@@ -0,0 +1,81 @@
1
+ # Contributing
2
+
3
+ Spree i18n is an open source project and we encourage contributions. Please see the [contributors guidelines](http://spreecommerce.com/documentation/contributing_to_spree.html) for more information before contributing.
4
+
5
+ In the spirit of [free software][1], **everyone** is encouraged to help improve this project.
6
+
7
+ Here are some ways *you* can contribute:
8
+
9
+ * by using prerelease versions
10
+ * by reporting [bugs][2]
11
+ * by suggesting new features
12
+ * by writing [translations][3] (e.g. use branch 2-4-stable for Spree v2.4.x)
13
+ * by writing or editing documentation
14
+ * by writing specifications
15
+ * by writing code (*no patch is too small*: fix typos, add comments, clean up inconsistent whitespace)
16
+ * by refactoring code
17
+ * by resolving [issues][2]
18
+ * by reviewing patches
19
+
20
+ ---
21
+
22
+ ## Filing an issue
23
+
24
+ When filing an issue on this extension, please first do these things:
25
+
26
+ * Verify you can reproduce this issue in a brand new application.
27
+ * Run through the steps to reproduce the issue again.
28
+
29
+ In the issue itself please provide:
30
+
31
+ * A comprehensive list of steps to reproduce the issue.
32
+ * What you're *expecting* to happen compared with what's *actually* happening.
33
+ * The version of Spree *and* the version of Rails.
34
+ * A list of all extensions.
35
+ * Any relevant stack traces ("Full trace" preferred)
36
+ * Your `Gemfile`
37
+
38
+ In 99% of cases, this information is enough to determine the cause and solution to the problem that is being described.
39
+
40
+ ---
41
+
42
+ ## Pull requests
43
+
44
+ We gladly accept pull requests to fix bugs and, in some circumstances, add new features to this extension.
45
+
46
+ Here's a quick guide:
47
+
48
+ 1. Fork the repo.
49
+
50
+ 2. Run the tests. We only take pull requests with passing tests, and it's great to know that you have a clean slate.
51
+
52
+ 3. Create new branch then make changes and add tests for your changes. Only refactoring and documentation changes require no new tests. If you are adding functionality or fixing a bug, we need tests!
53
+
54
+ 4. Push to your fork and submit a pull request. If the changes will apply cleanly to the latest stable branches and master branch, you will only need to submit one pull request.
55
+
56
+ At this point you're waiting on us. We may suggest some changes or improvements or alternatives.
57
+
58
+ Some things that will increase the chance that your pull request is accepted, taken straight from the Ruby on Rails guide:
59
+
60
+ * Use Rails idioms and helpers.
61
+ * Include tests that fail without your code, and pass with it.
62
+ * Update the documentation, the surrounding one, examples elsewhere, guides, whatever is affected by your contribution.
63
+
64
+ ---
65
+
66
+ ## TL;DR
67
+
68
+ * Fork the repo
69
+ * Clone your repo
70
+ * Run `bundle install`
71
+ * Run `bundle exec rake test_app` to create the test application in `spec/dummy`
72
+ * Make your changes
73
+ * Ensure specs pass by running `bundle exec rspec spec`
74
+ * Ensure all syntax ok by running `rubocop .`
75
+ * Submit your pull request
76
+
77
+ And in case we didn't emphasize it enough: **we love tests!**
78
+
79
+ [1]: http://www.fsf.org/licensing/essays/free-sw.html
80
+ [2]: https://github.com/spree-contrib/spree_i18n/issues
81
+ [3]: https://github.com/spree-contrib/spree_i18n/tree/master/config/locales
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "rails-controller-testing"
4
+ gem 'spree', github: 'spree/spree', branch: 'master'
5
+
6
+ gemspec
@@ -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 CHANGED
@@ -1,15 +1,101 @@
1
- #Spree Internationalization
1
+ # Spree Internationalization
2
2
 
3
- This is the Internationalization project for [Spree Commerce](http://spreecommerce.com/)
3
+ [![Build Status](https://travis-ci.org/spree-contrib/spree_i18n.svg?branch=master)](https://travis-ci.org/spree-contrib/spree_i18n)
4
+ [![Code Climate](https://codeclimate.com/github/spree-contrib/spree_i18n/badges/gpa.svg)](https://codeclimate.com/github/spree-contrib/spree_i18n)
4
5
 
6
+ This is the Internationalization project for [Spree Commerce][1]
5
7
 
6
- See the [official Internationalization documentation](http://guides.spreecommerce.com/i18n.html) for more details.
8
+ See the [official Internationalization documentation][2] for more details.
7
9
 
8
- To install, simply add the Gem to your Gemfile
10
+ Happy translating!
9
11
 
12
+ ---
10
13
 
11
- 1. Add the following to your Gemfile
12
- <pre>
13
- gem 'spree_i18n', :git => 'git://github.com/spree/spree_i18n.git'
14
- </pre>
15
- 2. Run `bundle install`
14
+ 1. Add this extension to your Gemfile with this line:
15
+
16
+ #### Spree >= 3.1
17
+
18
+ ```ruby
19
+ gem 'spree_i18n', github: 'spree-contrib/spree_i18n'
20
+ ```
21
+
22
+ #### Spree 3.0 and Spree 2.x
23
+
24
+ ```ruby
25
+ gem 'spree_i18n', github: 'spree-contrib/spree_i18n', branch: 'X-X-stable'
26
+ ```
27
+
28
+ The `branch` option is important: it must match the version of Spree you're using.
29
+ For example, use `3-0-stable` if you're using Spree `3-0-stable` or any `3.0.x` version.
30
+
31
+ 2. Install the gem using Bundler:
32
+ ```ruby
33
+ bundle install
34
+ ```
35
+
36
+ 3. Copy & run migrations
37
+ ```ruby
38
+ bundle exec rails g spree_i18n:install
39
+ ```
40
+
41
+ 4. Restart your server
42
+
43
+ If your server was running, restart it so that it can find the assets properly.
44
+
45
+ ---
46
+
47
+ ## Model Translations
48
+
49
+ We **removed** support for translating models into [a separate Gem](https://github.com/spree-contrib/spree_globalize).
50
+
51
+ Please update your `Gemfile` if you still need the model translations.
52
+
53
+ ```ruby
54
+ # Gemfile
55
+ gem 'spree_globalize', github: 'spree-contrib/spree_globalize', branch: 'master'
56
+ ```
57
+
58
+ ---
59
+
60
+ ## Upgrading
61
+
62
+ **WARNING**: If you want to keep your model translations, be sure to add the `spree_globalize` gem to your `Gemfile` **before** migrating the database. Otherwise **you will loose your translations**!
63
+
64
+ ### 1. Migrate your database
65
+
66
+ bin/rake spree_i18n:upgrade
67
+ bin/rake db:migrate
68
+
69
+ *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 `spree_globalize` gem in your `Gemfile`, if you want to keep them.
70
+
71
+ ### 2. Remove Assets
72
+
73
+ From `vendor/assets/javascripts/spree/backend/all.js`
74
+ ```
75
+ //= require spree/backend/spree_i18n
76
+ ```
77
+
78
+ and from `vendor/assets/stylesheets/spree/backend/all.css`
79
+ ```
80
+ *= require spree/backend/spree_i18n
81
+ ```
82
+
83
+ ### 3. Remove Configuration
84
+
85
+ Remove all occurrences of `SpreeI18n::Config.supported_locales` from your code.
86
+
87
+ ---
88
+
89
+ ## Contributing
90
+
91
+ [See corresponding guidelines][7]
92
+
93
+ ---
94
+
95
+ Copyright (c) 2010-2015 [Spree Commerce Inc.][1] and other [contributors][5]. released under the [New BSD License][6]
96
+
97
+ [1]: https://spreecommerce.org
98
+ [2]: https://guides.spreecommerce.org/developer/i18n.html
99
+ [5]: https://github.com/spree-contrib/spree_i18n/graphs/contributors
100
+ [6]: https://github.com/spree-contrib/spree_i18n/blob/master/LICENSE.md
101
+ [7]: https://github.com/spree-contrib/spree_i18n/blob/master/CONTRIBUTING.md
@@ -0,0 +1,86 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rake'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rubygems/package_task'
7
+ require 'rspec/core/rake_task'
8
+ require 'spree/testing_support/common_rake'
9
+ require 'spree_i18n'
10
+
11
+ Bundler::GemHelper.install_tasks
12
+ RSpec::Core::RakeTask.new
13
+
14
+ task default: :spec
15
+
16
+ spec = eval(File.read('spree_i18n.gemspec'))
17
+
18
+ Gem::PackageTask.new(spec) do |p|
19
+ p.gem_spec = spec
20
+ end
21
+
22
+ desc 'Generates a dummy app for testing'
23
+ task :test_app do
24
+ ENV['LIB_NAME'] = 'spree_i18n'
25
+ Rake::Task['common:test_app'].invoke
26
+ end
27
+
28
+ namespace :spree_i18n do
29
+ desc 'Update by retrieving the latest Spree locale files'
30
+ task :update_default do
31
+ puts "Fetching latest Spree locale file to #{locales_dir}"
32
+ require 'uri'
33
+ require 'net/https'
34
+
35
+ location = 'https://raw.github.com/spree/spree/master/core/config/locales/en.yml'
36
+ begin
37
+ uri = URI.parse(location)
38
+ http = Net::HTTP.new(uri.host, uri.port)
39
+ http.use_ssl = true
40
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
41
+ puts "Getting from #{uri}"
42
+ request = Net::HTTP::Get.new(uri.request_uri)
43
+ case response = http.request(request)
44
+ when Net::HTTPRedirection then location = response['location']
45
+ when Net::HTTPClientError, Net::HTTPServerError then response.error!
46
+ end
47
+ end until Net::HTTPSuccess == response
48
+
49
+ FileUtils.mkdir_p(default_dir) unless File.directory?(default_dir)
50
+
51
+ File.open("#{default_dir}/spree_core.yml", 'w') { |file| file << response.body }
52
+ end
53
+
54
+ desc 'Syncronize translation files with latest en (adds comments with fallback en value)'
55
+ task :sync do
56
+ puts 'Starting syncronization...'
57
+ words = translation_keys
58
+
59
+ Dir["#{locales_dir}/*.yml"].each do |filename|
60
+ basename = File.basename(filename, '.yml')
61
+ (comments, other) = Spree::I18nUtils.read_file(filename, basename)
62
+ # Initializing hash variable as en fallback if it does not exist
63
+ words.each { |k, _v| other[k] ||= "#{words[k]}" }
64
+ # Remove if not defined in en locale
65
+ other.delete_if { |k, _v| !words[k] }
66
+ Spree::I18nUtils.write_file(filename, basename, comments, other, false)
67
+ end
68
+ end
69
+
70
+ def translation_keys
71
+ (dummy_comments, words) = Spree::I18nUtils.read_file(File.dirname(__FILE__) + '/default/spree_core.yml', 'en')
72
+ words
73
+ end
74
+
75
+ def locales_dir
76
+ File.join File.dirname(__FILE__), 'config/locales'
77
+ end
78
+
79
+ def default_dir
80
+ File.join File.dirname(__FILE__), 'default'
81
+ end
82
+
83
+ def env_locale
84
+ ENV['LOCALE'].presence
85
+ end
86
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
4
+ ENGINE_PATH = File.expand_path('../../lib/spree_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