tolk 1.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{public → app/assets/stylesheets}/tolk/reset.css +0 -0
- data/{public → app/assets/stylesheets}/tolk/screen.css +1 -2
- data/app/controllers/tolk/application_controller.rb +1 -1
- data/app/models/tolk/locale.rb +21 -19
- data/app/models/tolk/phrase.rb +1 -1
- data/app/models/tolk/translation.rb +31 -2
- data/app/views/layouts/tolk/application.html.erb +4 -3
- data/app/views/tolk/locales/all.html.erb +1 -1
- data/app/views/tolk/locales/index.html.erb +0 -1
- data/app/views/tolk/locales/show.html.erb +4 -4
- data/app/views/tolk/searches/show.html.erb +1 -1
- data/config/routes.rb +8 -5
- data/lib/tasks/tolk_tasks.rake +1 -10
- data/lib/tolk.rb +2 -0
- data/lib/tolk/engine.rb +1 -1
- metadata +52 -69
- data/README +0 -60
File without changes
|
data/app/models/tolk/locale.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Tolk
|
2
2
|
class Locale < ActiveRecord::Base
|
3
|
-
|
3
|
+
self.table_name = "tolk_locales"
|
4
4
|
|
5
5
|
MAPPING = {
|
6
6
|
'ar' => 'Arabic',
|
@@ -34,7 +34,7 @@ module Tolk
|
|
34
34
|
'nl' => 'Dutch',
|
35
35
|
'no' => 'Norwegian',
|
36
36
|
'pl' => 'Polish',
|
37
|
-
'pt-
|
37
|
+
'pt-br' => 'Portuguese (Brazilian)',
|
38
38
|
'pt-PT' => 'Portuguese (Portugal)',
|
39
39
|
'ro' => 'Romanian',
|
40
40
|
'ru' => 'Russian',
|
@@ -47,11 +47,13 @@ module Tolk
|
|
47
47
|
'tr' => 'Turkish',
|
48
48
|
'uk' => 'Ukrainian',
|
49
49
|
'vi' => 'Vietnamese',
|
50
|
-
'zh'
|
50
|
+
'zh-CN' => 'Chinese (Simplified)',
|
51
|
+
'zh-TW' => 'Chinese (Traditional)'
|
51
52
|
}
|
52
53
|
|
53
54
|
has_many :phrases, :through => :translations, :class_name => 'Tolk::Phrase'
|
54
55
|
has_many :translations, :class_name => 'Tolk::Translation', :dependent => :destroy
|
56
|
+
|
55
57
|
accepts_nested_attributes_for :translations, :reject_if => proc { |attributes| attributes['text'].blank? }
|
56
58
|
before_validation :remove_invalid_translations_from_target, :on => :update
|
57
59
|
|
@@ -103,7 +105,7 @@ module Tolk
|
|
103
105
|
self.special_prefixes.include?(prefix) || self.special_keys.include?(key)
|
104
106
|
end
|
105
107
|
|
106
|
-
PLURALIZATION_KEYS = ['
|
108
|
+
PLURALIZATION_KEYS = ['none', 'one', 'two', 'few', 'many', 'other']
|
107
109
|
def pluralization_data?(data)
|
108
110
|
keys = data.keys.map(&:to_s)
|
109
111
|
keys.all? {|k| PLURALIZATION_KEYS.include?(k) }
|
@@ -133,8 +135,8 @@ module Tolk
|
|
133
135
|
existing_ids = self.translations.all(:select => 'tolk_translations.phrase_id').map(&:phrase_id).uniq
|
134
136
|
phrases = phrases.scoped(:conditions => ['tolk_phrases.id NOT IN (?)', existing_ids]) if existing_ids.present?
|
135
137
|
|
136
|
-
result = phrases.paginate({:page => page}.merge(options))
|
137
|
-
|
138
|
+
result = phrases.paginate({:page => page, :per_page => Phrase.per_page}.merge(options))
|
139
|
+
ActiveRecord::Associations::Preloader.new result, :translations
|
138
140
|
result
|
139
141
|
end
|
140
142
|
|
@@ -148,14 +150,14 @@ module Tolk
|
|
148
150
|
self.translations.containing_text(query)
|
149
151
|
end
|
150
152
|
|
151
|
-
phrases = Tolk::Phrase.scoped(:order => 'tolk_phrases.key ASC')
|
153
|
+
phrases = Tolk::Phrase.scoped(:order => 'tolk_phrases.key ASC')
|
152
154
|
phrases = phrases.scoped(:conditions => ['tolk_phrases.id IN(?)', translations.map(&:phrase_id).uniq])
|
153
155
|
phrases.paginate({:page => page}.merge(options))
|
154
156
|
end
|
155
|
-
|
157
|
+
|
156
158
|
def search_phrases_without_translation(query, page = nil, options = {})
|
157
159
|
return phrases_without_translation(page, options) unless query.present?
|
158
|
-
|
160
|
+
|
159
161
|
phrases = Tolk::Phrase.scoped(:order => 'tolk_phrases.key ASC')
|
160
162
|
|
161
163
|
found_translations_ids = Tolk::Locale.primary_locale.translations.all(:conditions => ["tolk_translations.text LIKE ?", "%#{query}%"], :select => 'tolk_translations.phrase_id').map(&:phrase_id).uniq
|
@@ -163,7 +165,7 @@ module Tolk
|
|
163
165
|
phrases = phrases.scoped(:conditions => ['tolk_phrases.id NOT IN (?) AND tolk_phrases.id IN(?)', existing_ids, found_translations_ids]) if existing_ids.present?
|
164
166
|
|
165
167
|
result = phrases.paginate({:page => page}.merge(options))
|
166
|
-
|
168
|
+
ActiveRecord::Associations::Preloader.new result, :translations
|
167
169
|
result
|
168
170
|
end
|
169
171
|
|
@@ -189,26 +191,26 @@ module Tolk
|
|
189
191
|
MAPPING[self.name] || self.name
|
190
192
|
end
|
191
193
|
|
192
|
-
def
|
194
|
+
def get(key)
|
193
195
|
if phrase = Tolk::Phrase.find_by_key(key)
|
194
|
-
t = self.translations.
|
196
|
+
t = self.translations.where(:phrase_id => phrase.id).first
|
195
197
|
t.text if t
|
196
198
|
end
|
197
199
|
end
|
198
200
|
|
199
201
|
def translations_with_html
|
200
|
-
translations = self.translations.all(:conditions => "tolk_translations.text LIKE '%>%' AND
|
202
|
+
translations = self.translations.all(:conditions => "tolk_translations.text LIKE '%>%' AND
|
201
203
|
tolk_translations.text LIKE '%<%' AND tolk_phrases.key NOT LIKE '%_html'", :joins => :phrase)
|
202
|
-
|
204
|
+
ActiveRecord::Associations::Preloader.new translations, :phrase
|
203
205
|
translations
|
204
206
|
end
|
205
207
|
|
206
208
|
private
|
207
209
|
|
208
210
|
def remove_invalid_translations_from_target
|
209
|
-
self.translations.
|
210
|
-
|
211
|
-
self.translations.
|
211
|
+
self.translations.target.dup.each do |t|
|
212
|
+
unless t.valid?
|
213
|
+
self.translations.target.delete(t)
|
212
214
|
else
|
213
215
|
t.updated_at = Time.current # Silly hax to fool autosave into saving the record
|
214
216
|
end
|
@@ -222,12 +224,12 @@ module Tolk
|
|
222
224
|
:conditions => { :'tolk_translations.locale_id' => self.id }.merge(conditions),
|
223
225
|
:joins => :translations, :order => 'tolk_phrases.key ASC')
|
224
226
|
|
225
|
-
Tolk::Phrase.send :preload_associations, result, :translations
|
226
|
-
|
227
227
|
result.each do |phrase|
|
228
228
|
phrase.translation = phrase.translations.for(self)
|
229
229
|
end
|
230
230
|
|
231
|
+
ActiveRecord::Associations::Preloader.new result, :translations
|
232
|
+
|
231
233
|
result
|
232
234
|
end
|
233
235
|
|
data/app/models/tolk/phrase.rb
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
module Tolk
|
2
2
|
class Translation < ActiveRecord::Base
|
3
|
-
|
3
|
+
self.table_name = "tolk_translations"
|
4
4
|
|
5
5
|
scope :containing_text, lambda {|query| where("tolk_translations.text LIKE ?", "%#{query}%") }
|
6
6
|
|
7
7
|
serialize :text
|
8
8
|
validates_presence_of :text, :if => proc {|r| r.primary.blank? && !r.explicit_nil }
|
9
|
+
validate :check_matching_variables, :if => proc { |tr| tr.primary_translation.present? }
|
9
10
|
|
10
11
|
validates_uniqueness_of :phrase_id, :scope => :locale_id
|
11
12
|
|
12
13
|
belongs_to :phrase, :class_name => 'Tolk::Phrase'
|
13
14
|
belongs_to :locale, :class_name => 'Tolk::Locale'
|
15
|
+
validates_presence_of :locale_id
|
16
|
+
|
14
17
|
|
15
18
|
attr_accessor :force_set_primary_update
|
16
19
|
before_save :set_primary_updated
|
@@ -40,6 +43,7 @@ module Tolk
|
|
40
43
|
end
|
41
44
|
|
42
45
|
def text=(value)
|
46
|
+
value = value.to_s if value.kind_of?(Fixnum)
|
43
47
|
super unless value.to_s == text
|
44
48
|
end
|
45
49
|
|
@@ -51,6 +55,23 @@ module Tolk
|
|
51
55
|
end
|
52
56
|
end
|
53
57
|
|
58
|
+
def self.detect_variables(search_in)
|
59
|
+
case search_in
|
60
|
+
when String then Set.new(search_in.scan(/\{\{(\w+)\}\}/).flatten + search_in.scan(/\%\{(\w+)\}/).flatten)
|
61
|
+
when Array then search_in.inject(Set[]) { |carry, item| carry + detect_variables(item) }
|
62
|
+
when Hash then search_in.values.inject(Set[]) { |carry, item| carry + detect_variables(item) }
|
63
|
+
else Set[]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def variables
|
68
|
+
self.class.detect_variables(text)
|
69
|
+
end
|
70
|
+
|
71
|
+
def variables_match?
|
72
|
+
self.variables == primary_translation.variables
|
73
|
+
end
|
74
|
+
|
54
75
|
private
|
55
76
|
|
56
77
|
def set_explicit_nil
|
@@ -68,7 +89,6 @@ module Tolk
|
|
68
89
|
rescue ArgumentError
|
69
90
|
nil
|
70
91
|
end
|
71
|
-
|
72
92
|
end
|
73
93
|
|
74
94
|
self.text = nil if primary_translation.text.class != self.text.class
|
@@ -87,5 +107,14 @@ module Tolk
|
|
87
107
|
true
|
88
108
|
end
|
89
109
|
|
110
|
+
def check_matching_variables
|
111
|
+
unless variables_match?
|
112
|
+
if primary_translation.variables.empty? || primary_translation.variables.class == Set
|
113
|
+
self.errors.add(:text, "The original does not contain variables, so they should not be included.")
|
114
|
+
else
|
115
|
+
self.errors.add(:text, "The translation should contain the variables #{primary_translation.to_a.to_sentence}.")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
90
119
|
end
|
91
120
|
end
|
@@ -12,18 +12,19 @@
|
|
12
12
|
<%= javascript_include_tag :defaults %>
|
13
13
|
<% end %>
|
14
14
|
|
15
|
-
<%= stylesheet_link_tag "
|
15
|
+
<%= stylesheet_link_tag "tolk/reset" %>
|
16
|
+
<%= stylesheet_link_tag "tolk/screen" %>
|
16
17
|
<%= yield :head %>
|
17
18
|
</head>
|
18
19
|
|
19
20
|
<body>
|
20
21
|
<div id="container">
|
21
22
|
<div id="head">
|
22
|
-
<h1><span class="home"><%= link_to "Tolk",
|
23
|
+
<h1><span class="home"><%= link_to "Tolk", tolk.root_path %></span><%= yield :locale %></h1>
|
23
24
|
</div>
|
24
25
|
<%= yield %>
|
25
26
|
</div>
|
26
|
-
|
27
|
+
|
27
28
|
<script type="text/javascript">
|
28
29
|
$$('td textarea').each(function(element) {
|
29
30
|
element.setStyle({height: element.up('td').measure('height')+'px'});
|
@@ -4,7 +4,7 @@
|
|
4
4
|
<h3 class="switch">Completed translations <span>(<%= link_to 'See phrases missing translation', @locale %>)</span></h3>
|
5
5
|
|
6
6
|
<% if @locale.has_updated_translations? && action_name != 'updated' %>
|
7
|
-
<span class="notice">Some phrases have changed. <%= link_to "Update translations",
|
7
|
+
<span class="notice">Some phrases have changed. <%= link_to "Update translations", tolk.updated_locale_path(@locale) %>.</span>
|
8
8
|
<% end %>
|
9
9
|
|
10
10
|
<div class="search">
|
@@ -3,13 +3,13 @@
|
|
3
3
|
<% end %>
|
4
4
|
|
5
5
|
<% content_for :head do %>
|
6
|
-
<link rel="alternate" type="application/rss+xml" title="RSS" href="<%=
|
6
|
+
<link rel="alternate" type="application/rss+xml" title="RSS" href="<%= tolk.locale_path(@locale, :format => 'atom') -%>" />
|
7
7
|
<% end %>
|
8
8
|
|
9
|
-
<h3 class="switch">Phrases missing translation (<%= @locale.count_phrases_without_translation %>) <span>(<%= link_to 'See completed translations',
|
9
|
+
<h3 class="switch">Phrases missing translation (<%= @locale.count_phrases_without_translation %>) <span>(<%= link_to 'See completed translations', tolk.all_locale_path(@locale) %>)</span></h3>
|
10
10
|
|
11
11
|
<% if @locale.has_updated_translations? && action_name != 'updated' %>
|
12
|
-
<span class="notice">Some phrases have changed. <%= link_to "Update translations",
|
12
|
+
<span class="notice">Some phrases have changed. <%= link_to "Update translations", tolk.updated_locale_path(@locale) %>.</span>
|
13
13
|
<% end %>
|
14
14
|
|
15
15
|
<div class="search">
|
@@ -37,7 +37,7 @@
|
|
37
37
|
<% if params[:q].present? -%>
|
38
38
|
<%= highlight(format_i18n_value(phrase.translations.primary.text), params[:q]) -%>
|
39
39
|
<% else -%>
|
40
|
-
<%= format_i18n_value(phrase.translations.primary.text) -%>
|
40
|
+
<%= format_i18n_value(phrase.translations.primary.text).html_safe -%>
|
41
41
|
<% end -%>
|
42
42
|
<span class="key" title="<%= phrase.key %>"><%= truncate(phrase.key, :length => 100) %></span>
|
43
43
|
</td>
|
@@ -9,7 +9,7 @@
|
|
9
9
|
<div class="search_exits">
|
10
10
|
<%= link_to "Phrases missing translation", @locale %>
|
11
11
|
|
12
|
-
<%= link_to "Completed translations",
|
12
|
+
<%= link_to "Completed translations", tolk.all_locale_path(@locale) %>
|
13
13
|
</div>
|
14
14
|
|
15
15
|
<div class="translations">
|
data/config/routes.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
Tolk::Engine.routes.draw do
|
2
|
+
root :to => 'locales#index'
|
3
|
+
resources :locales do
|
4
|
+
member do
|
5
|
+
get :all
|
6
|
+
get :updated
|
7
|
+
end
|
6
8
|
end
|
9
|
+
resource :search
|
7
10
|
end
|
data/lib/tasks/tolk_tasks.rake
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
namespace :tolk do
|
2
2
|
desc "Add database tables, copy over the assets, and import existing translations"
|
3
3
|
task :setup => :environment do
|
4
|
-
Rake::Task['tolk:import_assets'].invoke
|
5
4
|
system("rails generate tolk_migration")
|
6
5
|
Rake::Task['db:migrate'].invoke
|
7
6
|
Rake::Task['tolk:sync'].invoke
|
8
7
|
Rake::Task['tolk:import'].invoke
|
9
8
|
end
|
10
|
-
|
9
|
+
|
11
10
|
desc "Sync Tolk with the default locale's yml file"
|
12
11
|
task :sync => :environment do
|
13
12
|
Tolk::Locale.sync!
|
@@ -32,12 +31,4 @@ namespace :tolk do
|
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
35
|
-
desc "Copies required assets from tolk to application's public/ directory"
|
36
|
-
task :import_assets do
|
37
|
-
tolk_assets = File.expand_path(File.join(File.dirname(__FILE__), '../../public/tolk'))
|
38
|
-
command = "cp -R #{tolk_assets} #{Rails.root}/public/"
|
39
|
-
puts command
|
40
|
-
system(command)
|
41
|
-
end
|
42
|
-
|
43
34
|
end
|
data/lib/tolk.rb
CHANGED
data/lib/tolk/engine.rb
CHANGED
metadata
CHANGED
@@ -1,63 +1,57 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: tolk
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
version: "1.0"
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- David Heinemeier Hansson
|
9
|
+
- Emilio Tagua
|
10
|
+
- Thomas Darde
|
13
11
|
autorequire:
|
14
12
|
bindir: bin
|
15
13
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
14
|
+
date: 2012-05-15 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
21
17
|
name: will_paginate
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
24
19
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 3
|
31
|
-
- 0
|
32
|
-
- pre
|
33
|
-
version: 3.0.pre
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '0'
|
34
24
|
type: :runtime
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: ya2yaml
|
38
25
|
prerelease: false
|
39
|
-
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ! '>='
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: ya2yaml
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
40
35
|
none: false
|
41
|
-
requirements:
|
36
|
+
requirements:
|
42
37
|
- - ~>
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
|
45
|
-
segments:
|
46
|
-
- 0
|
47
|
-
- 26
|
48
|
-
version: "0.26"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0.26'
|
49
40
|
type: :runtime
|
50
|
-
|
51
|
-
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.26'
|
48
|
+
description: Tolk is a web interface for doing i18n translations packaged as an engine
|
49
|
+
for Rails applications.
|
52
50
|
email: david@loudthinking.com
|
53
51
|
executables: []
|
54
|
-
|
55
52
|
extensions: []
|
56
|
-
|
57
53
|
extra_rdoc_files: []
|
58
|
-
|
59
|
-
files:
|
60
|
-
- README
|
54
|
+
files:
|
61
55
|
- MIT-LICENSE
|
62
56
|
- config/routes.rb
|
63
57
|
- init.rb
|
@@ -68,6 +62,8 @@ files:
|
|
68
62
|
- lib/tolk/import.rb
|
69
63
|
- lib/tolk/sync.rb
|
70
64
|
- lib/tolk.rb
|
65
|
+
- app/assets/stylesheets/tolk/reset.css
|
66
|
+
- app/assets/stylesheets/tolk/screen.css
|
71
67
|
- app/controllers/tolk/application_controller.rb
|
72
68
|
- app/controllers/tolk/locales_controller.rb
|
73
69
|
- app/controllers/tolk/searches_controller.rb
|
@@ -82,41 +78,28 @@ files:
|
|
82
78
|
- app/views/tolk/locales/show.html.erb
|
83
79
|
- app/views/tolk/searches/_form.html.erb
|
84
80
|
- app/views/tolk/searches/show.html.erb
|
85
|
-
|
86
|
-
- public/tolk/screen.css
|
87
|
-
has_rdoc: true
|
88
|
-
homepage: http://www.rubyonrails.org
|
81
|
+
homepage: http://github.com/tolk/tolk
|
89
82
|
licenses: []
|
90
|
-
|
91
83
|
post_install_message:
|
92
84
|
rdoc_options: []
|
93
|
-
|
94
|
-
require_paths:
|
85
|
+
require_paths:
|
95
86
|
- lib
|
96
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
88
|
none: false
|
98
|
-
requirements:
|
99
|
-
- -
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
|
102
|
-
|
103
|
-
- 0
|
104
|
-
version: "0"
|
105
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
94
|
none: false
|
107
|
-
requirements:
|
108
|
-
- -
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
|
111
|
-
segments:
|
112
|
-
- 0
|
113
|
-
version: "0"
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
114
99
|
requirements: []
|
115
|
-
|
116
100
|
rubyforge_project:
|
117
|
-
rubygems_version: 1.
|
101
|
+
rubygems_version: 1.8.24
|
118
102
|
signing_key:
|
119
103
|
specification_version: 3
|
120
104
|
summary: Rails engine providing web interface for managing i18n yaml files
|
121
105
|
test_files: []
|
122
|
-
|
data/README
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
Tolk is a Rails 3 engine designed to facilitate the translators doing the dirty work of translating your application to other languages.
|
2
|
-
|
3
|
-
* Installation & Setup
|
4
|
-
|
5
|
-
To install add the following to your Gemfile:
|
6
|
-
|
7
|
-
gem 'tolk'
|
8
|
-
|
9
|
-
To setup just run:
|
10
|
-
|
11
|
-
$ rake tolk:setup
|
12
|
-
|
13
|
-
* Usage
|
14
|
-
|
15
|
-
Tolk treats I18n.default_locale as the master source of strings to be translated. If you want the master source to be different from I18n.default_locale, you can override it by setting Tolk::Locale.primary_locale_name. Developers are expected to make all the changes to the master locale file ( en.yml by default ) and treat all the other locale.yml files as readonly files.
|
16
|
-
|
17
|
-
As tolk stores all the keys and translated strings in the database, you need to ask Tolk to update it's database from the primary yml file :
|
18
|
-
|
19
|
-
$ rake tolk:sync
|
20
|
-
|
21
|
-
The above will fetch all the new keys from en.yml and put them in the database. Additionally, it'll also get rid of the deleted keys from the database and reflect updated translations - if any.
|
22
|
-
|
23
|
-
If you already have data in your non primary locale files, you will need to import those to Tolk as a one time thing :
|
24
|
-
|
25
|
-
$ rake tolk:import
|
26
|
-
|
27
|
-
Upon visiting http://your_app.com/tolk - you will be presented with different options like creating new locale or providing translations for the existing locales. Once done with translating all the pending strings, you are can write back the new locales to filesystem :
|
28
|
-
|
29
|
-
$ rake tolk:dump_all
|
30
|
-
|
31
|
-
This will generate yml files for all non primary locales and put them in #{Rails.root}/config/locales/ directory by default.
|
32
|
-
|
33
|
-
You can use the dump_all method defined in Tolk::Locale directly and pass directory path as the argument if you want the generated files to be at a different location :
|
34
|
-
|
35
|
-
$ script/runner "Tolk::Locale.dump_all('/Users/lifo')"
|
36
|
-
|
37
|
-
You can even download the yml file using Tolk web interface by appending '.yml' to the locale url. E.g http://your_app.com/tolk/locales/de.yml
|
38
|
-
|
39
|
-
* Authentication
|
40
|
-
|
41
|
-
If you want to authenticate users who can access Tolk, you need to provide <tt>Tolk::ApplicationController.authenticator</tt> proc. For example :
|
42
|
-
|
43
|
-
# config/initializers/tolk.rb
|
44
|
-
Tolk::ApplicationController.authenticator = proc {
|
45
|
-
authenticate_or_request_with_http_basic do |user_name, password|
|
46
|
-
user_name == 'translator' && password == 'transpass'
|
47
|
-
end
|
48
|
-
}
|
49
|
-
|
50
|
-
Authenticator proc will be run from a before filter in controller context.
|
51
|
-
|
52
|
-
* Handling blank and non-string values
|
53
|
-
|
54
|
-
Tolk speaks YAML for non strings values. If you want to enter a nil values, you could just enter '~'. Similarly, for an Array value, you could enter :
|
55
|
-
|
56
|
-
---
|
57
|
-
- Sun
|
58
|
-
- Mon
|
59
|
-
|
60
|
-
And Tolk will take care of generating the appropriate entry in the YAML file.
|