tr8n_client_sdk 4.0.7 → 4.0.8

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: f51ee3da16caa6459444b84656eef9acb5ed3856
4
- data.tar.gz: 960acc24a20d38f18ade7e7236256cdf733ba641
3
+ metadata.gz: b0431a7e51712613de3712320c6320550e2aac04
4
+ data.tar.gz: f3e4bf196240bdef5d51ea9ad4cc0068e17272f3
5
5
  SHA512:
6
- metadata.gz: f079b8225526e02c7f2a13578e01ad6b7c7c530f31628a16efc7022eee6b44c7d1f458dbf53405eafc1be6a5b1d58f8f2277ccbcd93ecf09e1589b7361cd23f1
7
- data.tar.gz: 00b518b98803117f40468030514eab443784a98d35c91d779562599867cbe7937f2d0ffa162233b9460444d293cb7ee770243b63d2f0d7636722f81f50f03f9e
6
+ metadata.gz: febd9a1388357c3062dbcdd49fa4bb1406a5a0da86ef69807d77a5b09f25580718ba564125bee747f82cc60d5b34929938493cf29934db9e9bada158548f213a
7
+ data.tar.gz: 251a679dffc85eefe2f7c7dada4e876dbdeccb68a5ff077f53839525f2775b18562d64c5ee689ac56834135425d4da73cffb5fc6f999dbeea45f1648c7da50fa
data/README.md CHANGED
@@ -4,60 +4,57 @@
4
4
 
5
5
  Tr8n Client SDK for Ruby on Rails
6
6
  ===================================
