phrase 0.4.30 → 0.4.31
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.
- checksums.yaml +4 -4
- data/lib/phrase/formats.rb +10 -9
- data/lib/phrase/tool/commands/push.rb +25 -14
- data/lib/phrase/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bf0b86279fd6eb155d420c6f6e1eb484721f89f5
|
|
4
|
+
data.tar.gz: 4ab2fdd122f8a275df89fb76f020a48772cb631c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 169aeda0534c724f894cbbd03f6e08292da3e96fa3f9f1aee4bfa7c900e1098330a577b9383606b632f9988d5992189bda3b28d5035cfc2de5c95eacfc2c7b0f
|
|
7
|
+
data.tar.gz: 457868e5efae4cf27f2e3e240776b5b5e224f3f1e834447c4200926deee552cecb1c3334b4f20a3f85b7f17c14c292dc4b9e247f3f1d649731d9e49e61c92459
|
data/lib/phrase/formats.rb
CHANGED
|
@@ -132,22 +132,23 @@ module Phrase
|
|
|
132
132
|
custom_filename || handler.filename_for_locale(locale)
|
|
133
133
|
end
|
|
134
134
|
|
|
135
|
-
def self.file_format_exposes_locale?(file_path)
|
|
136
|
-
format = guess_possible_file_format_from_file_path(file_path)
|
|
135
|
+
def self.file_format_exposes_locale?(file_path, format_name=nil)
|
|
136
|
+
format = format_name || guess_possible_file_format_from_file_path(file_path)
|
|
137
137
|
format.nil? ? false : handler_class_for_format(format).locale_aware?
|
|
138
138
|
end
|
|
139
139
|
|
|
140
|
-
def self.detect_locale_name_from_file_path(file_path)
|
|
141
|
-
format = guess_possible_file_format_from_file_path(file_path)
|
|
140
|
+
def self.detect_locale_name_from_file_path(file_path, format_name=nil)
|
|
141
|
+
format = format_name || guess_possible_file_format_from_file_path(file_path)
|
|
142
142
|
format.nil? ? nil : handler_class_for_format(format).extract_locale_name_from_file_path(file_path)
|
|
143
143
|
end
|
|
144
144
|
|
|
145
|
-
def self.
|
|
146
|
-
if format.present?
|
|
147
|
-
|
|
148
|
-
|
|
145
|
+
def self.format_renders_locale_as_extension?(format)
|
|
146
|
+
if format.present?
|
|
147
|
+
format_class = handler_class_for_format(format)
|
|
148
|
+
format_class.renders_locale_as_extension?
|
|
149
|
+
else
|
|
150
|
+
false
|
|
149
151
|
end
|
|
150
|
-
false
|
|
151
152
|
end
|
|
152
153
|
|
|
153
154
|
def self.handler_class_for_format(format_name)
|
|
@@ -7,7 +7,6 @@ class Phrase::Tool::Commands::Push < Phrase::Tool::Commands::Base
|
|
|
7
7
|
def initialize(options, args)
|
|
8
8
|
super(options, args)
|
|
9
9
|
require_auth_token!
|
|
10
|
-
|
|
11
10
|
@file_names = @args[1..-1]
|
|
12
11
|
@locale = @options.get(:locale)
|
|
13
12
|
@format = @options.get(:format)
|
|
@@ -82,16 +81,15 @@ private
|
|
|
82
81
|
end
|
|
83
82
|
|
|
84
83
|
def upload_file(file)
|
|
85
|
-
if file_valid?(file) or
|
|
84
|
+
if file_valid?(file) or renders_locale_as_extension?(@format)
|
|
86
85
|
begin
|
|
87
86
|
tagged = " (tagged: #{@tags.join(", ")})" if @tags.size > 0
|
|
88
87
|
print_message "Uploading #{file}#{tagged}..."
|
|
89
|
-
|
|
90
|
-
locale =
|
|
88
|
+
if @locale.present?
|
|
89
|
+
locale = @locale
|
|
91
90
|
else
|
|
92
|
-
locale =
|
|
91
|
+
locale = guess_locale_for_upload(file, @format)
|
|
93
92
|
end
|
|
94
|
-
locale = @locale if @locale
|
|
95
93
|
api_client.upload(file, file_content(file), @tags, locale, @format, @update_translations, @skip_unverification, @skip_upload_tags, @convert_emoji)
|
|
96
94
|
print_message "OK".green
|
|
97
95
|
rescue Exception => e
|
|
@@ -109,10 +107,6 @@ private
|
|
|
109
107
|
content
|
|
110
108
|
end
|
|
111
109
|
|
|
112
|
-
def force_use_of_default_locale?(file_path)
|
|
113
|
-
not Phrase::Formats.file_format_exposes_locale?(file_path)
|
|
114
|
-
end
|
|
115
|
-
|
|
116
110
|
def utf16_to_utf8(string)
|
|
117
111
|
string.encode("UTF-8", "UTF-16")
|
|
118
112
|
end
|
|
@@ -121,6 +115,10 @@ private
|
|
|
121
115
|
Phrase::Tool::EncodingDetector.file_seems_to_be_utf16?(file)
|
|
122
116
|
end
|
|
123
117
|
|
|
118
|
+
def renders_locale_as_extension?(format_name)
|
|
119
|
+
Phrase::Formats.format_renders_locale_as_extension?(format_name)
|
|
120
|
+
end
|
|
121
|
+
|
|
124
122
|
def file_valid?(filepath)
|
|
125
123
|
extension = filepath.split('.').last
|
|
126
124
|
allowed_file_extensions.include?(extension)
|
|
@@ -130,6 +128,23 @@ private
|
|
|
130
128
|
File.exist?(file)
|
|
131
129
|
end
|
|
132
130
|
|
|
131
|
+
def guess_locale_for_upload(file, format_name=nil)
|
|
132
|
+
if file_format_exposes_locale?(file, format_name)
|
|
133
|
+
locale = detect_locale_name_from_file_path(file, format_name)
|
|
134
|
+
else
|
|
135
|
+
locale = Phrase::Tool::Locale.find_default_locale.try(:name)
|
|
136
|
+
end
|
|
137
|
+
locale
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def file_format_exposes_locale?(file, format_name)
|
|
141
|
+
Phrase::Formats.file_format_exposes_locale?(file, format_name)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def detect_locale_name_from_file_path(file, format_name)
|
|
145
|
+
Phrase::Formats.detect_locale_name_from_file_path(file, format_name)
|
|
146
|
+
end
|
|
147
|
+
|
|
133
148
|
def valid_tags_are_given?(tags)
|
|
134
149
|
tags.all? { |tag| Phrase::Tool::TagValidator.valid?(tag) }
|
|
135
150
|
end
|
|
@@ -138,10 +153,6 @@ private
|
|
|
138
153
|
File.exist?(RAILS_DEFAULT_FOLDER) && File.directory?(RAILS_DEFAULT_FOLDER)
|
|
139
154
|
end
|
|
140
155
|
|
|
141
|
-
def detect_locale_name_from_file_path(file_path)
|
|
142
|
-
Phrase::Formats.detect_locale_name_from_file_path(file_path)
|
|
143
|
-
end
|
|
144
|
-
|
|
145
156
|
def allowed_file_extensions
|
|
146
157
|
extensions = []
|
|
147
158
|
Phrase::Formats::SUPPORTED_FORMATS.each do |format, handler|
|
data/lib/phrase/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: phrase
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.31
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dynport GmbH
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-11-
|
|
11
|
+
date: 2014-11-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: colorize
|