t_t 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25ab6bc258b192373b542a9d1ed3b5cab2e8bc59
4
- data.tar.gz: b68173a8d400edbfeed308562e3e8fbf9b2a6b64
3
+ metadata.gz: db067791facedb6247eff1b9fed82785f6bd325a
4
+ data.tar.gz: ced2994ee972a2956c9799e4b1ba8c0e79ff3dc2
5
5
  SHA512:
6
- metadata.gz: e8cd5cccaf09832f11f17f21052b3ebdac483f6b704a7198796a9ee77e71fbce59a04f78d5e4a1153453aeb729eb593f1577db4df48917db8c68a2fd3ec6973d
7
- data.tar.gz: d24a5680945464b25a18650877b0bd86f5da8586273e9130b713c5eccb336282d08d650ba19fbba9fcf2cf1cd684e4bd345298d6de326a303e23156aaee8eb44
6
+ metadata.gz: cfe464540b1e363083f4bd74e5a647379e7f86f627b3d665f2eeab8f8a1cb90258a1a4ba42fb764707b7edb35b5ad44b4ed2717781e053a716863ac06f4e550b
7
+ data.tar.gz: 407fc17c5b26f170fbc58235d070e9e4483a63fa65502b4b44d5d39b2cf03658e2e64551cee614ea5dadab34d57cec95387e3b372749d11414340870098162a0
@@ -29,6 +29,19 @@ Rails.application.configure do
29
29
  end
30
30
  ```
31
31
 
32
+ By default missing translations marked as ":t_t: translations". You can override it:
33
+
34
+ ```ruby
35
+ # config/environments/development.rb
36
+
37
+ Rails.application.configure do
38
+ config.tt.sync = { locale: :en, mark: "you custom string" }
39
+
40
+ # sets mark to zero width space symbol
41
+ config.tt.sync = { locale: :en, mark: :space }
42
+ end
43
+ ```
44
+
32
45
  Also you can synchronise files without a page reload. Add the next line at the bottom `%rails_root%/Rakefile`:
33
46
 
34
47
  ```ruby
@@ -3,8 +3,6 @@ require 'yaml'
3
3
 
4
4
  module TT
5
5
  class I18nSync
6
- MARK = ":t_t: "
7
-
8
6
  module Utils
9
7
  extend self
10
8
 
@@ -29,11 +27,11 @@ module TT
29
27
  end
30
28
  end
31
29
 
32
- def sync_file(path, locale, standard)
30
+ def sync_file(path, locale, standard, mark)
33
31
  old_review = {}
34
32
  source = load_file(path, locale) { |content| old_review.merge!(content.fetch('review', {})) }
35
33
  new_review = {}
36
- content = { locale => sync_level(standard, source, new_review) }
34
+ content = { locale => sync_level(standard, source, new_review, mark) }
37
35
  review = old_review.merge(flat_hash(new_review))
38
36
  content['review'] = review unless review.empty?
39
37
  write_file(path, content)
@@ -45,19 +43,19 @@ module TT
45
43
 
46
44
  private
47
45
 
48
- def sync_level(st_level, source, review)
46
+ def sync_level(st_level, source, review, mark)
49
47
  level = st_level.inject({}) do |r, (key, st_node)|
50
48
  node = source[key]
51
49
 
52
50
  r[key] = case st_node
53
51
  when Hash
54
52
  sub_review = {}
55
- sub_level = sync_level(st_node, (node.is_a?(Hash) ? node : {}), sub_review)
53
+ sub_level = sync_level(st_node, (node.is_a?(Hash) ? node : {}), sub_review, mark)
56
54
  review[key] = sub_review unless sub_review.empty?
57
55
  sub_level
58
- when Array then node.is_a?(Array) ? node : st_node.map { |v| "#{ MARK }#{ v }" }
56
+ when Array then node.is_a?(Array) ? node : st_node.map { |v| "#{ mark }#{ v }" }
59
57
  else
60
- node.nil? ? "#{ MARK }#{ st_node }" : node
58
+ node.nil? ? "#{ mark }#{ st_node }" : node
61
59
  end
62
60
  r
63
61
  end
@@ -69,12 +67,13 @@ module TT
69
67
  end
70
68
 
71
69
  class FileGroup
72
- attr_reader :st_locale, :standard, :list
70
+ attr_reader :st_locale, :standard, :list, :mark
73
71
 
74
- def initialize(st_locale, standard, list)
72
+ def initialize(st_locale, standard, list, mark)
75
73
  @st_locale = st_locale
76
74
  @standard = standard
77
75
  @list = list
76
+ @mark = mark
78
77
  end
79
78
 
80
79
  def execute
@@ -82,7 +81,7 @@ module TT
82
81
  return if defined?(@prev_updated_at) && file_updated_at == @prev_updated_at
83
82
 
84
83
  st_source = Utils.load_file(standard, st_locale)
85
- list.each { |l, path| Utils.sync_file(path, l, st_source) }
84
+ list.each { |l, path| Utils.sync_file(path, l, st_source, mark) }
86
85
 
87
86
  @prev_updated_at = file_updated_at
88
87
  end
@@ -93,8 +92,8 @@ module TT
93
92
  Utils.flat_file(standard, st_locale).inject([]) do |list, (k, st_v)|
94
93
  item = flat_list.inject({ st_locale => st_v }) { |r, (l, h)| r.merge!(l => h[k]) }
95
94
 
96
- if item.any? { |_, v| v.nil? || v.to_s.include?(MARK) }
97
- item.each { |l, v| item[l] = nil if v.to_s.include?(MARK) }
95
+ if item.any? { |_, v| v.nil? || v.to_s.include?(mark) }
96
+ item.each { |l, v| item[l] = nil if v.to_s.include?(mark) }
98
97
  list << item
99
98
  end
100
99
 
@@ -105,7 +104,7 @@ module TT
105
104
 
106
105
  attr_reader :checker, :groups
107
106
 
108
- def initialize(st_locale, files)
107
+ def initialize(st_locale, files, mark)
109
108
  @groups = []
110
109
 
111
110
  files.inject({}) do |r, file|
@@ -119,7 +118,7 @@ module TT
119
118
  locales = group.keys
120
119
  next unless locales.include?(st_locale) && locales.size > 1
121
120
  list = group.reject { |l, v| l == st_locale }
122
- groups << FileGroup.new(st_locale, group[st_locale], list)
121
+ groups << FileGroup.new(st_locale, group[st_locale], list, mark)
123
122
  end
124
123
 
125
124
  @checker = ActiveSupport::FileUpdateChecker.new(groups.map(&:standard)) { execute }
@@ -39,14 +39,18 @@ module TT
39
39
 
40
40
  locale = :en
41
41
  glob = 'config/locales/**/*.yml'
42
+ mark = ':t_t: '
42
43
  if options.is_a?(Symbol) || options.is_a?(String)
43
44
  locale = options
44
45
  elsif options.is_a?(Hash)
45
46
  locale = options[:locale] if options.has_key?(:locale)
46
47
  glob = options[:glob] if options.has_key?(:glob)
48
+ if options[:mark]
49
+ mark = (options[:mark] == :space) ? "\u200B" : options[:mark]
50
+ end
47
51
  end
48
52
 
49
- file_sync = ::TT::I18nSync.new(locale.to_s, Dir.glob(glob))
53
+ file_sync = ::TT::I18nSync.new(locale.to_s, Dir.glob(glob), mark)
50
54
  TT::Rails.sync(file_sync)
51
55
  ::Rails.application.reloaders << file_sync.checker
52
56
  ActionDispatch::Reloader.to_prepare { file_sync.checker.execute_if_updated }
data/readme.md CHANGED
@@ -102,6 +102,10 @@ Just add `gem "t_t"` into your Gemfile and run `bundle`.
102
102
  Dos-T is tested against Ruby 1.9.3+ & JRuby(1.9+ compatible). If your application uses Ruby on Rails the framework version should be 3.2+
103
103
 
104
104
  ## Changelog
105
+ - 1.3.0
106
+ - Allow specify a custom mark for locale file synchonization
107
+ - 1.2.2
108
+ - Fix rails 5 integration
105
109
  - 1.2.0
106
110
  - Deprecate TT::Translator in favour of TT::Base & TT::Rails
107
111
  - Introduce a real-time watcher for [translation file synchronisation](./docs/synchronisation.md)
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "t_t"
5
- spec.version = "1.2.2"
5
+ spec.version = "1.3.0"
6
6
  spec.authors = ["Sergey Pchelintsev"]
7
7
  spec.email = ["mail@sergeyp.me"]
8
8
  spec.summary = %q{An opinioned I18n helper}
@@ -8,7 +8,7 @@ describe 'I18n synchronisation' do
8
8
  }
9
9
 
10
10
  YAML.stub :load_file, store do
11
- group = TT::I18nSync::FileGroup.new('en', __FILE__, { 'de' => 'de.yml' })
11
+ group = TT::I18nSync::FileGroup.new('en', __FILE__, { 'de' => 'de.yml' }, ':t_t: ')
12
12
  expectation = lambda do |path, content|
13
13
  assert_equal path, 'de.yml'
14
14
  assert_equal content, {
@@ -35,7 +35,7 @@ describe 'I18n synchronisation' do
35
35
  'de' => { 'b' => 'de-b' }
36
36
  }
37
37
  YAML.stub :load_file, store do
38
- group = TT::I18nSync::FileGroup.new('de', __FILE__, { 'en' => 'en.yml' })
38
+ group = TT::I18nSync::FileGroup.new('de', __FILE__, { 'en' => 'en.yml' }, ':t_t: ')
39
39
  expectation = lambda do |path, content|
40
40
  assert_equal path, 'en.yml'
41
41
  assert_equal content['en'], { 'b' => 'b' }
@@ -48,7 +48,7 @@ describe 'I18n synchronisation' do
48
48
  end
49
49
 
50
50
  it 'combines files into a full groups' do
51
- groupMock = Struct.new(:locale, :standard, :list) do
51
+ groupMock = Struct.new(:locale, :standard, :list, :mark) do
52
52
  def execute
53
53
  end
54
54
  end
@@ -60,7 +60,7 @@ describe 'I18n synchronisation' do
60
60
  'config/locales/es.yml', 'config/locales/views.en-US.yml', 'config/locales/models/orm.de.yml',
61
61
  'config/locales/en-US.yml', 'config/locales/views.es.yml', 'config/locales/models/orm.es.yml',
62
62
  'config/locales/fix.en-US.yml', 'config/locales/skip.de.yml'
63
- ])
63
+ ], ':t_t: ')
64
64
 
65
65
  assert_equal 3, sync.groups.length
66
66
 
@@ -81,7 +81,7 @@ describe 'I18n synchronisation' do
81
81
  'de' => { 'a' => ':t_t: a', 'b' => 'de-b' }
82
82
  }
83
83
  YAML.stub :load_file, store do
84
- sync = TT::I18nSync.new('en', ['en.yml', 'de.yml'])
84
+ sync = TT::I18nSync.new('en', ['en.yml', 'de.yml'], ':t_t: ')
85
85
  result = sync.missed
86
86
 
87
87
  assert_equal 1, result.size
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: t_t
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Pchelintsev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-15 00:00:00.000000000 Z
11
+ date: 2017-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n