Module: RemoteI18n
- Defined in:
- lib/remote_i18n.rb,
lib/remote_i18n/filter.rb,
lib/remote_i18n/version.rb,
lib/remote_i18n/integration.rb,
lib/remote_i18n/integration/rails3.rb
Defined Under Namespace
Modules: Integration, Version
Classes: Filter
Class Method Summary
collapse
Class Method Details
.add_filter? ⇒ Boolean
39
40
41
|
# File 'lib/remote_i18n.rb', line 39
def add_filter?
local_env?
end
|
.app_root ⇒ Object
64
65
66
|
# File 'lib/remote_i18n.rb', line 64
def app_root
@app_root ||= default_for_app_root
end
|
.app_root=(value) ⇒ Object
68
69
70
|
# File 'lib/remote_i18n.rb', line 68
def app_root=(value)
@app_root = value.nil? ? nil : Pathname(value.to_s)
end
|
.compile_all! ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/remote_i18n.rb', line 96
def compile_all!
I18n.backend.send("init_translations")
languages = I18n.backend.send("translations")
default_locale = I18n.locale
languages.each_key do |locale|
I18n.locale = locale
translations.each do |t|
name = t[:name]
i18n_path = t[:i18n_path]
only = t[:only]
next if !(only.include? locale.to_s)
output = I18n.translate(i18n_path)
path = output_root.join("#{name}.#{locale}.js")
compiled_output = "if(this.T === null || this.T == undefined)this.T = {};this.T.#{name} = #{output.to_json};"
FileUtils.mkdir_p File.dirname(path)
File.open(path, "w+") { |f| f.write compiled_output }
end
end
I18n.locale = default_locale
end
|
9
10
11
|
# File 'lib/remote_i18n.rb', line 9
def configure
yield self if block_given?
end
|
.debug(message) ⇒ Object
60
61
62
|
# File 'lib/remote_i18n.rb', line 60
def debug(message)
logger.debug "[RemoteI18n] #{message}"
end
|
.default_for_add_filter ⇒ Object
17
18
19
|
# File 'lib/remote_i18n.rb', line 17
def default_for_add_filter
local_env?
end
|
.default_for_app_root ⇒ Object
80
81
82
83
84
85
86
|
# File 'lib/remote_i18n.rb', line 80
def default_for_app_root
if defined?(Rails.root)
Rails.root
else
Pathname(Dir.pwd)
end
end
|
.default_for_env ⇒ Object
34
35
36
37
|
# File 'lib/remote_i18n.rb', line 34
def default_for_env
return Rails.env.to_s if defined?(Rails.env)
ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
end
|
.default_for_logger ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'lib/remote_i18n.rb', line 43
def default_for_logger
if defined?(Rails.logger)
Rails.logger
else
require 'logger'
Logger.new(STDOUT)
end
end
|
.env ⇒ Object
25
26
27
|
# File 'lib/remote_i18n.rb', line 25
def env
@env ||= default_for_env
end
|
.env=(value) ⇒ Object
29
30
31
32
|
# File 'lib/remote_i18n.rb', line 29
def env=(value)
@env = value.to_s.strip
@env = nil if @env == ''
end
|
.library_root ⇒ Object
13
14
15
|
# File 'lib/remote_i18n.rb', line 13
def library_root
@library_root ||= Pathname(__FILE__).dirname
end
|
.local_env? ⇒ Boolean
21
22
23
|
# File 'lib/remote_i18n.rb', line 21
def local_env?
%w(test development).include? RemoteI18n.env
end
|
.logger ⇒ Object
52
53
54
|
# File 'lib/remote_i18n.rb', line 52
def logger
@logger ||= default_for_logger
end
|
.logger=(value) ⇒ Object
56
57
58
|
# File 'lib/remote_i18n.rb', line 56
def logger=(value)
@logger = value
end
|
.output_root ⇒ Object
72
73
74
|
# File 'lib/remote_i18n.rb', line 72
def output_root
@output_root ||= app_root.join("public", "javascripts")
end
|
.output_root=(value) ⇒ Object
76
77
78
|
# File 'lib/remote_i18n.rb', line 76
def output_root=(value)
@output_root = value.nil? ? nil : Pathname(value.to_s)
end
|
.translate(opts) ⇒ Object
88
89
90
|
# File 'lib/remote_i18n.rb', line 88
def translate(opts)
translations << opts
end
|
.translations ⇒ Object
92
93
94
|
# File 'lib/remote_i18n.rb', line 92
def translations
@translations ||= []
end
|