phrase 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,134 +1,7 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  module Phrase::Backend
4
- # require_relative 'backend/base'
5
- module Phrase::Backend::Base
6
- PREFIX = "{{__phrase_"
7
- SUFFIX = "__}}"
8
-
9
- # attr_accessor :config
10
-
11
- def translate(*args)
12
- key = lookup_normalized_key(*args)
13
- case key[:translation]
14
- when String, nil, "" then decorate_translation(key[:key])
15
- else key[:translation]
16
- end
17
- end
18
-
19
- # def load_translations(*args)
20
- # raise NotImplementedError
21
- # end
22
- #
23
- # def raw_lookup(locale, key, scope=[], options={})
24
- # I18n.backend.load_translations unless I18n.backend.initialized?
25
- # keys = I18n.normalize_keys(locale, key, scope, options[:separator])
26
- # keys.inject(I18n.backend.send(:translations)) do |result, _key|
27
- # _key = _key.to_sym
28
- # return nil unless result.is_a?(Hash) && result.has_key?(_key)
29
- # result[_key]
30
- # end
31
- # end
32
-
33
- protected
34
- def decorate_translation(key=nil)
35
- return nil unless key.presence
36
- "#{PREFIX}#{key}#{SUFFIX}"
37
- end
38
-
39
- def translation_presence(*args)
40
- I18n.translate!(*args)
41
- rescue I18n::MissingTranslationData => e
42
- nil
43
- end
44
-
45
- def lookup_normalized_key(*args)
46
- translation = translation_presence(*args)
47
- caller = identify_caller
48
-
49
- if (translation.nil? || translation.is_a?(Hash)) && caller && args.first =~ /^\./
50
- args = transform_args_for_caller(caller, *args)
51
- translation = translation_presence(*args)
52
- end
53
-
54
- new_args = split_args(*args)
55
-
56
- normalized_key = I18n::Backend::Flatten.normalize_flat_keys(*new_args)
57
- normalized_key.gsub!("..", ".")
58
-
59
- {:key => normalized_key, :translation => translation}
60
- end
61
-
62
- def identify_caller
63
- caller = nil
64
- send(:caller)[0..6].each { |string| caller = match_caller(string) unless caller }
65
- caller.present? ? find_lookup_scope(caller) : nil
66
- end
67
-
68
- def match_caller(string)
69
- string.match(/(views)(\/.+)(?>:[0-9]+:in)/)
70
- end
71
-
72
- # def extract_required_vars(*args)
73
- # excluded = ["scope", "locale"]
74
- # required_vars = args.last.is_a?(Hash) ? args.pop.keys.sort { |a, b| a.to_s <=> b.to_s } : []
75
- # required_vars.delete_if { |var| excluded.include?(var.to_s) }
76
- # end
77
-
78
- def split_args(*args)
79
- options = args.last.is_a?(Hash) ? args.pop : {}
80
- key ||= args.shift
81
- locale = options.delete(:locale) || I18n.locale
82
- return [locale, key, options[:scope], nil]
83
- end
84
-
85
- def transform_args_for_caller(caller, *args)
86
- _scope = caller
87
-
88
- options = args.last.is_a?(Hash) ? args.pop : {}
89
-
90
- if !options[:scope].presence && _scope.presence
91
- options[:scope] = _scope
92
- end
93
-
94
- args.push(options)
95
- parts = args.first.to_s.split(".").select { |e| !e.blank? }
96
- args[0] = parts[0] if parts.size == 1
97
-
98
- return args
99
- end
100
-
101
- def find_lookup_scope(caller)
102
- split_path = caller[2][1..-1].split(".")[0].split("/")
103
-
104
- template_or_partial = remove_underscore_form_partial(split_path[-1])
105
- split_path[-1] = template_or_partial
106
-
107
- split_path.map!(&:to_sym)
108
- end
109
-
110
- def remove_underscore_form_partial(template_or_partial)
111
- if template_or_partial.to_s[0,1] == "_"
112
- template_or_partial.to_s[1..-1]
113
- else
114
- template_or_partial.to_s
115
- end
116
- end
117
4
  end
