tr8n_client_sdk 4.1.5 → 4.1.6

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: 9826d9afd314a52e2df7f0b362a2365d293812b7
4
- data.tar.gz: 771b6ba185227163c3dcf99a151d59162eb7685e
3
+ metadata.gz: 7cb47a8f25f6b27451a1c9e8b45a9d5311f18e79
4
+ data.tar.gz: 5f16ff10ab8df805d404234b5f8971a9d8bbdaa4
5
5
  SHA512:
6
- metadata.gz: 228ea21e988c0c8e98b3e2366858dfebbc3ec22ef2acd2c3284b362c6c0693dd36fe32eee833f6c67111f507e45884157b491689e063773826f67cd4e9d23cb6
7
- data.tar.gz: 3c0af5a81b95fe4150b0e36336b0ddd1a8bb977ede7a605072d31bb9529b282e4c6fc2750aed38258df2e6f0eb3dad50648a80c9eb87a42815b2bc3afe537e3d
6
+ metadata.gz: 7d002ca916300782dccd51275759dd7a6692f099a295f6f3d03518a7a73eda3ff22c00277f5cfb9f598e3dd3950ecd95b03cafad8ec058e255d851379f107bb2
7
+ data.tar.gz: 0a48178707dcd1ab2608deed5b787645f6133c6502dceff671d43f1bcaa67aef1983a2cb2afa929a512019335633650b2d6d650b7f1893818e826594d92dfaec
data/README.md CHANGED
@@ -10,57 +10,54 @@ Tr8n Client SDK for Ruby on Rails
10
10
  [![Dependency Status](https://www.versioneye.com/user/projects/53cda6a5225426f1e8000165/badge.svg?style=flat)](https://www.versioneye.com/user/projects/53cda6a5225426f1e8000165)
11
11
  [![Project status](http://stillmaintained.com/tr8n/tr8n_ruby_core.png)](http://stillmaintained.com/tr8n/tr8n_ruby_core.png)
12
12
 
13
- This Client SDK provides extensions necessary for translating Rails based application using the Tr8nHub service.
13
+ This Client SDK provides extensions necessary for translating Rails 3.2.X based application using the TranslationExchange.com service.
14
14
 
15
15
 
16
16
  Tr8n Client SDK Sample
17
17
  ===================================
18
18
 
19
- The best way to start using Tr8nHub is to run the sample application that comes bundled with this SDK.
19
+ The best way to start using the SDK is to run a sample application that comes bundled with this SDK.
20
20
 
21
21
  ```sh
22
22
  $ git clone https://github.com/tr8n/tr8n_rails_clientsdk.git
23
23
  $ cd tr8n_rails_clientsdk/spec/dummy
24
24
  $ bundle
25
- $ script/rails s
26
25
  ```
27
26
 
28
- This will start the dummy application in development mode. The development mode uses Tr8nHub sandbox server for translations.
27
+ Before you running the application, visit TranslationExchange.com, register as a new user and create a new application.
29
28
 
29
+ Update your key and secret in the following file: config/initializers/tr8n.rb
30
30
 
31
- Alternatively, you can use the same sample application as a stand alone app:
32
-
33
- https://github.com/tr8n/tr8n_rails_clientsdk_sample
34
-
35
- This application is running at:
36
-
37
- http://rails.tr8nhub.com
38
-
31
+ ```ruby
32
+ config.application = {
33
+ :key => YOUR_KEY,
34
+ :secret => YOUR_SECRET
35
+ }
36
+ ```
39
37
 
40
- Another sample application that uses this SDK is available here:
38
+ Now you can start the application by running:
41
39
 
42
- https://github.com/tr8n/tr8n_samples_bookface_rails
40
+ ```sh
41
+ $ bundle exec rails s
42
+ ```
43
43
 
44
- Install it and see how it works.
45
44
 
45
+ This will start the dummy application on port 3000. Open your browser and point to:
46
46
 
47
- Registering Your App
48
- ===================================
47
+ http://localhost:3000
49
48
 
50
- Before you can proceed with the integration, please register with https://translationexchange.com and create a new application.
51
49
 
52
- At the end of the registration process you will be given a key and a secret. You will need to enter them in the initialization function of the Tr8n SDK.
53
50
 
54
51
 
55
52
  Integration
56
53
  ===================================
57
54
 
58
- To integrate Tr8n SDK into your app, all you need to do is:
55
+ To integrate Tr8n SDK into your own app, all you need to do is:
59
56
 
60
- Add the following gems to your Gemfile:
57
+ Add the following gem to your Gemfile:
61
58
 
62
59
  ```ruby
63
- gem 'tr8n_client_sdk'
60
+ gem 'tr8n_client_sdk', '~> 3.2'
64
61
  ```
65
62
 
66
63
  Install the gems:
@@ -69,7 +66,7 @@ Install the gems:
69
66
  $ bundle
70
67
  ```
71
68
 
72
- Add the following configuration to your Application.rb (or to the various environment files):
69
+ Create an initializer file under config/initializers/tr8n.rb and add the following configuration:
73
70
 
74
71
  ```ruby
75
72
  Tr8n.configure do |config|
@@ -80,6 +77,39 @@ Add the following configuration to your Application.rb (or to the various enviro
80
77
  end
81
78
  ```
82
79
 
80
+ Tr8n is best run with caching enabled. You can specify your caching adapter using the following settings:
81
+
82
+ Memcache example:
83
+
84
+ ```ruby
85
+ Tr8n.configure do |config|
86
+ config.cache = {
87
+ :enabled => true,
88
+ :adapter => 'memcache',
89
+ :host => 'localhost:11211',
90
+ :version => 1,
91
+ :timeout => 3600
92
+ }
93
+ end
94
+ ```
95
+
96
+ Redis example:
97
+
98
+ ```ruby
99
+ Tr8n.configure do |config|
100
+ config.cache = {
101
+ :enabled => true,
102
+ :adapter => 'redis',
103
+ :host => 'localhost:6379',
104
+ :version => 1,
105
+ :timeout => 3600
106
+ }
107
+ end
108
+ ```
109
+
110
+ To see a full list of supported cache adapters or to create your own cache adapter, visit TranslationExchange.com/docs
111
+
112
+
83
113
  In the HEAD section of your layout, add:
84
114
 
85
115
  ```ruby
@@ -94,7 +124,24 @@ Now you can simply add the default language selector anywhere on your page using
94
124
  <%= tr8n_language_selector_tag %>
95
125
  ```
96
126
 
97
- And use TML (Translation Markup Language) to translate your strings, using:
127
+ The default language selector is used to enable/disable translation modes. It may be useful on staging or translation
128
+ server, but it may not be ideal on production. There are a number of alternative language selectors you can use, including your own.
129
+
130
+ To use a dropdown language selector that uses locale in the url parameter, use:
131
+
132
+ ```rails
133
+ <%= tr8n_language_selector_tag(
134
+ :type => :dropdown,
135
+ :style => "margin-top:15px",
136
+ :language => :english
137
+ ) %>
138
+ ```
139
+
140
+ As you see, you can provide custom values to how you want to make it look and whether you want to use the english version
141
+ of the language name or have the language be printed in a native language.
142
+
143
+
144
+ Now you can use TML (Translation Markup Language) in your application to translate your strings:
98
145
 
99
146
  ```rails
100
147
  <%= tr("Hello World") %>
@@ -103,37 +150,21 @@ And use TML (Translation Markup Language) to translate your strings, using:
103
150
  ...
104
151
  ```
105
152
 
106
- Learn more about TML at: http://wiki.tr8nhub.com
153
+ There are some additional methods that can be very useful. For instance, if you want to translate something inside a model,
154
+ you can simply use:
107
155
 
156
+ ```ruby
108
157
 
109
- Caching
110
- ===================================
111
-
112
- You should enable caching for your application. Without caching you will be querying the service for new translations on every page load.
113
- If you do it too much, you will be throttled. The translation service is designed to service the up-to-date translations only if you your translators are in translation mode.
114
- For all other users you should serve translations from your cache.
115
-
116
- To enable cache, simply add the following configuration to Tr8n config:
158
+ "Hello World".translate
117
159
 
118
- ```ruby
119
- Tr8n.configure do |config|
120
- config.cache = {
121
- :enabled => true,
122
- :adapter => 'memcache',
123
- :host => 'localhost:11211',
124
- :version => 2,
125
- :timeout => 3600
126
- }
127
- end
128
160
  ```
129
161
 
130
- The following Cache adapters are supported:
131
162
 
132
- Memcache, Redis, CDB, File
163
+ Learn more about TML at: https://TranslationExchange.com/docs
133
164
 
134
- It is easy to add any other custom cache adapter as well.
135
165
 
136
- Memcache and Redis adapters can do a realtime cache warmup - by loading the translations from the service and storing them in the cache.
166
+ Caching
167
+ ===================================
137
168
 
138
169
  To reset/upgrade your cache, you can simply call
139
170
 
@@ -144,13 +175,7 @@ To reset/upgrade your cache, you can simply call
144
175
  All the keys stored in memory based cache are versioned. By upgrading the version you will effectively invalidate the old keys and the new keys will be loaded from the translation service.
145
176
 
146
177
 
147
- CDB and File adapters require pre-generation. You can pre-generate your cache by running:
148
-
149
- ```sh
150
- $ rake tr8n:generate_cache:file
151
- ```
152
-
153
- or
178
+ File adapters require pre-generation. You can pre-generate your cache by running:
154
179
 
155
180
  ```sh
156
181
  $ rake tr8n:generate_cache:cdb
@@ -177,7 +202,7 @@ Tr8n comes with its own logger. If you would like to see what the SDK is doing b
177
202
  ```
178
203
 
179
204
 
180
- Rules Engine Customizations
205
+ Customization
181
206
  ===================================
182
207
 
183
208
  Tr8n comes with default settings for the rules engine. For example, it assumes that you have the following methods in your ApplicationController:
File without changes
@@ -41,9 +41,9 @@ module Tr8nClientSdk
41
41
  # tr(:label => label, :description => "", :tokens => {}, :options => {})
42
42
  ############################################################
43
43
  def tr(label, description = '', tokens = {}, options = {})
44
- return label.html_safe if label.tr8n_translated?
45
-
46
44
  params = Tr8n::Utils.normalize_tr_params(label, description, tokens, options)
45
+ return params[:label].html_safe if params[:label].tr8n_translated?
46
+
47
47
  params[:options][:caller] = caller
48
48
 
49
49
  if request
@@ -41,6 +41,7 @@ module Tr8nClientSdk
41
41
  base.rescue_from 'Tr8n::Exception' do |e|
42
42
  Tr8n.logger.error(e)
43
43
  Tr8n.logger.error(e.backtrace)
44
+ Tr8n.session.reset
44
45
  raise e
45
46
  end
46
47
  end
@@ -166,19 +166,23 @@ module Tr8nClientSdk
166
166
  ######################################################################
167
167
 
168
168
  def tr8n_style_attribute_tag(attr_name = 'float', default = 'right', lang = tr8n_current_language)
169
+ return "#{attr_name}:#{default}".html_safe if Tr8n.config.disabled?
169
170
  "#{attr_name}:#{lang.align(default)}".html_safe
170
171
  end
171
172
 
172
173
  def tr8n_style_directional_attribute_tag(attr_name = 'padding', default = 'right', value = '5px', lang = tr8n_current_language)
174
+ return "#{attr_name}-#{default}:#{value}".html_safe if Tr8n.config.disabled?
173
175
  "#{attr_name}-#{lang.align(default)}:#{value}".html_safe
174
176
  end
175
177
 
176
178
  def tr8n_dir_attribute_tag(lang = tr8n_current_language)
179
+ return "dir='ltr'" if Tr8n.config.disabled?
177
180
  "dir='#{lang.dir}'".html_safe
178
181
  end
179
182
 
180
183
  def tr8n_lang_attribute_tag(lang = tr8n_current_language)
181
- "lang=#{lang.locale}".html_safe
184
+ return "lang='en-US'" if Tr8n.config.disabled?
185
+ "lang='#{lang.locale}'".html_safe
182
186
  end
183
187
 
184
188
  end
@@ -37,8 +37,6 @@ require File.join(File.dirname(__FILE__), 'extensions/action_common_methods')
37
37
  require File.join(File.dirname(__FILE__), 'extensions/action_view_extension')
38
38
  require File.join(File.dirname(__FILE__), 'extensions/action_controller_extension')
39
39
 
40
- require File.join(File.dirname(__FILE__), 'extensions/string')
41
-
42
40
  module Tr8nClientSdk
43
41
  class Railtie < ::Rails::Railtie #:nodoc:
44
42
  initializer 'tr8n_client_sdk' do |app|
@@ -30,5 +30,5 @@
30
30
  #++
31
31
 
32
32
  module Tr8nClientSdk
33
- VERSION = '4.1.5'
33
+ VERSION = '4.1.6'
34
34
  end
@@ -29,9 +29,10 @@
29
29
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
30
  #++
31
31
 
32
+ require "tr8n_core"
33
+ require "tr8n_client_sdk/core/string"
32
34
  require "tr8n_client_sdk/railtie"
33
35
  require "tr8n_client_sdk/engine"
34
- require "tr8n_core"
35
36
  require "tr8n/cache_adapters/rails"
36
37
 
37
38
  module Tr8nClientSdk
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tr8n_client_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.5
4
+ version: 4.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Berkovich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-26 00:00:00.000000000 Z
11
+ date: 2014-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -56,11 +56,11 @@ files:
56
56
  - lib/tasks/tr8n_client_sdk.rake
57
57
  - lib/tr8n/cache_adapters/rails.rb
58
58
  - lib/tr8n_client_sdk.rb
59
+ - lib/tr8n_client_sdk/core/string.rb
59
60
  - lib/tr8n_client_sdk/engine.rb
60
61
  - lib/tr8n_client_sdk/extensions/action_common_methods.rb
61
62
  - lib/tr8n_client_sdk/extensions/action_controller_extension.rb
62
63
  - lib/tr8n_client_sdk/extensions/action_view_extension.rb
63
- - lib/tr8n_client_sdk/extensions/string.rb
64
64
  - lib/tr8n_client_sdk/railtie.rb
65
65
  - lib/tr8n_client_sdk/version.rb
66
66
  homepage: https://github.com/tr8n/tr8n_rails_clientsdk