diff --git a/README.md b/README.md index fac804cc..055a59e6 100644 --- a/README.md +++ b/README.md @@ -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 + +Substitute with your locale code (e.g: `it`). + +This will do a cleanup and prepare `.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). diff --git a/Rakefile b/Rakefile index 6841aaaf..38b3aa67 100644 --- a/Rakefile +++ b/Rakefile @@ -32,32 +32,7 @@ namespace :solidus_i18n do end 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) - 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 env_locale - ENV['LOCALE'].presence - end end diff --git a/lib/solidus_i18n.rb b/lib/solidus_i18n.rb index 8f3f7ec4..7c247bc9 100644 --- a/lib/solidus_i18n.rb +++ b/lib/solidus_i18n.rb @@ -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' diff --git a/lib/solidus_i18n/utils.rb b/lib/solidus_i18n/utils.rb deleted file mode 100644 index fa61a1c3..00000000 --- a/lib/solidus_i18n/utils.rb +++ /dev/null @@ -1,56 +0,0 @@ -require 'active_support/core_ext' - -module SolidusI18n - module Utils - # Retrieve comments, translation data in hash form - def read_file(filename, basename) - # Add error checking for failed file read? - (comments, data) = IO.read(filename).split(/#{basename}:\s*\n/) - return comments, create_hash(data) - end - module_function :read_file - - # Creates hash of translation data - def create_hash(data) - words = {} - return words unless data - parent = [] - previous_key = 'base' - data.split("\n").each do |w| - next if w.strip.blank? || w.strip[0] == '#' - (key, value) = w.split(':', 2) - value ||= '' - # Determine level of current key in comparison to parent array - shift = (key =~ /\w/) / 2 - parent.size - key = key.sub(/^\s+/, '') - # If key is child of previous key, add previous key as parent - parent << previous_key if shift > 0 - # If key is not related to previous key, remove parent keys - (shift*-1).times { parent.pop } if shift < 0 - # Track key in case next key is child of this key - previous_key = key - words[parent.join(':') + ':' + key] = value - end - words - end - module_function :create_hash - - # Writes to file from translation data hash structure - def write_file(filename, basename, _comments, words, comment_values = true, _fallback_values = {}) - File.open(filename, 'w') do |log| - log.puts(basename + ": \n") - words.sort.each do |k, v| - keys = k.split(':') - # Add indentation for children keys - (keys.size - 1).times do - keys[keys.size - 1] = ' ' + keys[keys.size - 1] - end - value = v.strip - value = ('#' + value) if comment_values && !value.blank? - log.puts "#{keys[keys.size - 1]}: #{value}\n" - end - end - end - module_function :write_file - end -end