i18n_redis 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -66,6 +66,10 @@ Find Key
66
66
  Clone data for all locale It will load master data to all present locale
67
67
 
68
68
  I18nRedis.clone_data_for_all_locale(i18n_key,master_locale="en")
69
+
70
+ Update Missing key from master data
71
+
72
+ I18nRedis.create_missing_keys_for_locale(src_locale="en",dest_locale, key_value)
69
73
 
70
74
  Search and Replace I18n Value
71
75
 
data/i18n_redis.gemspec CHANGED
@@ -17,5 +17,5 @@ Gem::Specification.new do |s|
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
- s.add_runtime_dependency(%q<redis>, ["~> 2.2.0"])
20
+ s.add_runtime_dependency(%q<redis>, ["~> 3.0.0"])
21
21
  end
data/lib/i18n_redis.rb CHANGED
@@ -1,26 +1,26 @@
1
1
  require 'rubygems'
2
2
  require 'redis'
3
- require 'ruby-debug'
4
- require "i18n_redis/version"
3
+ require_relative "i18n_redis/version"
5
4
 
6
5
 
7
6
  module I18nRedis
8
7
 
9
-
10
8
  # Connect To Redis
11
9
  def self.connect(args={})
12
10
  $i18n_redis = Redis.new(args)
13
11
  end
14
12
 
15
13
  # YAML TO REDIS
16
- # yaml to redis for i18n
14
+ # yaml to redis for i18n
17
15
  # file name is "/abc/en.yml"
18
16
  def self.yaml_to_redis(file_name)
19
-
20
- if File.exist?(file_name)
17
+
18
+ if File.exist?(file_name)
21
19
  yaml_hash = YAML::load(File.open(file_name))
22
20
  yaml_hash.each do |k,v|
23
- # if yaml data contain further nested then create nestedkey or add key to redis
21
+ #have to force key to_string because of some funny keys (eg. true/false)
22
+ k = k.to_s
23
+ # if yaml data contain further nested then create nestedkey or add key to redis
24
24
  self.add_value_to_redis(yaml_hash[k],k)
25
25
  end
26
26
  end
@@ -30,28 +30,37 @@ module I18nRedis
30
30
  # errors:
31
31
  # template:
32
32
  # header: "%{count} errors prohibited this %{model} from being saved"
33
- # This method generates folloeing key and set its respective value
33
+ # This method generates following key and set its respective value
34
34
  # en.errors.template.header="%{count} errors prohibited this %{model} from being saved"
35
35
  def self.add_value_to_redis(yaml_hash,yaml_key)
36
36
  if yaml_hash.is_a?(Hash)
37
37
  yaml_hash.each do |key,value|
38
+ key = key.to_s
39
+ value = value.to_s
40
+ if value == ""
41
+ value = "MISSING_TRANSLATION"
42
+ end
38
43
  if yaml_hash[key].is_a?(Hash)
39
44
  add_value_to_redis(yaml_hash[key],yaml_key+"."+key)
40
45
  else
41
- create(yaml_key+"."+key,value)
46
+ create(yaml_key+"."+key,value)
42
47
  end
43
- end
48
+ end
44
49
  else
45
- create(yaml_key,yaml_hash)
50
+ yaml_hash = yaml_hash.to_s
51
+ if yaml_hash == ""
52
+ yaml_hash = "MISSING_TRANSLATION"
53
+ end
54
+ create(yaml_key,yaml_hash)
46
55
  end
47
56
  end
48
57
 
49
-
50
- # Add to en(master) it will add to all company
51
- # locale is a redis hash which contain default key and value as locale name
58
+
59
+ # Add to en(master) it will add to all company
60
+ # locale is a redis hash which contain default key and value as locale name
52
61
  # or it can be user id company id etc
53
- # any data is added to master it will find all the respective company and add data
54
- # key can be en.label_text
62
+ # any data is added to master it will find all the respective company and add data
63
+ # key can be en.label_text
55
64
 
56
65
  def self.add_to_all_locale(key,val)
57
66
  locale_array = $i18n_redis.hgetall("locale")
@@ -69,7 +78,7 @@ module I18nRedis
69
78
  end
70
79
  end
71
80
 
72
-
81
+
73
82
 
74
83
  #This contain name = "user name or id",value en_20
75
84
  def self.add_locale(name,value)
@@ -89,7 +98,7 @@ module I18nRedis
89
98
  value = $i18n_redis.get(i18n_key)
