lost_in_translation 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8cc2c96a1dd7b0b6b434b4b986c921dad70df608
4
- data.tar.gz: f3f18bb07a228b47d66301363f650b6ca08c5a70
3
+ metadata.gz: 070feed0b28c42b519ad16f3b90b40236e2be6f7
4
+ data.tar.gz: 918e49b028b84dce8f84cb450e0dad92367e1602
5
5
  SHA512:
6
- metadata.gz: ed1bdf9ab6a228601091397ae1b7377a32fa703de10adcaf69f3a8811117f1b970ea54efe1d2abdd70a4e0784e7371618b2ac69dfdcc28caf844ab5025682f36
7
- data.tar.gz: 7ef6afd2517dc7a4f9f9428cae98d2d1983a6a1b7de284782a0c5f6e21c312cca4f718c9b1f39c90779b5e6ead345c93a1b4456f6b551fa412b80ca9a165c9df
6
+ metadata.gz: dd7d97c00384a3517e2275dfe8e76aae3a33f482130d59b5c6ad916b163532c40ae72e3779950c4221e23c0404b53eda330fea3fb82f749294558ce469541839
7
+ data.tar.gz: afe55294df201e9cd9452e655ec5910333a79381e2b367d30ab737e9c65ad7143c4bee467efd6128aa84502e4ccf2bd1657a1b5d77d1868d63f3af058bbb96c6
data/.gitignore CHANGED
@@ -6,4 +6,4 @@
6
6
  /doc/
7
7
  /pkg/
8
8
  /spec/reports/
9
- /tmp/
9
+ /tmp/*
data/bin/console CHANGED
File without changes
data/bin/setup CHANGED
File without changes
@@ -2,7 +2,7 @@
2
2
 
3
3
  #
4
4
  module LostInTranslation
5
- def diff(root, compared, lang1, lang2, structure = [], _max_count = 0, new_array = [])
5
+ def self.diff(root, compared, lang1, lang2, structure = [], _max_count = 0, new_array = [])
6
6
  count = 0
7
7
  root.each_pair do |key, value|
8
8
  next_root = root[key]
@@ -20,11 +20,11 @@ module LostInTranslation
20
20
  new_array
21
21
  end
22
22
 
23
- def get_locale(path)
23
+ def self.get_locale(path)
24
24
  path.split('/').last.split('.').first unless path.empty?
25
25
  end
26
26
 
27
- def clean(root, compared, structure = [], new_array = [])
27
+ def self.clean(root, compared, structure = [], new_array = [])
28
28
  root.each_pair do |key, value|
29
29
  next_root = root[key]
30
30
  next_compared = compared.nil? ? nil : compared[key]
@@ -2,7 +2,7 @@
2
2
 
3
3
  #
4
4
  module LostInTranslation
5
- def prepare_paths(path1, path2, post)
5
+ def self.prepare_paths(path1, path2, post)
6
6
  [path1, path2].each do |p|
7
7
  prepare_yaml(p, post)
8
8
  end
@@ -10,7 +10,7 @@ module LostInTranslation
10
10
 
11
11
  private
12
12
 
13
- def prepare_yaml(path, post)
13
+ def self.prepare_yaml(path, post)
14
14
  text = File.read(path)
15
15
  snippets = define_snippets
16
16
 
@@ -19,13 +19,14 @@ module LostInTranslation
19
19
  snippet = snippet.reverse if post
20
20
  text = text.gsub(snippet.first, snippet.second)
21
21
  end
22
-
23
- text = post ? postpare(variables, text) : prepare(variables, text)
22
+ text = post ? postpare(snippets, text) : prepare(snippets, text)
23
+ text = add_single_quotes(text) if post
24
+ text = text.gsub(': !,', ": '!,'") if post
24
25
 
25
26
  File.open(path, 'w') { |file| file.puts text }
26
27
  end
27
28
 
28
- def postpare(variables, text)
29
+ def self.postpare(variables, text)
29
30
  variables = text.scan(/varyberryterry.*/)
30
31
  variables.each do |var|
31
32
  new_var = var.delete(':')
@@ -35,7 +36,7 @@ module LostInTranslation
35
36
  text
36
37
  end
37
38
 
38
- def prepare(variables, text)
39
+ def self.prepare(variables, text)
39
40
  variables = text.scan(/: &.*/)
40
41
  variables.each do |var|
41
42
  new_var = var.gsub(': &', 'varyberryterry')
@@ -45,7 +46,27 @@ module LostInTranslation
45
46
  text
46
47
  end
47
48
 
