phrase 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -2
- data/.travis.yml +1 -0
- data/lib/phrase.rb +1 -0
- data/lib/phrase/api/client.rb +11 -2
- data/lib/phrase/delegate.rb +6 -2
- data/lib/phrase/formats.rb +151 -0
- data/lib/phrase/formats/csv.rb +19 -0
- data/lib/phrase/{tool/formats → formats}/custom.rb +3 -1
- data/lib/phrase/formats/gettext.rb +27 -0
- data/lib/phrase/formats/gettext_template.rb +19 -0
- data/lib/phrase/formats/ini.rb +19 -0
- data/lib/phrase/formats/json.rb +19 -0
- data/lib/phrase/formats/plist.rb +19 -0
- data/lib/phrase/formats/properties.rb +19 -0
- data/lib/phrase/formats/properties_xml.rb +19 -0
- data/lib/phrase/formats/qt_phrase_book.rb +19 -0
- data/lib/phrase/formats/qt_translation_source.rb +19 -0
- data/lib/phrase/formats/resx.rb +19 -0
- data/lib/phrase/formats/resx_windowsphone.rb +19 -0
- data/lib/phrase/formats/simple_json.rb +19 -0
- data/lib/phrase/formats/strings.rb +39 -0
- data/lib/phrase/formats/tmx.rb +19 -0
- data/lib/phrase/formats/xliff.rb +19 -0
- data/lib/phrase/formats/xml.rb +49 -0
- data/lib/phrase/formats/yaml.rb +19 -0
- data/lib/phrase/formats/yaml_symfony.rb +19 -0
- data/lib/phrase/hash_flattener.rb +15 -14
- data/lib/phrase/tool.rb +1 -1
- data/lib/phrase/tool/commands/pull.rb +4 -4
- data/lib/phrase/tool/commands/push.rb +14 -6
- data/lib/phrase/tool/options.rb +2 -1
- data/lib/phrase/tool/options_factory.rb +5 -1
- data/lib/phrase/version.rb +1 -1
- metadata +43 -38
- data/lib/phrase/tool/formats.rb +0 -87
- data/lib/phrase/tool/formats/base.rb +0 -37
- data/lib/phrase/tool/formats/gettext.rb +0 -19
- data/lib/phrase/tool/formats/gettext_pot.rb +0 -11
- data/lib/phrase/tool/formats/ini.rb +0 -11
- data/lib/phrase/tool/formats/json.rb +0 -11
- data/lib/phrase/tool/formats/plist.rb +0 -11
- data/lib/phrase/tool/formats/properties.rb +0 -11
- data/lib/phrase/tool/formats/qt_phrase_book.rb +0 -11
- data/lib/phrase/tool/formats/qt_translation_source.rb +0 -11
- data/lib/phrase/tool/formats/resx.rb +0 -11
- data/lib/phrase/tool/formats/strings.rb +0 -31
- data/lib/phrase/tool/formats/xliff.rb +0 -11
- data/lib/phrase/tool/formats/xml.rb +0 -41
- data/lib/phrase/tool/formats/yaml.rb +0 -11
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/lib/phrase.rb
CHANGED
data/lib/phrase/api/client.rb
CHANGED
@@ -84,9 +84,10 @@ class Phrase::Api::Client
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
-
def upload(filename, file_content, tags=[], locale=nil)
|
87
|
+
def upload(filename, file_content, tags=[], locale=nil, format=nil)
|
88
88
|
begin
|
89
89
|
params = {
|
90
|
+
"file_format" => format,
|
90
91
|
"filename" => filename,
|
91
92
|
"file_content" => file_content,
|
92
93
|
"tags[]" => tags
|
@@ -94,7 +95,7 @@ class Phrase::Api::Client
|
|
94
95
|
params["locale_name"] = locale unless locale.nil?
|
95
96
|
perform_api_request("/translation_keys/upload", :post, params)
|
96
97
|
rescue Phrase::Api::Exceptions::ServerError => e
|
97
|
-
raise "File #{filename} could not be uploaded"
|
98
|
+
raise "File #{filename} could not be uploaded (#{e})"
|
98
99
|
end
|
99
100
|
true
|
100
101
|
end
|
@@ -121,6 +122,7 @@ private
|
|
121
122
|
def display_api_error(response)
|
122
123
|
error_message = api_error_message(response)
|
123
124
|
$stderr.puts error_message
|
125
|
+
$stderr.puts error_message
|
124
126
|
end
|
125
127
|
|
126
128
|
def api_error_message(response)
|
@@ -129,6 +131,12 @@ private
|
|
129
131
|
error = parsed(response.body)["error"]
|
130
132
|
if error.class == String
|
131
133
|
message = error
|
134
|
+
elsif error.class == Hash
|
135
|
+
error.each_pair do |field, messages|
|
136
|
+
messages.each do |msg|
|
137
|
+
message << "#{msg}"
|
138
|
+
end
|
139
|
+
end
|
132
140
|
else
|
133
141
|
message = parsed(response.body)["message"]
|
134
142
|
end
|
@@ -151,6 +159,7 @@ private
|
|
151
159
|
end
|
152
160
|
response = http_client.request(request)
|
153
161
|
code = response.code.to_i
|
162
|
+
|
154
163
|
if (code == 200)
|
155
164
|
return response.body
|
156
165
|
else
|
data/lib/phrase/delegate.rb
CHANGED
@@ -17,7 +17,11 @@ module Phrase::Delegate
|
|
17
17
|
|
18
18
|
protected
|
19
19
|
def decorated_key_name
|
20
|
-
"#{Phrase.prefix}phrase_#{
|
20
|
+
"#{Phrase.prefix}phrase_#{normalized_display_key}#{Phrase.suffix}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def normalized_display_key
|
24
|
+
@display_key.gsub("<", "[[[[[[html_open]]]]]]").gsub(">", "[[[[[[html_close]]]]]]")
|
21
25
|
end
|
22
26
|
end
|
23
|
-
end
|
27
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
module Phrase
|
4
|
+
module Formats
|
5
|
+
autoload :Custom, 'phrase/formats/custom'
|
6
|
+
autoload :Json, 'phrase/formats/json'
|
7
|
+
autoload :Csv, 'phrase/formats/csv'
|
8
|
+
autoload :Gettext, 'phrase/formats/gettext'
|
9
|
+
autoload :GettextTemplate, 'phrase/formats/gettext_template'
|
10
|
+
autoload :Ini, 'phrase/formats/ini'
|
11
|
+
autoload :Properties, 'phrase/formats/properties'
|
12
|
+
autoload :PropertiesXml, 'phrase/formats/properties_xml'
|
13
|
+
autoload :Plist, 'phrase/formats/plist'
|
14
|
+
autoload :QtPhraseBook, 'phrase/formats/qt_phrase_book'
|
15
|
+
autoload :QtTranslationSource, 'phrase/formats/qt_translation_source'
|
16
|
+
autoload :Resx, 'phrase/formats/resx'
|
17
|
+
autoload :ResxWindowsphone, 'phrase/formats/resx_windowsphone'
|
18
|
+
autoload :SimpleJson, 'phrase/formats/simple_json'
|
19
|
+
autoload :Strings, 'phrase/formats/strings'
|
20
|
+
autoload :Xml, 'phrase/formats/xml'
|
21
|
+
autoload :Tmx, 'phrase/formats/tmx'
|
22
|
+
autoload :Xliff, 'phrase/formats/xliff'
|
23
|
+
autoload :Yaml, 'phrase/formats/yaml'
|
24
|
+
autoload :YamlSymfony, 'phrase/formats/yaml_symfony'
|
25
|
+
|
26
|
+
class Base
|
27
|
+
def self.supports_extension?(extension)
|
28
|
+
self.extensions.map(&:to_s).include?(extension.to_s)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.extensions
|
32
|
+
[]
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.directory_for_locale(locale)
|
36
|
+
"./"
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.filename_for_locale(locale)
|
40
|
+
raise "not implemented"
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.extract_locale_name_from_file_path(file_path)
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.default_locale_name
|
48
|
+
Phrase::Tool::Locale.find_default_locale.try(:name)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.locale_aware?
|
52
|
+
false
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.target_directory
|
56
|
+
"phrase/locales/"
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.config
|
60
|
+
@config ||= get_config
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.get_config
|
64
|
+
config = Phrase::Tool::Config.new
|
65
|
+
config.load
|
66
|
+
end
|
67
|
+
private_class_method :config
|
68
|
+
end
|
69
|
+
|
70
|
+
SUPPORTED_FORMATS = {
|
71
|
+
custom: Phrase::Formats::Custom,
|
72
|
+
json: Phrase::Formats::Json,
|
73
|
+
csv: Phrase::Formats::Csv,
|
74
|
+
gettext: Phrase::Formats::Gettext,
|
75
|
+
gettext_template: Phrase::Formats::GettextTemplate,
|
76
|
+
ini: Phrase::Formats::Ini,
|
77
|
+
properties: Phrase::Formats::Properties,
|
78
|
+
properties_xml: Phrase::Formats::PropertiesXml,
|
79
|
+
plist: Phrase::Formats::Plist,
|
80
|
+
qph: Phrase::Formats::QtPhraseBook,
|
81
|
+
ts: Phrase::Formats::QtTranslationSource,
|
82
|
+
resx: Phrase::Formats::Resx,
|
83
|
+
resx_windowsphone: Phrase::Formats::ResxWindowsphone,
|
84
|
+
simple_json: Phrase::Formats::SimpleJson,
|
85
|
+
strings: Phrase::Formats::Strings,
|
86
|
+
xml: Phrase::Formats::Xml,
|
87
|
+
tmx: Phrase::Formats::Tmx,
|
88
|
+
xlf: Phrase::Formats::Xliff,
|
89
|
+
yml: Phrase::Formats::Yaml,
|
90
|
+
yml_symfony: Phrase::Formats::YamlSymfony,
|
91
|
+
}
|
92
|
+
|
93
|
+
def self.config
|
94
|
+
@config ||= get_config
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.get_config
|
98
|
+
config = Phrase::Tool::Config.new
|
99
|
+
config.load
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.custom_handler
|
103
|
+
handler_class_for_format(:custom)
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.target_directory(format_name)
|
107
|
+
handler = handler_class_for_format(format_name)
|
108
|
+
custom_handler.target_directory || handler.target_directory
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.directory_for_locale_in_format(locale, format_name)
|
112
|
+
handler = handler_class_for_format(format_name)
|
113
|
+
custom_directory = custom_handler.directory_for_locale(locale, format_name)
|
114
|
+
custom_directory || handler.directory_for_locale(locale)
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.filename_for_locale_in_format(locale, format_name)
|
118
|
+
handler = handler_class_for_format(format_name)
|
119
|
+
custom_filename = custom_handler.filename_for_locale(locale, format_name)
|
120
|
+
custom_filename || handler.filename_for_locale(locale)
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.file_format_exposes_locale?(file_path)
|
124
|
+
format = guess_possible_file_format_from_file_path(file_path)
|
125
|
+
format.nil? ? false : handler_class_for_format(format).locale_aware?
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.detect_locale_name_from_file_path(file_path)
|
129
|
+
format = guess_possible_file_format_from_file_path(file_path)
|
130
|
+
format.nil? ? nil : handler_class_for_format(format).extract_locale_name_from_file_path(file_path)
|
131
|
+
end
|
132
|
+
|
133
|
+
def self.handler_class_for_format(format_name)
|
134
|
+
SUPPORTED_FORMATS.fetch(format_name.to_sym)
|
135
|
+
end
|
136
|
+
private_class_method :handler_class_for_format
|
137
|
+
|
138
|
+
def self.guess_possible_file_format_from_file_path(file_path)
|
139
|
+
extension = extension_from_file_path(file_path)
|
140
|
+
possible_format = SUPPORTED_FORMATS.keys.find do |format|
|
141
|
+
SUPPORTED_FORMATS[format].send(:supports_extension?, extension)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
private_class_method :guess_possible_file_format_from_file_path
|
145
|
+
|
146
|
+
def self.extension_from_file_path(file_path)
|
147
|
+
file_path.split('.').last.downcase
|
148
|
+
end
|
149
|
+
private_class_method :extension_from_file_path
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
module Phrase
|
4
|
+
module Formats
|
5
|
+
class Csv < Phrase::Formats::Base
|
6
|
+
def self.filename_for_locale(locale)
|
7
|
+
"phrase.#{locale.name}.csv"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.locale_aware?
|
11
|
+
false
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.extensions
|
15
|
+
[:csv]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
module Phrase
|
4
|
+
module Formats
|
5
|
+
class Gettext < Phrase::Formats::Base
|
6
|
+
def self.directory_for_locale(locale)
|
7
|
+
"./#{locale.name}/"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.filename_for_locale(locale)
|
11
|
+
"#{config.domain}.po"
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.target_directory
|
15
|
+
"locales/"
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.locale_aware?
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.extensions
|
23
|
+
[:po]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
module Phrase
|
4
|
+
module Formats
|
5
|
+
class GettextTemplate < Phrase::Formats::Base
|
6
|
+
def self.filename_for_locale(locale)
|
7
|
+
"phrase.pot"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.locale_aware?
|
11
|
+
false
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.extensions
|
15
|
+
[:pot]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
module Phrase
|
4
|
+
module Formats
|
5
|
+
class Ini < Phrase::Formats::Base
|
6
|
+
def self.filename_for_locale(locale)
|
7
|
+
"phrase.#{locale.name}.ini"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.locale_aware?
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.extensions
|
15
|
+
[:ini]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
module Phrase
|
4
|
+
module Formats
|
5
|
+
class Json < Phrase::Formats::Base
|
6
|
+
def self.filename_for_locale(locale)
|
7
|
+
"phrase.#{locale.name}.json"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.locale_aware?
|
11
|
+
false
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.extensions
|
15
|
+
[:json]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
module Phrase
|
4
|
+
module Formats
|
5
|
+
class Plist < Phrase::Formats::Base
|
6
|
+
def self.filename_for_locale(locale)
|
7
|
+
"phrase.#{locale.name}.plist"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.locale_aware?
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.extensions
|
15
|
+
[:plist]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
module Phrase
|
4
|
+
module Formats
|
5
|
+
class Properties < Phrase::Formats::Base
|
6
|
+
def self.filename_for_locale(locale)
|
7
|
+
"phrase.#{locale.name}.properties"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.locale_aware?
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.extensions
|
15
|
+
[:properties]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
module Phrase
|
4
|
+
module Formats
|
5
|
+
class PropertiesXml < Phrase::Formats::Base
|
6
|
+
def self.filename_for_locale(locale)
|
7
|
+
"phrase.#{locale.name}.xml"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.locale_aware?
|
11
|
+
false
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.extensions
|
15
|
+
[:xml]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
module Phrase
|
4
|
+
module Formats
|
5
|
+
class QtPhraseBook < Phrase::Formats::Base
|
6
|
+
def self.filename_for_locale(locale)
|
7
|
+
"phrase.#{locale.name}.qph"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.locale_aware?
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.extensions
|
15
|
+
[:qph]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
module Phrase
|
4
|
+
module Formats
|
5
|
+
class QtTranslationSource < Phrase::Formats::Base
|
6
|
+
def self.filename_for_locale(locale)
|
7
|
+
"phrase.#{locale.name}.ts"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.locale_aware?
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.extensions
|
15
|
+
[:ts]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|