Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New translations update tasks #91

Merged
merged 3 commits into from
Jun 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
.localeapp/locales
.project
coverage
default
config/locales/en.yml
Gemfile.lock
tmp
nbproject
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ gem 'mysql2'

group :development, :test do
gem "pry-rails"
gem 'i18n-tasks', '~> 0.9' if branch == 'master'
end

gemspec
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ you want your users to be able to select from the locale toggle on the frontend.

---

## Updating Translations

If you want to improve the translations on your language, run the tasks:

bundle exec rake solidus_i18n:update_default
bundle exec i18n-tasks add-missing --nil-value --locale <LOCALE>

Substitute <LOCALE> with your locale code (e.g: `it`).

This will do a cleanup and prepare `<LOCALE>.yml` with all the missing keys.
You can then write the translations and open a pull request.

---

## Model Translations

We **removed** support for translating models into [a separate Gem](https://github.com/solidusio-contrib/solidus_globalize).
Expand Down
51 changes: 4 additions & 47 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,59 +23,16 @@ require 'solidus_i18n'
namespace :solidus_i18n do
desc 'Update by retrieving the latest Solidus locale files'
task :update_default do
puts "Fetching latest Solidus locale file to #{locales_dir}"
require 'uri'
require 'net/https'

require 'open-uri'
puts "Fetching latest Solidus locale file"
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)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
puts "Getting from #{uri}"
request = Net::HTTP::Get.new(uri.request_uri)
case response = http.request(request)
when Net::HTTPRedirection then location = response['location']
when Net::HTTPClientError, Net::HTTPServerError then response.error!
end
end until Net::HTTPSuccess == response

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

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)'
task :sync do
puts 'Starting syncronization...'
words = translation_keys

Dir["#{locales_dir}/*.yml"].each do |filename|
basename = File.basename(filename, '.yml')
(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] }
SolidusI18n::Utils.write_file(filename, basename, comments, other, false)
open("#{locales_dir}/en.yml", 'wb') do |file|
file << open(location).read
end
end

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

def locales_dir
File.join File.dirname(__FILE__), 'config/locales'
end

def default_dir
File.join File.dirname(__FILE__), 'default'
end

def env_locale
ENV['LOCALE'].presence
end
end
1 change: 0 additions & 1 deletion lib/solidus_i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
require 'solidus_i18n/engine'
require 'solidus_i18n/locale'
require 'solidus_i18n/version'
require 'solidus_i18n/utils'
require 'coffee_script'
require 'deface'
56 changes: 0 additions & 56 deletions lib/solidus_i18n/utils.rb

This file was deleted.