90
99
  value.gsub!(/\b#{search_value}\b/,replace_value)
91
100
  create(i18n_key,value)
92
- end
101
+ end
93
102
  end
94
103
 
95
104
  # copy one locale data to all present locale
@@ -97,7 +106,7 @@ module I18nRedis
97
106
  # find out all master keys i.e en
98
107
  master_keys= find_all("#{master_locale}.*")
99
108
  master_keys.each do |key|
100
- clone_key = "#{i18n_key}.#{key.split('.').drop(1).join(".")}"
109
+ clone_key = "#{i18n_key}.#{key.split('.').drop(1).join(".")}"
101
110
  create(clone_key,$i18n_redis.get(key))
102
111
  end
103
112
  end
@@ -106,14 +115,29 @@ module I18nRedis
106
115
  # en to us
107
116
 
108
117
  def self.copy_locale_to_other(src_locale,dest_locale)
109
- src_keys= find_all("#{master_locale}.*")
118
+ src_keys= find_all("#{src_locale}.*")
110
119
  src_keys.each do |key|
111
- clone_key = "#{dest_locale}.#{key.split('.').drop(1).join(".")}"
120
+ clone_key = "#{dest_locale}.#{key.split('.').drop(1).join(".")}"
112
121
  create(clone_key,$i18n_redis.get(key))
113
122
  end
114
123
  end
115
124
 
116
- def find_all_for_locale(locale)
125
+ # Clone only the keys that are missing from one locale to another
126
+ # Example:
127
+ # you have en.roles.administrator: administrator it copies empty string to the
128
+ # desired language like:
129
+ # es.roles.administrator: ""
130
+
131
+ def self.create_missing_keys_for_locale(src_locale="en",dest_locale, key_value)
132
+ # first we get all the keys for src locale and omit the locale
133
+ src_keys = self.find_all_for_locale(src_locale).map {|k| k.split('.').drop(1).join('.')}
134
+ dst_keys = self.find_all_for_locale(dest_locale).map {|k| k.split('.').drop(1).join('.')}
135
+ diff_keys = src_keys - dst_keys
136
+ diff_keys.each do |k|
137
+ self.add(k, key_value, dest_locale)
138
+ end
139
+ end
140
+ def self.find_all_for_locale(locale)
117
141
  self.find_all("#{locale}.*")
118
142
  end
119
143
 
@@ -125,9 +149,9 @@ module I18nRedis
125
149
  def self.get_locales
126
150
  $i18n_redis.hgetall("locale")
127
151
  end
128
-
152
+
129
153
  # add key
130
- def add(key,value,locale)
154
+ def self.add(key,value,locale)
131
155
  key = "#{locale}.#{key}" if locale
132
156
  self.create(key,value)
133
157
  end
@@ -147,7 +171,7 @@ module I18nRedis
147
171
  def self.destroy(key)
148
172
  $i18n_redis.del(key)
149
173
  end
150
-
174
+
151
175
  # get data from redis
152
176
  def self.find(key)
153
177
  $i18n_redis.get(key)
@@ -1,3 +1,3 @@
1
1
  module I18nRedis
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,57 @@
1
+ # Additional translations at https://github.com/plataformatec/devise/wiki/I18n
2
+
3
+ en:
4
+ errors:
5
+ messages:
6
+ expired: "has expired, please request a new one"
7
+ not_found: "not found"
8
+ already_confirmed: "was already confirmed, please try signing in"
9
+ not_locked: "was not locked"
10
+ not_saved:
11
+ one: "1 error prohibited this %{resource} from being saved:"
12
+ other: "%{count} errors prohibited this %{resource} from being saved:"
13
+
14
+ devise:
15
+ failure:
16
+ already_authenticated: 'You are already signed in.'
17
+ unauthenticated: 'You need to sign in or sign up before continuing.'
18
+ unconfirmed: 'You have to confirm your account before continuing.'
19
+ locked: 'Your account is locked.'
20
+ invalid: 'Invalid email or password.'
21
+ invalid_token: 'Invalid authentication token.'
22
+ timeout: 'Your session expired, please sign in again to continue.'
23
+ inactive: 'Your account was not activated yet.'
24
+ sessions:
25
+ signed_in: 'Signed in successfully.'
26
+ signed_out: 'Signed out successfully.'
27
+ passwords:
28
+ send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
29
+ updated: 'Your password was changed successfully. You are now signed in.'
30
+ updated_not_active: 'Your password was changed successfully.'
31
+ send_paranoid_instructions: "If your e-mail exists on our database, you will receive a password recovery link on your e-mail"
32
+ confirmations:
33
+ send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
34
+ send_paranoid_instructions: 'If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
35
+ confirmed: 'Your account was successfully confirmed. You are now signed in.'
36
+ registrations:
37
+ signed_up: 'Welcome! You have signed up successfully.'
38
+ signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
39
+ signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
40
+ signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
41
+ updated: 'You updated your account successfully.'
42
+ update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
43
+ destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
44
+ unlocks:
45
+ send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
46
+ unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
47
+ send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
48
+ omniauth_callbacks:
49
+ success: 'Successfully authorized from %{kind} account.'
50
+ failure: 'Could not authorize you from %{kind} because "%{reason}".'
51
+ mailer:
52
+ confirmation_instructions:
53
+ subject: 'Confirmation instructions'
54
+ reset_password_instructions:
55
+ subject: 'Reset password instructions'
56
+ unlock_instructions:
57
+ subject: 'Unlock Instructions'
@@ -0,0 +1,31 @@
1
+ require File.expand_path('spec/spec_helper')
2
+ require File.expand_path('lib/i18n_redis')
3
+
4
+ describe I18nRedis do
5
+ before do
6
+ # should probably mock this somehow
7
+ @redis = I18nRedis.connect(db: 4)
8
+ @it = I18nRedis
9
+ end
10
+ after do
11
+ # we are going to flush the database after testing
12
+ @redis.flushdb
13
+ end
14
+ describe "before inserting" do
15
+ it "should have no keys inside" do
16
+ @redis.keys.count.must_equal 0
17
+ end
18
+ end
19
+ describe "locales" do
20
+ before do
21
+ @it.add_locale("test", "test")
22
+ end
23
+ it "should contain the inserted key within the locale" do
24
+ @redis.hget("locale","test").must_equal "test"
25
+ end
26
+ it "should remove the locale with remove_locale" do
27
+ @it.remove_locale("test")
28
+ @redis.hget("locale","test").must_be_nil
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ require 'minitest/autorun'
2
+ require 'turn'
3
+
4
+ Turn.config do |c|
5
+ c.format = :outline
6
+ c.natural = :true
7
+ end
metadata CHANGED
@@ -1,49 +1,41 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: i18n_redis
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 2
10
- version: 0.0.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Amar Daxini
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-08-19 00:00:00 +05:30
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-11-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: redis
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
18
+ requirements:
27
19
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 2
32
- - 2
33
- - 0
34
- version: 2.2.0
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
35
22
  type: :runtime
36
- version_requirements: *id001
37
- description: I18n YAML to Redis Management.It convert exising yaml to redis.Provides various helper methods to add,update,remove,create,copy master to another locale,one locale to another locale etc.
38
- email:
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
30
+ description: I18n YAML to Redis Management.It convert exising yaml to redis.Provides
31
+ various helper methods to add,update,remove,create,copy master to another locale,one
32
+ locale to another locale etc.
33
+ email:
39
34
  - amar.daxini@livialegal.com
40
35
  executables: []
41
-
42
36
  extensions: []
43
-
44
37
  extra_rdoc_files: []
45
-
46
- files:
38
+ files:
47
39
  - .gitignore
48
40
  - Gemfile
49
41
  - README.markdown
@@ -51,39 +43,34 @@ files:
51
43
  - i18n_redis.gemspec
52
44
  - lib/i18n_redis.rb
53
45
  - lib/i18n_redis/version.rb
54
- has_rdoc: true
55
- homepage: ""
46
+ - spec/files/devise.en.yml
47
+ - spec/i18n_redis_spec.rb
48
+ - spec/spec_helper.rb
49
+ homepage: ''
56
50
  licenses: []
57
-
58
51
  post_install_message:
59
52
  rdoc_options: []
60
-
61
- require_paths:
53
+ require_paths:
62
54
  - lib
63
- required_ruby_version: !ruby/object:Gem::Requirement
55
+ required_ruby_version: !ruby/object:Gem::Requirement
64
56
  none: false
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- hash: 3
69
- segments:
70
- - 0
71
- version: "0"
72
- required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
62
  none: false
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- hash: 3
78
- segments:
79
- - 0
80
- version: "0"
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
81
67
  requirements: []
82
-
83
68
  rubyforge_project: i18n_redis
84
- rubygems_version: 1.4.2
69
+ rubygems_version: 1.8.23
85
70
  signing_key:
86
71
  specification_version: 3
87
72
  summary: I18n YAML to Redis Management
88
- test_files: []
89
-
73
+ test_files:
74
+ - spec/files/devise.en.yml
75
+ - spec/i18n_redis_spec.rb
76
+ - spec/spec_helper.rb