synergy_i18n 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -0,0 +1,55 @@
1
+ ---
2
+ en:
3
+ activerecord:
4
+ attributes:
5
+ promotion:
6
+ name: "Name"
7
+ description: "Description"
8
+ code: "Code"
9
+ usage_limit: "Usage limit"
10
+ starts_at: "Starts at"
11
+ expires_at: "Expires at"
12
+ add_rule_of_type: Add rule of type
13
+ coupon: Coupon
14
+ coupon_code: Coupon code
15
+ editing_promotion: Editing Promotion
16
+ expiry: Expiry
17
+ free_shipping: Free Shipping
18
+ may_be_combined_with_other_promotions: May be combined with other promotions
19
+ new_promotion: New Promotion
20
+ no_rules_added: No rules added
21
+ promotion: Promotion
22
+ promotions: Promotions
23
+ promotion_form:
24
+ match_policies:
25
+ all: Match any of these rules
26
+ any: Match all of these rules
27
+ promotions_description: Manage offers and coupons with promotions
28
+ promotion_rule_types:
29
+ user:
30
+ name: User
31
+ description: Available only to the specified users
32
+ product:
33
+ name: Product(s)
34
+ description: Order includes specified product(s)
35
+ item_total:
36
+ name: Item total
37
+ description: Order total meets these criteria
38
+ first_order:
39
+ name: First order
40
+ description: Must be the customer's first order
41
+ product_rule:
42
+ choose_products: Choose products
43
+ label: "Order must contain %{select} of these products"
44
+ match_any: at least one
45
+ match_all: all
46
+ product_source:
47
+ group: From product group
48
+ manual: Manually choose
49
+ rules: Rules
50
+ user_rule:
51
+ choose_users: Choose users
52
+ item_total_rule:
53
+ operators:
54
+ gt: greater than
55
+ gte: greater than or equal to
@@ -0,0 +1,47 @@
1
+ require 'rails'
2
+
3
+ module Spree
4
+ module I18nUtils
5
+
6
+ # #Retrieve comments, translation data in hash form
7
+ def read_file(filename, basename)
8
+ (comments, data) = IO.read(filename).split(/\n#{basename}:\s*\n/) #Add error checking for failed file read?
9
+ return comments, create_hash(data)
10
+ end
11
+
12
+ #Creates hash of translation data
13
+ def create_hash(data)
14
+ words = Hash.new
15
+ return words if !data
16
+ parent = Array.new
17
+ previous_key = 'base'
18
+ data.split("\n").each do |w|
19
+ next if w.strip.blank? || w.strip[0]=='#'
20
+ (key, value) = w.split(':', 2)
21
+ value ||= ''
22
+ shift = (key =~ /\w/)/2 - parent.size #Determine level of current key in comparison to parent array
23
+ key = key.sub(/^\s+/,'')
24
+ parent << previous_key if shift > 0 #If key is child of previous key, add previous key as parent
25
+ (shift*-1).times { parent.pop } if shift < 0 #If key is not related to previous key, remove parent keys
26
+ previous_key = key #Track key in case next key is child of this key
27
+ words[parent.join(':')+':'+key] = value
28
+ end
29
+ words
30
+ end
31
+
32
+ #Writes to file from translation data hash structure
33
+ def write_file(filename,basename,comments,words,comment_values=true, fallback_values={})
34
+ File.open(filename, "w") do |log|
35
+ log.puts(comments+"\n"+basename+": \n")
36
+ words.sort.each do |k,v|
37
+ keys = k.split(':')
38
+ (keys.size-1).times { keys[keys.size-1] = ' ' + keys[keys.size-1] } #Add indentation for children keys
39
+ value = v.strip
40
+ value = ("#" + value) if comment_values and not value.blank?
41
+ log.puts "#{keys[keys.size-1]}: #{value}\n"
42
+ end
43
+ end
44
+ end
45
+
46
+ end
47
+ end
data/lib/spree_i18n.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'spree_core'
2
+
3
+ module SpreeI18n
4
+ class Engine < Rails::Engine
5
+
6
+ config.autoload_paths += %W(#{config.root}/lib)
7
+
8
+ def self.activate
9
+ # Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
10
+ # Rails.env == "production" ? require(c) : load(c)
11
+ # end
12
+ end
13
+ config.to_prepare &method(:activate).to_proc
14
+ end
15
+ end
@@ -0,0 +1,89 @@
1
+ require 'spree/i18n_utils'
2
+
3
+ include Spree::I18nUtils
4
+
5
+ namespace :spree_i18n do
6
+
7
+ language_root = File.dirname(__FILE__) + "/../../config/locales"
8
+ default_dir = File.dirname(__FILE__) + "/../../default"
9
+
10
+ desc "Update by retrieving the latest Spree locale fils"
11
+ task :update_default do
12
+
13
+ puts "Fetching latest Spree locale file to #{language_root}"
14
+ #TODO also pull the auth and dash locales once they exist
15
+ exec %(
16
+ curl -Lo '#{default_dir}/spree_api.yml' http://github.com/spree/spree/raw/master/api/config/locales/en.yml
17
+ curl -Lo '#{default_dir}/spree_core.yml' http://github.com/spree/spree/raw/master/core/config/locales/en.yml
18
+ curl -Lo '#{default_dir}/spree_promo.yml' http://github.com/spree/spree/raw/master/promo/config/locales/en.yml
19
+ )
20
+ end
21
+
22
+ desc "Syncronize translation files with latest en (adds comments with fallback en value)"
23
+ task :sync do
24
+ puts "Starting syncronization..."
25
+ words = composite_keys
26
+ Dir["#{language_root}/*.yml"].each do |filename|
27
+ basename = File.basename(filename, '.yml')
28
+ (comments, other) = read_file(filename, basename)
29
+ words.each { |k,v| other[k] ||= "#{words[k]}" } #Initializing hash variable as en fallback if it does not exist
30
+ other.delete_if { |k,v| !words[k] } #Remove if not defined in en locale
31
+ write_file(filename, basename, comments, other, false)
32
+ end
33
+ end
34
+
35
+ desc "Create a new translation file based on en"
36
+ task :new do
37
+ if !ENV['LOCALE'] || ENV['LOCALE'] == ''
38
+ print "You must provide a valid LOCALE value, for example:\nrake spree:i18:new LOCALE=pt-PT\n"
39
+ exit
40
+ end
41
+
42
+ write_file "#{language_root}/#{ENV['LOCALE']}.yml", "#{ENV['LOCALE']}", '---', composite_keys
43
+ print "New locale generated.\n"
44
+ print "Don't forget to also download the rails translation from: http://github.com/svenfuchs/rails-i18n/tree/master/rails/locale\n"
45
+ end
46
+
47
+ desc "Show translation status for all supported locales other than en."
48
+ task :stats do
49
+ words = composite_keys
50
+ words.delete_if { |k,v| !v.match(/\w+/) or v.match(/^#/) }
51
+
52
+ results = ActiveSupport::OrderedHash.new
53
+ locale = ENV['LOCALE'] || ''
54
+ Dir["#{language_root}/*.yml"].each do |filename|
55
+ # next unless filename.match('_spree')
56
+ basename = File.basename(filename, '.yml')
57
+
58
+ # next if basename.starts_with?('en')
59
+ (comments, other) = read_file(filename, basename)
60
+ other.delete_if { |k,v| !words[k] } #Remove if not defined in en.yml
61
+ other.delete_if { |k,v| !v.match(/\w+/) or v.match(/#/) }
62
+
63
+ translation_status = 100*(other.values.size / words.values.size.to_f)
64
+ results[basename] = translation_status
65
+ end
66
+ puts "Translation status:"
67
+ results.sort.each do |basename, translation_status|
68
+ puts basename + "\t- #{sprintf('%.1f', translation_status)}%"
69
+ end
70
+ puts
71
+ end
72
+ end
73
+
74
+ #Retrieve US word set
75
+ def get_translation_keys(gem_name)
76
+ (dummy_comments, words) = read_file(File.dirname(__FILE__) + "/../../default/#{gem_name}.yml", "en")
77
+ words
78
+ end
79
+
80
+ # Returns a composite hash of all relevant translation keys from each of the gems
81
+ def composite_keys
82
+ api_keys = get_translation_keys "spree_api"
83
+ auth_keys = get_translation_keys "spree_auth"
84
+ core_keys = get_translation_keys "spree_core"
85
+ dash_keys = get_translation_keys "spree_dash"
86
+ promo_keys = get_translation_keys "spree_promo"
87
+
88
+ api_keys.merge(auth_keys).merge(core_keys).merge(dash_keys).merge(promo_keys)
89
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: synergy_i18n
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Yuri Schastny
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-11-18 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: spree_core
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 103
29
+ segments:
30
+ - 0
31
+ - 30
32
+ - 0
33
+ version: 0.30.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: Provides locale information for use in Synergy/Spree.
37
+ email: y.schastny@gmail.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - README.md
46
+ - default/spree_dash.yml
47
+ - default/spree_promo.yml
48
+ - default/spree_core.yml
49
+ - default/spree_api.yml
50
+ - default/spree_auth.yml
51
+ - config/locales/th.yml
52
+ - config/locales/et.yml
53
+ - config/locales/lv.yml
54
+ - config/locales/mx.yml
55
+ - config/locales/de-CH.yml
56
+ - config/locales/sk.yml
57
+ - config/locales/en-GB.yml
58
+ - config/locales/sl-SI.yml
59
+ - config/locales/nl-NL.yml
60
+ - config/locales/es.yml
61
+ - config/locales/fi.yml
62
+ - config/locales/da.yml
63
+ - config/locales/nl-BE.yml
64
+ - config/locales/il.yml
65
+ - config/locales/pl.yml
66
+ - config/locales/fr-FR.yml
67
+ - config/locales/pt-PT.yml
68
+ - config/locales/vn.yml
69
+ - config/locales/nb-NO.yml
70
+ - config/locales/ru.yml
71
+ - config/locales/cs-CZ.yml
72
+ - config/locales/jp.yml
73
+ - config/locales/zh-CN.yml
74
+ - config/locales/pt-BR.yml
75
+ - config/locales/lt.yml
76
+ - config/locales/en-AU.yml
77
+ - config/locales/de.yml
78
+ - config/locales/sv-SE.yml
79
+ - config/locales/ko.yml
80
+ - config/locales/it.yml
81
+ - lib/spree_i18n.rb
82
+ - lib/tasks/i18n.rake
83
+ - lib/spree/i18n_utils.rb
84
+ homepage: http://synergycommerce.ru
85
+ licenses: []
86
+
87
+ post_install_message:
88
+ rdoc_options: []
89
+
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 57
98
+ segments:
99
+ - 1
100
+ - 8
101
+ - 7
102
+ version: 1.8.7
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ hash: 3
109
+ segments:
110
+ - 0
111
+ version: "0"
112
+ requirements:
113
+ - none
114
+ rubyforge_project: synergy_i18n
115
+ rubygems_version: 1.8.15
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: Provides locale information for use in Synergy/Spree.
119
+ test_files: []
120
+