48
- def define_snippets
49
+ def self.add_single_quotes(text)
50
+ tmp = ''
51
+ text.each_line do |line|
52
+ tmp += edit_line(line)
53
+ end
54
+ tmp
55
+ end
56
+
57
+ def self.edit_line(line)
58
+ return line if line.match(/: .*%.*$/).blank?
59
+ arr = line.split(': ', 2)
60
+ return line if arr[1].blank?
61
+ arr[1] = arr[1].gsub("\'", '')
62
+ arr[1] = arr[1].gsub("\"", '')
63
+ arr[1] = "'" + arr[1] unless arr[1].start_with?("\'") || arr[1].start_with?("\"")
64
+ arr[1] = arr[1].squish + "'\n" unless arr[1].squish.end_with?("\'") || arr[1].squish.end_with?("\"")
65
+ arr[1] = arr[1].gsub("\'! ", "! \'")
66
+ return arr.join(': ')
67
+ end
68
+
69
+ def self.define_snippets
49
70
  snippets = []
50
71
  snippets << ['<<', 'a_greater_than_sign']
51
72
  snippets << ['*', 'an_asterik_sign']
@@ -2,15 +2,16 @@
2
2
 
3
3
  #
4
4
  module LostInTranslation
5
- def string_to_hash(string)
5
+ def self.string_to_hash(string)
6
6
  array = string.split('---')
7
7
  value = array.pop
8
8
  arr = array.reverse
9
9
  arr[1..-1].inject(arr[0] => value) { |memo, i| { i => memo } }
10
10
  end
11
11
 
12
- def merge_hash(merge_from, merge_to)
12
+ def self.merge_hash(merge_from, merge_to)
13
13
  return if merge_from.is_a?(String) || merge_to.is_a?(String)
14
+ pp merge_to
14
15
  merged_hash = merge_to
15
16
  first_key = merge_from.keys.first
16
17
  merged_hash[first_key] = if merge_to.key?(first_key)
@@ -21,7 +22,7 @@ module LostInTranslation
21
22
  merged_hash
22
23
  end
23
24
 
24
- def sort_hash(object)
25
+ def self.sort_hash(object)
25
26
  return object unless object.is_a?(Hash)
26
27
  hash = {}
27
28
  object.each { |k, v| hash[k] = sort_hash(v) }
@@ -3,6 +3,7 @@
3
3
  require 'lost_in_translation'
4
4
  require 'rails'
5
5
  module LostInTranslation
6
+ #
6
7
  class Railtie < Rails::Railtie
7
8
  railtie_name :lost_in_translation
8
9
 
@@ -1,56 +1,67 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
3
4
  module LostInTranslation
4
- def ask_for_permission(lang1, lang2, app_name)
5
- system 'clear'
6
- puts 'Comparing Locales'
7
- puts "Application: #{app_name}" unless app_name.nil?
8
- puts "Master Locale: #{lang1}.yml"
9
- puts "Slave Locale: #{lang2}.yml"
10
- puts 'Is this ok?[y/n]'
11
- a = STDIN.gets.chomp
12
- a == 'y' || a == 'Y'
5
+ def self.ask_for_permission(lang1, lang2, app_name)
6
+ log
7
+ log 'Comparing Locales'
8
+ log "Application: #{app_name}" unless app_name.nil?
9
+ log "Master Locale: #{lang1}.yml"
10
+ log "Slave Locale: #{lang2}.yml"
11
+ a = [(print "# Is this ok?[Y/n]: "), STDIN.gets.chomp][1]
12
+ a == 'y' || a == 'Y' || a == ''
13
13
  end
14
14
 
15
- def ask_for_languages
16
- system 'clear'
17
- puts 'What I18n-yaml files do you want to compare?'
18
- lang1 = [(print "Master (e.g. 'en'): "), STDIN.gets.chomp][1]
19
- lang2 = [(print "Slave: (e.g. 'de'): "), STDIN.gets.chomp][1]
15
+ def self.ask_for_languages
16
+ log
17
+ log 'What I18n-yaml files do you want to compare?'
18
+ lang1 = [(print "# Master (e.g. 'en'): "), STDIN.gets.chomp][1]
19
+ lang2 = [(print "# Slave: (e.g. 'de'): "), STDIN.gets.chomp][1]
20
20
  [lang1, lang2]
21
21
  end
22
22
 
23
- def ask_for_max_count
24
- system 'clear'
25
- puts 'How many do you want to edit max?'
26
- max_count = [(print 'Max. Count (default = 50000): '), STDIN.gets.chomp][1]
23
+ def self.ask_for_max_count
24
+ log
25
+ log 'How many do you want to edit max?'
26
+ max_count = [(print '# Max. Count (default = 50000): '), STDIN.gets.chomp][1]
27
27
  max_count
28
28
  end
29
29
 
30
- def ask_for_paths
31
- system 'clear'
32
- puts 'Please type in the absolute paths to the I18n-yaml file you want to compare?'
33
- puts 'e.g. /home/youruser/Documents/your-awesome-app/config/locales/en.yml'
34
- path1 = [(print 'Master: '), STDIN.gets.chomp][1]
35
- path2 = [(print 'Slave:: '), STDIN.gets.chomp][1]
30
+ def self.ask_for_paths
31
+ log
32
+ log 'Please type in the absolute paths to the I18n-yaml file you want to compare?'
33
+ log 'e.g. /home/youruser/Documents/your-awesome-app/config/locales/en.yml'
34
+ path1 = [(print '# Master: '), STDIN.gets.chomp][1]
35
+ path2 = [(print '# Slave:: '), STDIN.gets.chomp][1]
36
36
  [path1, path2]
