Skip to content

Commit

Permalink
Renames spree_i18n to solidus_i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas von Deyen committed Oct 31, 2015
1 parent 08bea11 commit 9bf0fd8
Show file tree
Hide file tree
Showing 27 changed files with 94 additions and 110 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source 'https://rubygems.org'

gem 'spree', github: 'spree/spree', branch: 'master'
gem 'solidus', github: 'solidusio/solidus', branch: 'master'

gemspec
73 changes: 27 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
# Spree Internationalization
# Solidus Internationalization

[![Build Status](https://travis-ci.org/spree-contrib/spree_i18n.svg?branch=master)](https://travis-ci.org/spree-contrib/spree_i18n)
[![Code Climate](https://codeclimate.com/github/spree-contrib/spree_i18n/badges/gpa.svg)](https://codeclimate.com/github/spree-contrib/spree_i18n)
[![Build Status](https://travis-ci.org/solidusio-contrib/solidus_i18n.svg?branch=master)](https://travis-ci.org/solidusio-contrib/solidus_i18n)
[![Code Climate](https://codeclimate.com/github/solidusio-contrib/solidus_i18n/badges/gpa.svg)](https://codeclimate.com/github/solidusio-contrib/solidus_i18n)

This is the Internationalization project for [Spree Commerce][1]

See the [official Internationalization documentation][2] for more details.

Happy translating!
This is the Internationalization project for [Solidus](https://solidus.io)

---

Expand All @@ -16,78 +12,63 @@ Happy translating!
Add the following to your `Gemfile`:

```ruby
gem 'spree_i18n', github: 'spree-contrib/spree_i18n', branch: 'master'
gem 'solidus_i18n', github: 'solidusio-contrib/solidus_i18n', branch: 'master'
```

Run `bundle install`

You can use the generator to install migrations and append spree_i18n assets to
your app spree manifest file.
You can use the generator to install migrations and append solidus_i18n assets to
your app solidus manifest file.

rails g spree_i18n:install
bin/rails g solidus_i18n:install

This will insert these lines into your spree manifest files:
This will insert these lines into your Spree assets manifests:

In `vendor/assets/javascripts/spree/frontend/all.js`

```
//= require spree/frontend/spree_i18n
//= require spree/frontend/solidus_i18n
```

In `vendor/assets/javascripts/spree/backend/all.js`

```
//= require spree/backend/solidus_i18n
```

---

## Model Translations

We **removed** support for translating models into [a separate Gem](https://github.com/spree-contrib/spree_globalize).
We **removed** support for translating models into [a separate Gem](https://github.com/solidusio-contrib/solidus_globalize).

Please update your `Gemfile` if you still need the model translations.

```ruby
# Gemfile
gem 'spree_globalize', github: 'spree-contrib/spree_globalize', branch: 'master'
gem 'solidus_globalize', github: 'solidusio-contrib/solidus_globalize', branch: 'master'
```

---

## Upgrading

**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**!
**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**!

### 1. Migrate your database

bin/rake spree_i18n:upgrade
bin/rake solidus:i18n:upgrade
bin/rake db:migrate

*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.

### 2. Remove Assets

From `vendor/assets/javascripts/spree/backend/all.js`
```
//= require spree/backend/spree_i18n
```

and from `vendor/assets/stylesheets/spree/backend/all.css`
```
*= require spree/backend/spree_i18n
```
*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.

### 3. Remove Configuration
### 2. Remove Configuration

Remove all occurrences of `SpreeI18n::Config.supported_locales` from your code.
Remove all occurrences of `SolidusI18n::Config.supported_locales` from your code.

---

## Contributing

[See corresponding guidelines][7]

---

Copyright (c) 2010-2015 [Spree Commerce Inc.][1] and other [contributors][5]. released under the [New BSD License][6]
Contributing
------------

[1]: http:https://spreecommerce.com
[2]: http:https://guides.spreecommerce.com/developer/i18n.html
[5]: https://github.com/spree-contrib/spree_i18n/graphs/contributors
[6]: https://github.com/spree-contrib/spree_i18n/blob/master/LICENSE.md
[7]: https://github.com/spree-contrib/spree_i18n/blob/master/CONTRIBUTING.md
Solidus is an open source project and we encourage contributions. Please read
[CONTRIBUTING.md](CONTRIBUTING.md) before contributing.
22 changes: 11 additions & 11 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@ require 'rake/packagetask'
require 'rubygems/package_task'
require 'rspec/core/rake_task'
require 'spree/testing_support/common_rake'
require 'spree_i18n'
require 'solidus_i18n'

Bundler::GemHelper.install_tasks
RSpec::Core::RakeTask.new

task default: :spec

spec = eval(File.read('spree_i18n.gemspec'))
spec = eval(File.read('solidus_i18n.gemspec'))

Gem::PackageTask.new(spec) do |p|
p.gem_spec = spec
end

desc 'Generates a dummy app for testing'
task :test_app do
ENV['LIB_NAME'] = 'spree_i18n'
ENV['LIB_NAME'] = 'solidus_i18n'
Rake::Task['common:test_app'].invoke
end

namespace :spree_i18n do
desc 'Update by retrieving the latest Spree locale files'
namespace :solidus_i18n do
desc 'Update by retrieving the latest Solidus locale files'
task :update_default do
puts "Fetching latest Spree locale file to #{locales_dir}"
puts "Fetching latest Solidus locale file to #{locales_dir}"
require 'uri'
require 'net/https'

location = 'https://raw.github.com/spree/spree/master/core/config/locales/en.yml'
location = 'https://raw.github.com/solidusio/solidus/master/core/config/locales/en.yml'
begin
uri = URI.parse(location)
http = Net::HTTP.new(uri.host, uri.port)
Expand All @@ -47,7 +47,7 @@ namespace :spree_i18n do

FileUtils.mkdir_p(default_dir) unless File.directory?(default_dir)

File.open("#{default_dir}/spree_core.yml", 'w') { |file| file << response.body }
File.open("#{default_dir}/solidus_core.yml", 'w') { |file| file << response.body }
end

desc 'Syncronize translation files with latest en (adds comments with fallback en value)'
Expand All @@ -57,17 +57,17 @@ namespace :spree_i18n do

Dir["#{locales_dir}/*.yml"].each do |filename|
basename = File.basename(filename, '.yml')
(comments, other) = Spree::I18nUtils.read_file(filename, basename)
(comments, other) = SolidusI18n::Utils.read_file(filename, basename)
# Initializing hash variable as en fallback if it does not exist
words.each { |k, _v| other[k] ||= "#{words[k]}" }
# Remove if not defined in en locale
other.delete_if { |k, _v| !words[k] }
Spree::I18nUtils.write_file(filename, basename, comments, other, false)
SolidusI18n::Utils.write_file(filename, basename, comments, other, false)
end
end

def translation_keys
(dummy_comments, words) = Spree::I18nUtils.read_file(File.dirname(__FILE__) + '/default/spree_core.yml', 'en')
(dummy_comments, words) = SolidusI18n::Utils.read_file(File.dirname(__FILE__) + '/default/solidus_core.yml', 'en')
words
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

def update_i18n_settings
params.each do |name, value|
next unless SpreeI18n::Config.has_preference? name
SpreeI18n::Config[name] = value.map(&:to_sym)
next unless SolidusI18n::Config.has_preference? name
SolidusI18n::Config[name] = value.map(&:to_sym)
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/spree/api/base_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Spree::Api::BaseController.class_eval do
include SpreeI18n::ControllerLocaleHelper
include SolidusI18n::ControllerLocaleHelper
end
2 changes: 1 addition & 1 deletion app/controllers/spree/base_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Spree::BaseController.class_eval do
include SpreeI18n::ControllerLocaleHelper
include SolidusI18n::ControllerLocaleHelper
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module SpreeI18n
module SolidusI18n
module LocaleHelper

def select_available_locales
Expand All @@ -13,7 +13,7 @@ def available_locales_options
end

# Need to manually add en to the array because the en.yml was moved from
# this project. spree/spree now has those keys.
# this project. solidusio/solidus now has those keys.
def all_locales_options
Locale.all.map { |locale| locale_presentation(locale) }.push(['English (EN)', :en])
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- insert_bottom '#main-nav-bar > .navbar-right' -->
<% if SpreeI18n::Config.available_locales.many? %>
<% if SolidusI18n::Config.available_locales.many? %>
<li id="locale-select" data-hook>
<%= form_tag spree.set_locale_path, class: 'navbar-form' do %>
<div class="form-group">
Expand Down
2 changes: 1 addition & 1 deletion bin/rails
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

ENGINE_ROOT = File.expand_path('../..', __FILE__)
ENGINE_PATH = File.expand_path('../../lib/spree_i18n/engine', __FILE__)
ENGINE_PATH = File.expand_path('../../lib/solidus_i18n/engine', __FILE__)

require 'rails/all'
require 'rails/engine/commands'
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
module SpreeI18n
module SolidusI18n
module Generators
class InstallGenerator < Rails::Generators::Base
class_option :auto_run_migrations, type: :boolean, default: true

def add_javascripts
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/spree_i18n\n"
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/spree_i18n\n"
append_file 'vendor/assets/javascripts/spree/backend/all.js',
"//= require spree/backend/solidus_i18n\n"
append_file 'vendor/assets/javascripts/spree/frontend/all.js',
"//= require spree/frontend/solidus_i18n\n"
end

def add_migrations
run 'bundle exec rake railties:install:migrations FROM=spree_i18n'
run 'bin/rake solidus_i18n:install:migrations'
end

def run_migrations
if options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask 'Would you like to run the migrations now? [Y/n]')
run 'bundle exec rake db:migrate'
answer = ask('Would you like to run the migrations now? [Y/n]')
if options[:auto_run_migrations] || ['', 'y', 'Y'].include?(answer)
run 'bin/rake db:migrate'
else
puts "Skiping rake db:migrate, don't forget to run it!"
end
Expand Down
7 changes: 7 additions & 0 deletions lib/solidus_i18n.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'sass/rails'
require 'rails-i18n'
require 'solidus_core'
require 'solidus_i18n/engine'
require 'solidus_i18n/version'
require 'solidus_i18n/utils'
require 'coffee_script'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module SpreeI18n
module SolidusI18n
class Configuration < Spree::Preferences::Configuration
# These configs intend to, respectively:
#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module SpreeI18n
module SolidusI18n
# The fact this logic is in a single module also helps to apply a custom
# locale on the spree/api context since api base controller inherits from
# MetalController instead of Spree::BaseController
Expand All @@ -11,7 +11,7 @@ module ControllerLocaleHelper
private

# Overrides the Spree::Core::ControllerHelpers::Common logic so that only
# supported locales defined by SpreeI18n::Config.supported_locales can
# supported locales defined by SolidusI18n::Config.supported_locales can
# actually be set
def set_user_language
# params[:locale] can be added by routing-filter gem
Expand Down
12 changes: 6 additions & 6 deletions lib/spree_i18n/engine.rb → lib/solidus_i18n/engine.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
require 'routing_filter'
require 'kaminari-i18n/engine'

module SpreeI18n
module SolidusI18n
class Engine < Rails::Engine
engine_name 'spree_i18n'
engine_name 'solidus_i18n'

config.autoload_paths += %W(#{config.root}/lib)

initializer 'spree-i18n' do |app|
SpreeI18n::Engine.instance_eval do
initializer 'solidus.i18n' do |app|
SolidusI18n::Engine.instance_eval do
pattern = pattern_from app.config.i18n.available_locales

add("config/locales/#{pattern}/*.{rb,yml}")
add("config/locales/#{pattern}.{rb,yml}")
end
end

initializer 'spree_i18n.environment', before: :load_config_initializers do |app|
initializer 'solidus.i18n.environment', before: :load_config_initializers do |app|
app.config.i18n.fallbacks = true
I18n.locale = app.config.i18n.default_locale if app.config.i18n.default_locale
SpreeI18n::Config = SpreeI18n::Configuration.new
SolidusI18n::Config = SolidusI18n::Configuration.new
end

def self.activate
Expand Down
2 changes: 1 addition & 1 deletion lib/spree_i18n/locale.rb → lib/solidus_i18n/locale.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module SpreeI18n
module SolidusI18n
class Locale
class << self
def all
Expand Down
4 changes: 2 additions & 2 deletions lib/spree/i18n_utils.rb → lib/solidus_i18n/utils.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'active_support/core_ext'

module Spree
module I18nUtils
module SolidusI18n
module Utils
# Retrieve comments, translation data in hash form
def read_file(filename, basename)
# Add error checking for failed file read?
Expand Down
8 changes: 4 additions & 4 deletions lib/spree_i18n/version.rb → lib/solidus_i18n/version.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module SpreeI18n
module SolidusI18n
module_function

# Returns the version of the currently loaded SpreeI18n as a
# Returns the version of the currently loaded SolidusI18n as a
# <tt>Gem::Version</tt>.
def version
Gem::Version.new VERSION::STRING
end

module VERSION
MAJOR = 3
MINOR = 1
MAJOR = 1
MINOR = 0
TINY = 0
PRE = 'beta'

Expand Down
7 changes: 0 additions & 7 deletions lib/spree_i18n.rb

This file was deleted.

Loading

0 comments on commit 9bf0fd8

Please sign in to comment.