7
- [![Build Status](https://travis-ci.org/tr8n/tr8n_rails_clientsdk.png?branch=master)](https://travis-ci.org/tr8n/tr8n_rails_clientsdk)
7
+ [![Build Status](https://travis-ci.org/tr8n/tr8n_rails_clientsdk.png?branch=rails-3.2.x)](https://travis-ci.org/tr8n/tr8n_rails_clientsdk)
8
8
  [![Coverage Status](https://coveralls.io/repos/tr8n/tr8n_rails_clientsdk/badge.png)](https://coveralls.io/r/tr8n/tr8n_rails_clientsdk)
9
9
  [![Gem Version](https://badge.fury.io/rb/tr8n_client_sdk.png)](http://badge.fury.io/rb/tr8n_client_sdk)
10
- [![Dependency Status](https://www.versioneye.com/user/projects/52e4bc4cec1375b57600000f/badge.png)](https://www.versioneye.com/user/projects/52e4bc4cec1375b57600000f)
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
60
  gem 'tr8n_client_sdk'
@@ -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
@@ -103,38 +133,12 @@ And use TML (Translation Markup Language) to translate your strings, using:
103
133
  ...
104
134
  ```
105
135
 
106
- Learn more about TML at: http://wiki.tr8nhub.com
136
+ Learn more about TML at: https://TranslationExchange.com/docs
107
137
 
108
138
 
109
139
  Caching
110
140
  ===================================
111
141
 
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:
117
-
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
- ```
129
-
130
- The following Cache adapters are supported:
131
-
132
- Memcache, Redis, CDB, File
133
-
134
- It is easy to add any other custom cache adapter as well.
135
-
136
- Memcache and Redis adapters can do a realtime cache warmup - by loading the translations from the service and storing them in the cache.
137
-
138
142
  To reset/upgrade your cache, you can simply call
139
143
 
140
144
  ```ruby
@@ -144,13 +148,7 @@ To reset/upgrade your cache, you can simply call
144
148
  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
149
 
146
150
 
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
151
+ File adapters require pre-generation. You can pre-generate your cache by running:
154
152
 
155
153
  ```sh
156
154
  $ rake tr8n:generate_cache:cdb
@@ -177,7 +175,7 @@ Tr8n comes with its own logger. If you would like to see what the SDK is doing b
177
175
  ```
178
176
 
179
177
 
180
- Rules Engine Customizations
178
+ Customization
181
179
  ===================================
182
180
 
183
181
  Tr8n comes with default settings for the rules engine. For example, it assumes that you have the following methods in your ApplicationController:
@@ -1,20 +1,20 @@
1
1
  <% if Tr8n.config.enabled? %>
2
2
  <% featured_languages = tr8n_application.featured_languages %>
3
- <% if featured_languages.any? %>
3
+ <% if featured_languages.any? %>
4
4
  <style>
5
- .tr8n_language_strip {text-align:center; color:#777;}
6
- .tr8n_language_strip a {text-decoration:none; color:#777; outline:none; border:0px; font-size:10px;}
7
- .tr8n_language_strip a img {border:0px;}
8
- .tr8n_language_strip a:hover {text-decoration:underline}
5
+ .tr8n_language_strip {text-align:center; color:#777;}
6
+ .tr8n_language_strip a {text-decoration:none; color:#777; outline:none; border:0px; font-size:10px;}
7
+ .tr8n_language_strip a img {border:0px;}
8
+ .tr8n_language_strip a:hover {text-decoration:underline}
9
9
  </style>
10
10
  <div class="tr8n_language_strip" style="font-size:12px;">
11
11
  <% featured_languages.each do |lang| %>
12
- <%= tr8n_language_name_tag(lang, opts) %> &nbsp;
12
+ <%= tr8n_language_name_tag(lang, opts) %> &nbsp;
13
13
  <% end %>
14
-
14
+
15
15
  <% if featured_languages.size > 0 %>
16
- <%=link_to_function("&raquo;".html_safe, "Tr8n.UI.LanguageSelector.show()") %>
17
- <% end %>
16
+ <%=link_to_function("&raquo;".html_safe, "Tr8n.UI.LanguageSelector.show()") %>
17
+ <% end %>
18
18
  </div>
19
19
  <% end %>
20
20
  <% end %>
@@ -1,18 +1,18 @@
1
1
  <% if Tr8n.config.enabled? %>
2
2
 
3
3
  <style type="text/css">
4
- .tr8n_fltr {
4
+ .tr8n_fltr {
5
5
  <%=tr8n_style_attribute_tag('float', 'right')%> !important;
6
- }
7
- .tr8n_fltl {
6
+ }
7
+ .tr8n_fltl {
8
8
  <%=tr8n_style_attribute_tag('float', 'left')%> !important;
9
- }
10
- .tr8n_txtr {
9
+ }
10
+ .tr8n_txtr {
11
11
  <%=tr8n_style_attribute_tag('text-align', 'right')%> !important;
12
- }
13
- .tr8n_txtl {
12
+ }
13
+ .tr8n_txtl {
14
14
  <%=tr8n_style_attribute_tag('text-align', 'left')%> !important;
15
- }
15
+ }
16
16
  </style>
17
17
 
18
18
  <script>
@@ -1,6 +1,14 @@
1
1
  #--
2
- # Copyright (c) 2010-2013 Michael Berkovich, tr8nhub.com
2
+ # Copyright (c) 2014 Michael Berkovich, TranslationExchange.com
3
3
  #
4
+ # _______ _ _ _ ______ _
5
+ # |__ __| | | | | (_) | ____| | |
6
+ # | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
7
+ # | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
8
+ # | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
9
+ # |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
10
+ # __/ |
11
+ # |___/
4
12
  # Permission is hereby granted, free of charge, to any person obtaining
5
13
  # a copy of this software and associated documentation files (the
6
14
  # "Software"), to deal in the Software without restriction, including
@@ -24,7 +32,7 @@
24
32
  namespace :tr8n_client_sdk do
25
33
 
26
34
  task :init => :environment do
27
-
35
+
28
36
  end
29
37
 
30
38
  task :cache do
@@ -1,6 +1,14 @@
1
1
  #--
2
- # Copyright (c) 2013 Michael Berkovich, tr8nhub.com
2
+ # Copyright (c) 2014 Michael Berkovich, TranslationExchange.com
3
3
  #
4
+ # _______ _ _ _ ______ _
5
+ # |__ __| | | | | (_) | ____| | |
6
+ # | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
7
+ # | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
8
+ # | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
9
+ # |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
10
+ # __/ |
11
+ # |___/
4
12
  # Permission is hereby granted, free of charge, to any person obtaining
5
13
  # a copy of this software and associated documentation files (the
6
14
  # "Software"), to deal in the Software without restriction, including
@@ -1,6 +1,14 @@
1
1
  #--
2
- # Copyright (c) 2013 Michael Berkovich, tr8nhub.com
2
+ # Copyright (c) 2014 Michael Berkovich, TranslationExchange.com
3
3
  #
4
+ # _______ _ _ _ ______ _
5
+ # |__ __| | | | | (_) | ____| | |
6
+ # | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
7
+ # | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
8
+ # | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
9
+ # |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
10
+ # __/ |
11
+ # |___/
4
12
  # Permission is hereby granted, free of charge, to any person obtaining
5
13
  # a copy of this software and associated documentation files (the
6
14
  # "Software"), to deal in the Software without restriction, including
@@ -32,7 +40,7 @@ module Tr8nClientSdk
32
40
  # or
33
41
  # tr(:label => label, :description => "", :tokens => {}, :options => {})
34
42
  ############################################################
35
- def tr(label, description = "", tokens = {}, options = {})
43
+ def tr(label, description = '', tokens = {}, options = {})
36
44
  return label.html_safe if label.tr8n_translated?
37
45
 
38
46
  params = Tr8n::Utils.normalize_tr_params(label, description, tokens, options)
@@ -91,20 +99,32 @@ module Tr8nClientSdk
91
99
  ## Common methods - wrappers
92
100
  ######################################################################
93
101
 
102
+ def tr8n_session
103
+ Tr8n.session
104
+ end
105
+
94
106
  def tr8n_application
95
- Tr8n.session.application
107
+ tr8n_session.application
96
108
  end
97
109
 
98
110
  def tr8n_current_user
99
- Tr8n.session.current_user
111
+ tr8n_session.current_user
100
112
  end
101
113
 
102
114
  def tr8n_current_translator
103
- Tr8n.session.current_translator
115
+ tr8n_session.current_translator
116
+ end
117
+
118
+ def tr8n_current_locale
119
+ tr8n_session.current_language.locale
104
120
  end
105
121
 
106
122
  def tr8n_current_language
107
- Tr8n.session.current_language
123
+ tr8n_session.current_language
124
+ end
125
+
126
+ def tr8n_language_dir
127
+ tr8n_current_language.dir
108
128
  end
109
129
 
110
130
  end
@@ -1,6 +1,14 @@
1
1
  #--
2
- # Copyright (c) 2013 Michael Berkovich, tr8nhub.com
2
+ # Copyright (c) 2014 Michael Berkovich, TranslationExchange.com
3
3
  #
4
+ # _______ _ _ _ ______ _
5
+ # |__ __| | | | | (_) | ____| | |
6
+ # | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
7
+ # | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
8
+ # | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
9
+ # |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
10
+ # __/ |
11
+ # |___/
4
12
  # Permission is hereby granted, free of charge, to any person obtaining
5
13
  # a copy of this software and associated documentation files (the
6
14
  # "Software"), to deal in the Software without restriction, including
@@ -25,8 +33,8 @@ module Tr8nClientSdk
25
33
  module ActionControllerExtension
26
34
 
27
35
  def self.included(base)
28
- base.send(:include, Tr8nClientSdk::ActionCommonMethods)
29
- base.send(:include, InstanceMethods)
36
+ base.send(:include, Tr8nClientSdk::ActionCommonMethods)
37
+ base.send(:include, InstanceMethods)
30
38
  base.before_filter :tr8n_init_client_sdk
31
39
  base.after_filter :tr8n_reset_client_sdk
32
40
  end
@@ -44,7 +52,7 @@ module Tr8nClientSdk
44
52
  end
45
53
  Tr8n.config.default_locale
46
54
  end
47
-
55
+
48
56
  # Overwrite this method in a controller to assign a custom source for all views
49
57
  def tr8n_source
50
58
  "/#{controller_name}/#{action_name}"
@@ -55,7 +63,7 @@ module Tr8nClientSdk
55
63
  # Overwrite this method in a controller to assign a custom component for all views
56
64
  def tr8n_component
57
65
  nil
58
- end
66
+ end
59
67
 
60
68
  def tr8n_init_current_locale
61
69
  self.send(Tr8n.config.current_locale_method) if Tr8n.config.current_locale_method
@@ -76,7 +84,6 @@ module Tr8nClientSdk
76
84
  def tr8n_init_client_sdk
77
85
  return if Tr8n.config.disabled?
78
86
 
79
- Tr8n.logger.info("Initializing request...")
80
87
  @tr8n_started_at = Time.now
81
88
 
82
89
  Tr8n.session.init
@@ -85,13 +92,10 @@ module Tr8nClientSdk
85
92
 
86
93
  cookie_name = "tr8n_#{tr8n_application.key}"
87
94
  if request.cookies[cookie_name]
88
- Tr8n.logger.info("Cookie exists:")
89
95
  cookie_params = Tr8n::Utils.decode_and_verify_params(request.cookies[cookie_name], tr8n_application.secret)
90
96
  Tr8n.logger.info(cookie_params.inspect)
91
97
  locale = cookie_params["locale"]
92
98
  translator = Tr8n::Translator.new(cookie_params["translator"].merge(:application => tr8n_application)) unless cookie_params["translator"].nil?
93
- else
94
- Tr8n.logger.info("Cookie does not exist")
95
99
  end
96
100
 
97
101
  locale ||= tr8n_init_current_locale || Tr8n.config.default_locale
@@ -105,13 +109,9 @@ module Tr8nClientSdk
105
109
 
106
110
  def tr8n_reset_client_sdk
107
111
  return if Tr8n.config.disabled?
108
-
109
112
  @tr8n_finished_at = Time.now
110
-
111
- Tr8n.logger.info("Resetting request...")
112
113
  tr8n_application.submit_missing_keys
113
114
  Tr8n.session.reset
114
-
115
115
  Tr8n.logger.info("Request took #{@tr8n_finished_at - @tr8n_started_at} mls") if @tr8n_started_at
116
116
  end
117
117
 
@@ -1,6 +1,14 @@
1
1
  #--
2
- # Copyright (c) 2013 Michael Berkovich, tr8nhub.com
2
+ # Copyright (c) 2014 Michael Berkovich, TranslationExchange.com
3
3
  #
4
+ # _______ _ _ _ ______ _
5
+ # |__ __| | | | | (_) | ____| | |
6
+ # | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
7
+ # | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
8
+ # | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
9
+ # |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
10
+ # __/ |
11
+ # |___/
4
12
  # Permission is hereby granted, free of charge, to any person obtaining
5
13
  # a copy of this software and associated documentation files (the
6
14
  # "Software"), to deal in the Software without restriction, including
@@ -25,6 +33,15 @@ module Tr8nClientSdk
25
33
  module ActionViewExtension
26
34
  extend ActiveSupport::Concern
27
35
 
36
+ def trh(tokens = {}, options = {}, &block)
37
+ return '' unless block_given?
38
+
39
+ label = capture(&block)
40
+
41
+ tokenizer = Tr8n::Tokenizers::Dom.new(tokens, options)
42
+ tokenizer.translate(label).html_safe
43
+ end
44
+
28
45
  def tr8n_options_for_select(options, selected = nil, description = nil, lang = Tr8n.session.current_language)
29
46
  options_for_select(options.tro(description), selected)
30
47
  end
@@ -41,25 +58,25 @@ module Tr8nClientSdk
41
58
  def tr8n_language_flag_tag(lang = tr8n_current_language, opts = {})
42
59
  return "" unless tr8n_application.feature_enabled?(:language_flags)
43
60
  html = image_tag(lang.flag_url, :style => "vertical-align:middle;", :title => lang.native_name)
44
- html << "&nbsp;".html_safe
61
+ html << "&nbsp;".html_safe
45
62
  html.html_safe
46
63
  end
47
64
 
48
65
  def tr8n_language_name_tag(lang = tr8n_current_language, opts = {})
49
66
  show_flag = opts[:flag].nil? ? true : opts[:flag]
50
67
  name_type = opts[:name].nil? ? :full : opts[:name] # :full, :native, :english, :locale
51
- linked = opts[:linked].nil? ? true : opts[:linked]
68
+ linked = opts[:linked].nil? ? true : opts[:linked]
52
69
 
53
70
  html = "<span style='white-space: nowrap'>"
54
71
  html << tr8n_language_flag_tag(lang, opts) if show_flag
55
72
  html << "<span dir='ltr'>"
56
73
 
57
74
  name = case name_type
58
- when :native then lang.native_name
59
- when :english then lang.english_name
60
- when :locale then lang.locale
61
- else lang.full_name
62
- end
75
+ when :native then lang.native_name
76
+ when :english then lang.english_name
77
+ when :locale then lang.locale
78
+ else lang.full_name
79
+ end
63
80
 
64
81
  html << name
65
82
  html << "</span></span>"
@@ -73,25 +90,25 @@ module Tr8nClientSdk
73
90
 
74
91
  def tr8n_language_strip_tag(opts = {})
75
92
  opts[:flag] = opts[:flag].nil? ? false : opts[:flag]
76
- opts[:name] = opts[:name].nil? ? :native : opts[:name]
77
- opts[:linked] = opts[:linked].nil? ? true : opts[:linked]
78
- opts[:javascript] = opts[:javascript].nil? ? false : opts[:javascript]
93
+ opts[:name] = opts[:name].nil? ? :native : opts[:name]
94
+ opts[:linked] = opts[:linked].nil? ? true : opts[:linked]
95
+ opts[:javascript] = opts[:javascript].nil? ? false : opts[:javascript]
79
96
 
80
- render(:partial => '/tr8n_client_sdk/tags/language_strip', :locals => {:opts => opts})
97
+ render(:partial => '/tr8n_client_sdk/tags/language_strip', :locals => {:opts => opts})
81
98
  end
82
99
 
83
100
  def tr8n_flashes_tag(opts = {})
84
- render(:partial => '/tr8n_client_sdk/tags/flashes', :locals => {:opts => opts})
101
+ render(:partial => '/tr8n_client_sdk/tags/flashes', :locals => {:opts => opts})
85
102
  end
86
103
 
87
104
  def tr8n_scripts_tag(opts = {})
88
- render(:partial => '/tr8n_client_sdk/tags/scripts', :locals => {:opts => opts})
105
+ render(:partial => '/tr8n_client_sdk/tags/scripts', :locals => {:opts => opts})
89
106
  end
90
107
 
91
108
  def tr8n_select_month(date, options = {}, html_options = {})
92
109
  month_names = options[:use_short_month] ? Tr8n.config.default_abbr_month_names : Tr8n.config.default_month_names
93
110
  select_month(date, options.merge(
94
- :use_month_names => month_names.collect{|month_name| tr8n_current_language.translate(month_name, options[:description] || "Month name")}
111
+ :use_month_names => month_names.collect{|month_name| tr8n_current_language.translate(month_name, options[:description] || "Month name")}
95
112
  ), html_options)
96
113
  end
97
114
 
@@ -111,6 +128,7 @@ module Tr8nClientSdk
111
128
  Thread.current[:block_options].pop
112
129
  ret
113
130
  end
131
+ alias_method :tr8n_block, :tr8n_with_options_tag
114
132
 
115
133
  def tr8n_when_string_tag(time, opts = {})
116
134
  elapsed_seconds = Time.now - time
@@ -120,12 +138,12 @@ module Tr8nClientSdk
120
138
  tr('a moment ago', 'Time reference')
121
139
  elsif elapsed_seconds < 55.minutes
122
140
  elapsed_minutes = (elapsed_seconds / 1.minute).to_i
123
- tr("{minutes||minute} ago", 'Time reference', :minutes => elapsed_minutes)
141
+ tr('{minutes || minute} ago', 'Time reference', :minutes => elapsed_minutes)
124
142
  elsif elapsed_seconds < 1.75.hours
125
- tr("about an hour ago", 'Time reference')
143
+ tr('about an hour ago', 'Time reference')
126
144
  elsif elapsed_seconds < 12.hours
127
145
  elapsed_hours = (elapsed_seconds / 1.hour).to_i
128
- tr("{hours||hour} ago", 'Time reference', :hours => elapsed_hours)
146
+ tr('{hours || hour} ago', 'Time reference', :hours => elapsed_hours)
129
147
  elsif time.today_in_time_zone?
130
148
  display_time(time, :time_am_pm)
131
149
  elsif time.yesterday_in_time_zone?
@@ -133,16 +151,16 @@ module Tr8nClientSdk
133
151
  elsif elapsed_seconds < 5.days
134
152
  time.tr(:day_time).gsub('/ ', '/').sub(/^[0:]*/,"")
135
153
  elsif time.same_year_in_time_zone?
136
- time.tr(:monthname_abbr_time).gsub('/ ', '/').sub(/^[0:]*/,"")
154
+ time.tr(:monthname_abbr_time).gsub('/ ', '/').sub(/^[0:]*/, '')
137
155
  else
138
- time.tr(:monthname_abbr_year_time).gsub('/ ', '/').sub(/^[0:]*/,"")
156
+ time.tr(:monthname_abbr_year_time).gsub('/ ', '/').sub(/^[0:]*/, '')
139
157
  end
140
158
  end
141
159
 
142
160
  def tr8n_url_tag(path)
143
161
  tr8n_application.url_for(path)
144
162
  end
145
-
163
+
146
164
  ######################################################################
147
165
  ## Language Direction Support
148
166
  ######################################################################
@@ -159,5 +177,9 @@ module Tr8nClientSdk
159
177
  "dir='#{lang.dir}'".html_safe
160
178
  end
161
179
 
180
+ def tr8n_lang_attribute_tag(lang = tr8n_current_language)
181
+ "lang=#{lang.locale}".html_safe
182
+ end
183
+
162
184
  end
163
185
  end
@@ -0,0 +1,44 @@
1
+ #--
2
+ # Copyright (c) 2014 Michael Berkovich, TranslationExchange.com
3
+ #
4
+ # _______ _ _ _ ______ _
5
+ # |__ __| | | | | (_) | ____| | |
6
+ # | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
7
+ # | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
8
+ # | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
9
+ # |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
10
+ # __/ |
11
+ # |___/
12
+ # Permission is hereby granted, free of charge, to any person obtaining
13
+ # a copy of this software and associated documentation files (the
14
+ # "Software"), to deal in the Software without restriction, including
15
+ # without limitation the rights to use, copy, modify, merge, publish,
16
+ # distribute, sublicense, and/or sell copies of the Software, and to
17
+ # permit persons to whom the Software is furnished to do so, subject to
18
+ # the following conditions:
19
+ #
20
+ # The above copyright notice and this permission notice shall be
21
+ # included in all copies or substantial portions of the Software.
22
+ #
23
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
+ #++
31
+
32
+ class String
33
+
34
+ def tr8n_translated
35
+ return self if frozen?
36
+ @tr8n_translated = true
37
+ self.html_safe
38
+ end
39
+
40
+ def tr8n_translated?
41
+ @tr8n_translated
42
+ end
43
+
44
+ end
@@ -1,6 +1,14 @@
1
1
  #--
2
- # Copyright (c) 2014 Michael Berkovich, tr8nhub.com
2
+ # Copyright (c) 2014 Michael Berkovich, TranslationExchange.com
3
3
  #
4
+ # _______ _ _ _ ______ _
5
+ # |__ __| | | | | (_) | ____| | |
6
+ # | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
7
+ # | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
8
+ # | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
9
+ # |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
10
+ # __/ |
11
+ # |___/
4
12
  # Permission is hereby granted, free of charge, to any person obtaining
5
13
  # a copy of this software and associated documentation files (the
6
14
  # "Software"), to deal in the Software without restriction, including
@@ -29,6 +37,8 @@ require File.join(File.dirname(__FILE__), 'extensions/action_common_methods')
29
37
  require File.join(File.dirname(__FILE__), 'extensions/action_view_extension')
30
38
  require File.join(File.dirname(__FILE__), 'extensions/action_controller_extension')
31
39
 
40
+ require File.join(File.dirname(__FILE__), 'extensions/string')
41
+
32
42
  module Tr8nClientSdk
33
43
  class Railtie < ::Rails::Railtie #:nodoc:
34
44
  initializer 'tr8n_client_sdk' do |app|
@@ -38,7 +48,7 @@ module Tr8nClientSdk
38
48
  end
39
49
  ActiveSupport.on_load(:action_controller) do
40
50
  include Tr8nClientSdk::ActionControllerExtension
41
- end
51
+ end
42
52
  end
43
53
  end
44
54
  end
@@ -23,5 +23,5 @@
23
23
 
24
24
 
25
25
  module Tr8nClientSdk
26
- VERSION = "4.0.7"
26
+ VERSION = '4.0.8'
27
27
  end
@@ -1,6 +1,14 @@
1
1
  #--
2
- # Copyright (c) 2014 Michael Berkovich, tr8nhub.com
2
+ # Copyright (c) 2014 Michael Berkovich, TranslationExchange.com
3
3
  #
4
+ # _______ _ _ _ ______ _
5
+ # |__ __| | | | | (_) | ____| | |
6
+ # | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
7
+ # | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
8
+ # | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
9
+ # |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
10
+ # __/ |
11
+ # |___/
4
12
  # Permission is hereby granted, free of charge, to any person obtaining
5
13
  # a copy of this software and associated documentation files (the
6
14
  # "Software"), to deal in the Software without restriction, including
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.0.7
4
+ version: 4.0.8
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-06-13 00:00:00.000000000 Z
11
+ date: 2014-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.0
19
+ version: '4.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 4.0.0
26
+ version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: tr8n_core
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 4.0.6
33
+ version: '4.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: 4.0.6
40
+ version: '4.0'
41
41
  description: Client SDK for Tr8n translation engine.
42
42
  email:
43
43
  - michael@tr8nhub.com
@@ -45,22 +45,23 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - LICENSE
49
+ - README.md
50
+ - Rakefile
48
51
  - app/views/tr8n_client_sdk/tags/_language_selector.html.erb
49
52
  - app/views/tr8n_client_sdk/tags/_language_strip.html.erb
50
53
  - app/views/tr8n_client_sdk/tags/_powered_by_tr8n.html.erb
51
54
  - app/views/tr8n_client_sdk/tags/_scripts.html.erb
52
55
  - config/routes.rb
53
56
  - lib/tasks/tr8n_client_sdk.rake
57
+ - lib/tr8n_client_sdk.rb
54
58
  - lib/tr8n_client_sdk/engine.rb
55
59
  - lib/tr8n_client_sdk/extensions/action_common_methods.rb
56
60
  - lib/tr8n_client_sdk/extensions/action_controller_extension.rb
57
61
  - lib/tr8n_client_sdk/extensions/action_view_extension.rb
62
+ - lib/tr8n_client_sdk/extensions/string.rb
58
63
  - lib/tr8n_client_sdk/railtie.rb
59
64
  - lib/tr8n_client_sdk/version.rb
60
- - lib/tr8n_client_sdk.rb
61
- - LICENSE
62
- - Rakefile
63
- - README.md
64
65
  homepage: https://github.com/tr8n/tr8n_rails_clientsdk
65
66
  licenses:
66
67
  - MIT-LICENSE
@@ -81,8 +82,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
82
  version: '0'
82
83
  requirements: []
83
84
  rubyforge_project:
84
- rubygems_version: 2.0.3
85
+ rubygems_version: 2.4.1
85
86
  signing_key:
86
87
  specification_version: 4
87
88
  summary: Tr8n Client SDK for Ruby on Rails
88
89
  test_files: []
90
+ has_rdoc: