ghost_reader 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,35 +1,59 @@
1
1
  GhostReader
2
2
  ===========
3
3
 
4
- i18n backend to ghost_writer service
4
+ GhostReader is an alternative I18n backend which makes use of the
5
+ GhostWriter service.
5
6
 
6
7
  ## Usage
7
8
 
8
- add a folowing to `config/initializers/ghost_reader.rb`
9
-
10
- I18n.backend=GhostReader::Backend.new("HTTP_URL_TO_GHOST_SERVER",
11
- :default_backend=>I18n.backend, :wait_time=>30,
12
- :trace => Proc.new do |message|
13
- Rails.logger.debug message
14
- end)
15
-
16
- ### wait_time
17
- The 'wait_time' is the minimum time in seconds after which reached a change
18
- from the Ghost_Writer Ghost_Client. A low value minimizes the delay,
19
- a high value minimizes the network-traffic.
20
- Default-Value is 30
21
-
22
- ### default_backend
23
- The Ghost_reader tries to find default-values for not found translations and
24
- posts them to the server together with the statistical data.
25
-
26
- ### max_packet_size
27
- For preventing Errors on receiving Server splits the ghost-reader the posts
28
- in parts with max max_packet_size count of keys
29
-
30
- ### trace
31
- Proc for logging connection handling to Server
32
-
33
-
9
+ ### Gemfile
10
+
11
+ gem 'ghost_reader', '~> 1.1.1'
12
+
13
+ ### config/initializers/ghost_reader.rb
14
+
15
+ unless Rails.env.test?
16
+ config = {
17
+ :report_interval => 42, # secs
18
+ :retrieval_interval => 23, # secs
19
+ :fallback => I18n.backend,
20
+ :logfile => File.join(Rails.root, %w(log ghostwriter.log)),
21
+ :service => {
22
+ :api_key => '<here_goes_your_api_key>'
23
+ }
24
+ }
25
+
26
+ I18n.backend = GhostReader::Backend.new(config)
27
+ end
28
+
29
+ ## Configuration
30
+
31
+ * 'report interval' is the delay in seconds between subsequent POST
32
+ requests (reporting requests), which report missing translations.
33
+ * 'retrieval_interval' is the delay in seconds between subsequent GET
34
+ requests (incremental requests), which retrieve updated translations.
35
+ * 'fallback' point to the I18n backend wich should be used as a
36
+ fallback.
37
+ * 'logfile' is the path to a optional, separate logfile. If this is
38
+ omitted, log messages go to standard out.
39
+ * 'service' holds a hash with connection details.
40
+ - 'api_key' is a GhostWriter API key.
41
+ - 'host' is the hostname, optionally with port.
42
+ - 'protocol' is either 'http' or 'https'
43
+ - 'uri' is the complete uri with the folling keys, which will be
44
+ replaced: :protocol, :host, :api_key
45
+
46
+ ## TODO
47
+
48
+ * implement counting, for statistics
49
+ * document all config options
50
+
51
+ ## THANKS
52
+
53
+ All work on GhostReader is supported by Panter LLC, Zurich,
54
+ Switzerland. http://panter.ch
55
+
56
+ Special thanks go to Andreas Koenig, for his inital version of
57
+ GhostReader, and Peco Danajlovski for helping with the rewrite.
34
58
 
35
59
 
@@ -1,10 +1,6 @@
1
1
  require 'logger'
2
2
  require 'ostruct'
3
3
  require 'i18n'
4
- #require 'i18n/backend/transliterator' # i18n/backend/base fails to require this
5
- #require 'i18n/backend/base'
6
- #require 'i18n/backend/memoize'
7
- #require 'i18n/backend/flatten'
8
4
 
9
5
  module GhostReader
10
6
  class Backend
@@ -30,6 +26,10 @@ module GhostReader
30
26
  config.logger.info "Initialized GhostReader backend."
31
27
  end
32
28
 
29
+ def available_locales
30
+ ( memoized_lookup.keys + config.fallback.available_locales ).uniq
31
+ end
32
+
33
33
  protected
34
34
 
35
35
  # this won't be called if memoize kicks in
@@ -147,7 +147,7 @@ module GhostReader
147
147
 
148
148
  include I18n::Backend::Base
149
149
  include Implementation
150
- include I18n::Backend::Memoize # provides @memoized_lookup
150
+ include I18n::Backend::Memoize # provides #memoized_lookup
151
151
  include I18n::Backend::Flatten # provides #flatten_translations
152
152
  end
153
153
  end
@@ -1,3 +1,3 @@
1
1
  module GhostReader
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
@@ -40,6 +40,19 @@ describe GhostReader::Backend do
40
40
  result.has_key?(:one).should be_true
41
41
  end
42
42
 
43
+ it 'should nicely respond to available_locales' do
44
+ @backend.should respond_to(:available_locales)
45
+
46
+ expected = [:en, :de]
47
+ @fallback.stub!(:available_locales).and_return(expected)
48
+ @backend.available_locales.should eq(expected)
49
+
50
+ # FIXME
51
+ # @backend.send(:memoize_merge!, :it => {'dummay' => 'Dummy'})
52
+ # @backend.translate(:it, 'this.is.a.test')
53
+ # @backend.available_locales.should eq([:it, :en, :de])
54
+ end
55
+
43
56
  context 'nicely merge data into memoized_hash' do
44
57
 
45
58
  it 'should work with valid data' do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ghost_reader
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 1
10
- version: 1.1.1
9
+ - 2
10
+ version: 1.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Phil Hofmann