37
37
  end
38
38
 
39
- def ask_for_sorting(lang, _app_name)
40
- system 'clear'
41
- puts "Do you want the #{lang}.yml to be sorted?"
42
- puts 'Alphabetically & Recursive (ASC)'
43
- puts '[y/n]'
44
- a = STDIN.gets.chomp
45
- a == 'y' || a == 'Y'
39
+ def self.ask_for_sorting(lang, _app_name)
40
+ log
41
+ log "Do you want the #{lang}.yml to be sorted?"
42
+ log 'Alphabetically & Recursive (ASC)'
43
+ a = [(print "# [Y/n]: "), STDIN.gets.chomp][1]
44
+ a == 'y' || a == 'Y' || a == ''
46
45
  end
47
46
 
48
- def ask_for_translation(value, new_structure, lang1, lang2)
49
- system 'clear'
47
+ def self.ask_for_translation(value, new_structure, lang1, lang2)
48
+ log
50
49
  new_s = new_structure.join('---')
51
- puts "#{new_s} is missing"
52
- puts "in #{lang1}: #{value}"
53
- new_val = [(print lang2 + ': '), STDIN.gets.chomp][1]
50
+ log "#{new_s} is missing"
51
+ log "in #{lang1}: #{value}"
52
+ new_val = [(print '# ' + lang2 + ': '), STDIN.gets.chomp][1]
54
53
  new_val == '' ? nil : (new_s + '---' + new_val)
55
54
  end
55
+
56
+ def self.log(text = '')
57
+ max_length = 70
58
+ outside = 4
59
+ puts '#' * max_length if text.blank?
60
+ arr = text.scan(/.{1,#{max_length - outside}}/)
61
+ arr.each do |str|
62
+ fill_length = max_length - str.length - outside
63
+ fill = ' ' * fill_length
64
+ puts '# ' + str + fill + ' #'
65
+ end
66
+ end
56
67
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
3
4
  module LostInTranslation
4
- VERSION = '0.2.4'
5
+ VERSION = '0.2.5'
5
6
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  #
4
4
  module LostInTranslation
5
- def cleanup
5
+ def self.cleanup
6
6
  if defined? Rails
7
7
  lang2, lang1 = LostInTranslation.ask_for_languages
8
8
  path1 = "#{Rails.root}/config/locales/#{lang1}.yml"
@@ -16,6 +16,7 @@ module LostInTranslation
16
16
 
17
17
  abort('NOPE') unless File.exist?(path1) && File.exist?(path2)
18
18
 
19
+ prepare_paths(path1, path2, true)
19
20
  prepare_paths(path1, path2, false)
20
21
 
21
22
  first = YAML.load_file(path1)
@@ -1,5 +1,5 @@
1
1
  module LostInTranslation
2
- def full_automatic
2
+ def self.full_automatic
3
3
  if defined? Rails
4
4
  lang2, lang1 = LostInTranslation.ask_for_languages
5
5
  path1 = "#{Rails.root}/config/locales/#{lang1}.yml"
@@ -2,7 +2,7 @@
2
2
 
3
3
  #
4
4
  module LostInTranslation
5
- def half_automatic
5
+ def self.half_automatic
6
6
  if defined? Rails
7
7
  lang2, lang1 = LostInTranslation.ask_for_languages
8
8
  path1 = "#{Rails.root}/config/locales/#{lang1}.yml"
@@ -2,7 +2,8 @@
2
2
 
3
3
  #
4
4
  module LostInTranslation
5
- def interactive
5
+ def self.interactive
6
+ system 'clear'
6
7
  if defined? Rails
7
8
  app_name = Rails.application.class.parent_name
8
9
  lang1, lang2 = LostInTranslation.ask_for_languages
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LostInTranslation
4
- def recent
4
+ def self.recent
5
5
  app_name = Rails.application.class.parent_name
6
6
  lang1, lang2 = LostInTranslation.ask_for_languages
7
7
  path1 = "#{Rails.root}/config/locales/#{lang1}.yml"
@@ -13,6 +13,7 @@ module LostInTranslation
13
13
  FileUtils.cp(path1, copy_path1)
14
14
  `git checkout "#{path1}"`
15
15
 
16
+ prepare_paths(path1, copy_path1, true)
16
17
  prepare_paths(path1, copy_path1, false)
17
18
 
18
19
  first = YAML.load_file(path1)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lost_in_translation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Datyv
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-06 00:00:00.000000000 Z
11
+ date: 2017-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler