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 +4 -4
- data/README.md +80 -55
- data/lib/tr8n_client_sdk/{extensions → core}/string.rb +0 -0
- data/lib/tr8n_client_sdk/extensions/action_common_methods.rb +2 -2
- data/lib/tr8n_client_sdk/extensions/action_controller_extension.rb +1 -0
- data/lib/tr8n_client_sdk/extensions/action_view_extension.rb +5 -1
- data/lib/tr8n_client_sdk/railtie.rb +0 -2
- data/lib/tr8n_client_sdk/version.rb +1 -1
- data/lib/tr8n_client_sdk.rb +2 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cb47a8f25f6b27451a1c9e8b45a9d5311f18e79
|
4
|
+
data.tar.gz: 5f16ff10ab8df805d404234b5f8971a9d8bbdaa4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
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
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
38
|
+
Now you can start the application by running:
|
41
39
|
|
42
|
-
|
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
|
-
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
@@ -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
|
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|
|
data/lib/tr8n_client_sdk.rb
CHANGED
@@ -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.
|
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-
|
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
|