118
5
 
119
- # require_relative 'backend/phrase_service'
120
- module Phrase::Backend
121
- class PhraseService
122
- include Base
123
-
124
- def initialize(args = {})
125
- # self.config = { "locales" => {}, "strings" => {} }
126
- # Phrase.available_locales = self.config["locales"].keys.map(&:to_sym)
127
- self
128
- end
129
-
130
- end
131
- end
132
- # LOCALE in keys mit schreiben, hilft der GUI!? -> manuel
133
-
134
- end
6
+ require File.join(File.dirname(__FILE__), 'backend/base')
7
+ require File.join(File.dirname(__FILE__), 'backend/phrase_service')
@@ -1,11 +1,10 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  module Phrase::Backend::Base
4
+
4
5
  PREFIX = "{{__phrase_"
5
6
  SUFFIX = "__}}"
6
-
7
- attr_accessor :config
8
-
7
+
9
8
  def translate(*args)
10
9
  key = lookup_normalized_key(*args)
11
10
  case key[:translation]
@@ -13,26 +12,7 @@ module Phrase::Backend::Base
13
12
  else key[:translation]
14
13
  end
15
14
  end
16
-
17
- def load_translations(*args)
18
- raise NotImplementedError
19
- end
20
-
21
- def store_translation(locale, key, translation, options = {})
22
- I18n.backend.load_translations unless I18n.backend.initialized?
23
- I18n.backend.store_translations(locale, key.expand_to_hash(translation))
24
- end
25
-
26
- def raw_lookup(locale, key, scope=[], options={})
27
- I18n.backend.load_translations unless I18n.backend.initialized?
28
- keys = I18n.normalize_keys(locale, key, scope, options[:separator])
29
- keys.inject(I18n.backend.send(:translations)) do |result, _key|
30
- _key = _key.to_sym
31
- return nil unless result.is_a?(Hash) && result.has_key?(_key)
32
- result[_key]
33
- end
34
- end
35
-
15
+
36
16
  protected
37
17
  def decorate_translation(key=nil)
38
18
  return nil unless key.presence
@@ -44,21 +24,21 @@ module Phrase::Backend::Base
44
24
  rescue I18n::MissingTranslationData => e
45
25
  nil
46
26
  end
47
-
27
+
48
28
  def lookup_normalized_key(*args)
49
29
  translation = translation_presence(*args)
50
30
  caller = identify_caller
51
-
31
+
52
32
  if (translation.nil? || translation.is_a?(Hash)) && caller && args.first =~ /^\./
53
33
  args = transform_args_for_caller(caller, *args)
54
34
  translation = translation_presence(*args)
55
35
  end
56
-
36
+
57
37
  new_args = split_args(*args)
58
-
38
+
59
39
  normalized_key = I18n::Backend::Flatten.normalize_flat_keys(*new_args)
60
40
  normalized_key.gsub!("..", ".")
61
-
41
+
62
42
  {:key => normalized_key, :translation => translation}
63
43
  end
64
44
 
@@ -67,49 +47,43 @@ module Phrase::Backend::Base
67
47
  send(:caller)[0..6].each { |string| caller = match_caller(string) unless caller }
68
48
  caller.present? ? find_lookup_scope(caller) : nil
69
49
  end
70
-
50
+
71
51
  def match_caller(string)
72
52
  string.match(/(views)(\/.+)(?>:[0-9]+:in)/)
73
53
  end
74
-
75
- def extract_required_vars(*args)
76
- excluded = ["scope", "locale"]
77
- required_vars = args.last.is_a?(Hash) ? args.pop.keys.sort { |a, b| a.to_s <=> b.to_s } : []
78
- required_vars.delete_if { |var| excluded.include?(var.to_s) }
79
- end
80
-
54
+
81
55
  def split_args(*args)
82
56
  options = args.last.is_a?(Hash) ? args.pop : {}
83
57
  key ||= args.shift
84
58
  locale = options.delete(:locale) || I18n.locale
85
59
  return [locale, key, options[:scope], nil]
86
60
  end
87
-
61
+
88
62
  def transform_args_for_caller(caller, *args)
