phrase 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +2 -0
- data/lib/phrase.rb +12 -0
- data/lib/phrase/backend/base.rb +12 -16
- data/lib/phrase/engine.rb +12 -10
- data/lib/phrase/extensions/hash.rb +1 -0
- data/phrase.gemspec +3 -2
- metadata +14 -3
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/lib/phrase.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
|
3
|
+
require 'active_support/all'
|
4
|
+
|
3
5
|
module Phrase
|
4
6
|
autoload :Config, 'phrase/config'
|
5
7
|
|
6
8
|
class << self
|
9
|
+
|
7
10
|
def config
|
8
11
|
Thread.current[:phrase_config] ||= Phrase::Config.new
|
9
12
|
end
|
@@ -32,3 +35,12 @@ module Phrase
|
|
32
35
|
require 'phrase/engine'
|
33
36
|
require 'phrase/backend'
|
34
37
|
end
|
38
|
+
|
39
|
+
module I18n
|
40
|
+
class << self
|
41
|
+
def translate(*args)
|
42
|
+
Phrase.backend.translate(*args)
|
43
|
+
end
|
44
|
+
alias_method :t, :translate
|
45
|
+
end
|
46
|
+
end
|
data/lib/phrase/backend/base.rb
CHANGED
@@ -4,10 +4,7 @@ module Phrase::Backend::Base
|
|
4
4
|
|
5
5
|
def translate(*args)
|
6
6
|
key = lookup_normalized_key(*args)
|
7
|
-
|
8
|
-
when String, nil, "" then decorate_translation(key[:key])
|
9
|
-
else key[:translation]
|
10
|
-
end
|
7
|
+
decorate_translation(key[:key])
|
11
8
|
end
|
12
9
|
|
13
10
|
protected
|
@@ -16,19 +13,11 @@ module Phrase::Backend::Base
|
|
16
13
|
"#{Phrase.prefix}phrase_#{key}#{Phrase.suffix}"
|
17
14
|
end
|
18
15
|
|
19
|
-
def translation_presence(*args)
|
20
|
-
I18n.translate!(*args)
|
21
|
-
rescue I18n::MissingTranslationData => e
|
22
|
-
nil
|
23
|
-
end
|
24
|
-
|
25
16
|
def lookup_normalized_key(*args)
|
26
|
-
translation = translation_presence(*args)
|
27
17
|
caller = identify_caller
|
28
18
|
|
29
|
-
if
|
19
|
+
if caller && args.first =~ /^\./
|
30
20
|
args = transform_args_for_caller(caller, *args)
|
31
|
-
translation = translation_presence(*args)
|
32
21
|
end
|
33
22
|
|
34
23
|
new_args = split_args(*args)
|
@@ -36,13 +25,20 @@ module Phrase::Backend::Base
|
|
36
25
|
normalized_key = I18n::Backend::Flatten.normalize_flat_keys(*new_args)
|
37
26
|
normalized_key.gsub!("..", ".")
|
38
27
|
|
39
|
-
{:key => normalized_key
|
28
|
+
{:key => normalized_key}
|
40
29
|
end
|
41
30
|
|
42
31
|
def identify_caller
|
43
32
|
caller = nil
|
44
|
-
send(:caller)[0..6].each
|
45
|
-
|
33
|
+
send(:caller)[0..6].each do |string|
|
34
|
+
caller = match_caller(string) unless caller
|
35
|
+
end
|
36
|
+
|
37
|
+
if caller && caller.present?
|
38
|
+
find_lookup_scope(caller)
|
39
|
+
else
|
40
|
+
nil
|
41
|
+
end
|
46
42
|
end
|
47
43
|
|
48
44
|
def match_caller(string)
|
data/lib/phrase/engine.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
|
3
3
|
require 'phrase'
|
4
|
-
require '
|
4
|
+
require 'i18n'
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
if defined? Rails
|
7
|
+
module Phrase
|
8
|
+
class Engine < Rails::Engine
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
initializer 'phrase' do |app|
|
11
|
+
ActiveSupport.on_load(:action_view) do
|
12
|
+
::ActionView::Base.send :include, Phrase::Extensions::Base
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
ActiveSupport.on_load(:action_controller) do
|
16
|
+
::ActionController::Base.send :include, Phrase::Extensions::Base
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
19
|
-
end
|
21
|
+
end
|
data/phrase.gemspec
CHANGED
@@ -4,7 +4,7 @@ $:.unshift lib unless $:.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "phrase"
|
7
|
-
s.version = "0.0.
|
7
|
+
s.version = "0.0.8"
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Dynport GmbH"]
|
10
10
|
s.email = ["info@phraseapp.com"]
|
@@ -16,5 +16,6 @@ Gem::Specification.new do |s|
|
|
16
16
|
git_files = `git ls-files | grep -v spec/`.split("\n") rescue ''
|
17
17
|
s.files = git_files
|
18
18
|
s.executables = %w(phrase)
|
19
|
-
s.require_paths = ["lib"]
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.add_dependency('activesupport', '~> 3.0')
|
20
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phrase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,19 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
13
|
-
dependencies:
|
12
|
+
date: 2012-04-18 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: &70124418301040 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70124418301040
|
14
25
|
description: phrase allows you to edit translations inline, on the page itself. More
|
15
26
|
information at phraseapp.com
|
16
27
|
email:
|