tml 5.6.5 → 5.7.1

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.
@@ -0,0 +1,54 @@
1
+ # encoding: UTF-8
2
+ #--
3
+ # Copyright (c) 2016 Translation Exchange, Inc
4
+ #
5
+ # _______ _ _ _ ______ _
6
+ # |__ __| | | | | (_) | ____| | |
7
+ # | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
8
+ # | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
9
+ # | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
10
+ # |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
11
+ # __/ |
12
+ # |___/
13
+ # Permission is hereby granted, free of charge, to any person obtaining
14
+ # a copy of this software and associated documentation files (the
15
+ # "Software"), to deal in the Software without restriction, including
16
+ # without limitation the rights to use, copy, modify, merge, publish,
17
+ # distribute, sublicense, and/or sell copies of the Software, and to
18
+ # permit persons to whom the Software is furnished to do so, subject to
19
+ # the following conditions:
20
+ #
21
+ # The above copyright notice and this permission notice shall be
22
+ # included in all copies or substantial portions of the Software.
23
+ #
24
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
+ #++
32
+
33
+ #######################################################################
34
+ #
35
+ # Map Token
36
+ #
37
+ # {0} tagged himself/herself in {1,choice,singular#{1,number} {2,map,photo#photo|video#video}|plural#{1,number} {2,map,photo#photos|video#videos}}.
38
+ #
39
+ #######################################################################
40
+
41
+ class Tml::Tokens::XMessage::Map < Tml::Tokens::Data
42
+
43
+ attr_accessor :params
44
+
45
+ def initialize(label, opts)
46
+ @label = label
47
+ @short_name = opts[:index]
48
+ @full_name = "{#{@short_name}}"
49
+ @params = opts[:styles].collect{|style| style[:key]}
50
+ @case_keys = []
51
+ @context_keys = []
52
+ end
53
+
54
+ end
@@ -34,7 +34,7 @@ require 'digest/md5'
34
34
 
35
35
  class Tml::TranslationKey < Tml::Base
36
36
  belongs_to :application, :language
37
- attributes :id, :key, :label, :description, :locale, :level
37
+ attributes :id, :key, :label, :description, :locale, :level, :syntax
38
38
  has_many :translations # hashed by language
39
39
 
40
40
  def initialize(attrs = {})
@@ -68,6 +68,7 @@ class Tml::TranslationKey < Tml::Base
68
68
  end
69
69
 
70
70
  def set_translations(locale, translations)
71
+ return unless translations
71
72
  translations.each do |translation|
72
73
  translation.locale ||= locale
73
74
  translation.translation_key = self
@@ -199,6 +200,12 @@ class Tml::TranslationKey < Tml::Base
199
200
  end
200
201
 
201
202
  def substitute_tokens(translated_label, token_values, language, options = {})
203
+ if options[:syntax] == 'xmessage'
204
+ # pp "Translating #{translated_label} using xmessage syntax"
205
+ tokenizer = Tml::Tokenizers::XMessage.new(translated_label)
206
+ return tokenizer.substitute(language, token_values, options)
207
+ end
208
+
202
209
  if Tml::Tokenizers::Decoration.required?(translated_label)
203
210
  translated_label = Tml::Tokenizers::Decoration.new(translated_label, token_values, :allowed_tokens => decoration_tokens).substitute
204
211
  end
data/lib/tml/utils.rb CHANGED
@@ -41,7 +41,7 @@ module Tml
41
41
  def self.normalize_tr_params(label, description, tokens, options)
42
42
  return label if label.is_a?(Hash)
43
43
 
44
- if description.is_a?(Hash)
44
+ if description.is_a?(Hash) or description.is_a?(Array)
45
45
  return {
46
46
  :label => label,
47
47
  :description => nil,
data/lib/tml/version.rb CHANGED
@@ -31,7 +31,7 @@
31
31
  #++
32
32
 
33
33
  module Tml
34
- VERSION = '5.6.5'
34
+ VERSION = '5.7.1'
35
35
 
36
36
  def self.full_version
37
37
  "tml-ruby v#{Tml::VERSION} (Faraday v#{Faraday::VERSION})"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tml
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.6.5
4
+ version: 5.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Berkovich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-23 00:00:00.000000000 Z
11
+ date: 2017-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -84,9 +84,16 @@ files:
84
84
  - lib/tml/tokenizers/data.rb
85
85
  - lib/tml/tokenizers/decoration.rb
86
86
  - lib/tml/tokenizers/dom.rb
87
+ - lib/tml/tokenizers/x_message.rb
87
88
  - lib/tml/tokens/data.rb
89
+ - lib/tml/tokens/decoration.rb
90
+ - lib/tml/tokens/map.rb
88
91
  - lib/tml/tokens/method.rb
89
92
  - lib/tml/tokens/transform.rb
93
+ - lib/tml/tokens/x_message/choice.rb
94
+ - lib/tml/tokens/x_message/data.rb
95
+ - lib/tml/tokens/x_message/decoration.rb
96
+ - lib/tml/tokens/x_message/map.rb
90
97
  - lib/tml/translation.rb
91
98
  - lib/tml/translation_key.rb
92
99
  - lib/tml/translator.rb