89
63
  _scope = caller
90
-
64
+
91
65
  options = args.last.is_a?(Hash) ? args.pop : {}
92
-
66
+
93
67
  if !options[:scope].presence && _scope.presence
94
68
  options[:scope] = _scope
95
69
  end
96
-
70
+
97
71
  args.push(options)
98
72
  parts = args.first.to_s.split(".").select { |e| !e.blank? }
99
73
  args[0] = parts[0] if parts.size == 1
100
-
74
+
101
75
  return args
102
76
  end
103
-
77
+
104
78
  def find_lookup_scope(caller)
105
79
  split_path = caller[2][1..-1].split(".")[0].split("/")
106
-
80
+
107
81
  template_or_partial = remove_underscore_form_partial(split_path[-1])
108
82
  split_path[-1] = template_or_partial
109
-
83
+
110
84
  split_path.map!(&:to_sym)
111
85
  end
112
-
86
+
113
87
  def remove_underscore_form_partial(template_or_partial)
114
88
  if template_or_partial.to_s[0,1] == "_"
115
89
  template_or_partial.to_s[1..-1]
@@ -117,4 +91,4 @@ module Phrase::Backend::Base
117
91
  template_or_partial.to_s
118
92
  end
119
93
  end
120
- end
94
+ end
@@ -5,10 +5,8 @@ module Phrase::Backend
5
5
  include Base
6
6
 
7
7
  def initialize(args = {})
8
- self.config = { "locales" => {}, "strings" => {} }
9
- Phrase.available_locales = self.config["locales"].keys.map(&:to_sym)
10
8
  self
11
9
  end
12
10
 
13
11
  end
14
- end
12
+ end
@@ -1,4 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
+
2
3
  module Phrase
3
4
  class Config
4
5
  def enabled?
@@ -1,4 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
+
2
3
  require 'phrase'
3
4
  require 'rails'
4
5
 
@@ -1,7 +1,9 @@
1
+ # -*- encoding : utf-8 -*-
2
+
1
3
  module Phrase::Extensions
2
4
  end
3
5
 
4
- require_relative 'extensions/hash'
5
- require_relative 'extensions/string'
6
- require_relative 'extensions/base'
6
+ require File.join(File.dirname(__FILE__), 'extensions/hash')
7
+ require File.join(File.dirname(__FILE__), 'extensions/string')
8
+ require File.join(File.dirname(__FILE__), 'extensions/base')
7
9
 
@@ -1,3 +1,5 @@
1
+ # -*- encoding : utf-8 -*-
2
+
1
3
  require 'phrase/tool_config'
2
4
 
3
5
  require 'optparse'
@@ -1,3 +1,5 @@
1
+ # -*- encoding : utf-8 -*-
2
+
1
3
  require 'json'
2
4
 
3
5
  module PhraseGem
@@ -40,6 +42,7 @@ module PhraseGem
40
42
  end
41
43
 
42
44
  private
45
+
43
46
  def config
44
47
  @config ||= {}
45
48
  end
@@ -4,13 +4,13 @@ $:.unshift lib unless $:.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "phrase"
7
- s.version = "0.0.5"
7
+ s.version = "0.0.6"
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Dynport GmbH"]
10
10
  s.email = ["info@phraseapp.com"]
11
11
  s.homepage = "http://phraseapp.com"
12
12
  s.summary = %q{The best way to manage i18n.}
13
- s.description = s.summary
13
+ s.description = %q{phrase allows you to edit translations inline, on the page itself. More information at phraseapp.com}
14
14
  s.required_rubygems_version = ">= 1.3.6"
15
15
  s.rubyforge_project = "phrase"
16
16
  git_files = `git ls-files | grep -v spec/`.split("\n") rescue ''
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.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,9 +9,10 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-28 00:00:00.000000000Z
12
+ date: 2012-03-29 00:00:00.000000000Z
13
13
  dependencies: []
14
- description: The best way to manage i18n.
14
+ description: phrase allows you to edit translations inline, on the page itself. More
15
+ information at phraseapp.com
15
16
  email:
16
17
  - info@phraseapp.com
17
18
  executables: