phrase 0.4.14 → 0.4.15
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 +15 -0
- data/lib/ext/hash.rb +1 -1
- data/lib/generators/phrase/install_generator.rb +1 -1
- data/lib/generators/templates/phrase.rb +4 -4
- data/lib/phrase/adapters/fast_gettext.rb +3 -3
- data/lib/phrase/api/client.rb +27 -27
- data/lib/phrase/api/config.rb +3 -3
- data/lib/phrase/api/exceptions.rb +1 -1
- data/lib/phrase/api/query_params.rb +2 -2
- data/lib/phrase/backend/phrase_service.rb +12 -12
- data/lib/phrase/cache.rb +7 -7
- data/lib/phrase/config.rb +18 -18
- data/lib/phrase/delegate.rb +2 -2
- data/lib/phrase/delegate/fast_gettext.rb +1 -1
- data/lib/phrase/delegate/i18n.rb +26 -26
- data/lib/phrase/formats.rb +15 -13
- data/lib/phrase/formats/csv.rb +1 -1
- data/lib/phrase/formats/custom.rb +2 -2
- data/lib/phrase/formats/gettext.rb +1 -1
- data/lib/phrase/formats/ini.rb +1 -1
- data/lib/phrase/formats/json.rb +1 -1
- data/lib/phrase/formats/node_json.rb +23 -0
- data/lib/phrase/formats/php_array.rb +1 -1
- data/lib/phrase/formats/plist.rb +1 -1
- data/lib/phrase/formats/properties.rb +1 -1
- data/lib/phrase/formats/properties_xml.rb +1 -1
- data/lib/phrase/formats/qt_phrase_book.rb +1 -1
- data/lib/phrase/formats/qt_translation_source.rb +2 -2
- data/lib/phrase/formats/resx.rb +1 -1
- data/lib/phrase/formats/resx_windowsphone.rb +1 -1
- data/lib/phrase/formats/simple_json.rb +2 -2
- data/lib/phrase/formats/strings.rb +4 -4
- data/lib/phrase/formats/tmx.rb +2 -2
- data/lib/phrase/formats/xliff.rb +2 -2
- data/lib/phrase/formats/xml.rb +6 -6
- data/lib/phrase/formats/yaml.rb +2 -2
- data/lib/phrase/formats/yaml_symfony.rb +2 -2
- data/lib/phrase/tool.rb +2 -2
- data/lib/phrase/tool/commands.rb +1 -1
- data/lib/phrase/tool/commands/base.rb +14 -14
- data/lib/phrase/tool/commands/init.rb +4 -4
- data/lib/phrase/tool/commands/pull.rb +13 -13
- data/lib/phrase/tool/commands/show_help.rb +1 -1
- data/lib/phrase/tool/commands/show_version.rb +3 -3
- data/lib/phrase/tool/commands/tags.rb +1 -1
- data/lib/phrase/tool/config.rb +3 -3
- data/lib/phrase/tool/encoding_detector.rb +3 -3
- data/lib/phrase/tool/locale.rb +8 -8
- data/lib/phrase/tool/options.rb +3 -3
- data/lib/phrase/tool/options_factory.rb +11 -11
- data/lib/phrase/tool/tag_validator.rb +2 -2
- data/lib/phrase/version.rb +1 -1
- data/lib/phrase/view_helpers.rb +2 -2
- metadata +66 -37
@@ -7,11 +7,11 @@ module Phrase
|
|
7
7
|
name = locale.code || locale.name
|
8
8
|
"#{formatted(name)}.lproj"
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def self.filename_for_locale(locale)
|
12
12
|
"Localizable.strings"
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def self.target_directory
|
16
16
|
"./"
|
17
17
|
end
|
@@ -19,11 +19,11 @@ module Phrase
|
|
19
19
|
def self.extract_locale_name_from_file_path(file_path)
|
20
20
|
file_path.scan(/\/([a-zA-Z\-_]*).lproj\//i).first.try(:first)
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def self.locale_aware?
|
24
24
|
true
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def self.formatted(name)
|
28
28
|
return name unless name.include?("-")
|
29
29
|
parts = name.split("-")
|
data/lib/phrase/formats/tmx.rb
CHANGED
data/lib/phrase/formats/xliff.rb
CHANGED
data/lib/phrase/formats/xml.rb
CHANGED
@@ -5,13 +5,13 @@ module Phrase
|
|
5
5
|
class Xml < Phrase::Formats::Base
|
6
6
|
def self.directory_for_locale(locale)
|
7
7
|
if locale.default?
|
8
|
-
"values"
|
8
|
+
"values"
|
9
9
|
else
|
10
10
|
name = locale.code || locale.name
|
11
11
|
"values-#{formatted(name)}"
|
12
12
|
end
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def self.filename_for_locale(locale)
|
16
16
|
"strings.xml"
|
17
17
|
end
|
@@ -19,7 +19,7 @@ module Phrase
|
|
19
19
|
def self.target_directory
|
20
20
|
"res/"
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def self.extract_locale_name_from_file_path(file_path)
|
24
24
|
return default_locale_name if file_path.scan(/\/values\/strings.xml/i).first
|
25
25
|
locale_part = file_path.scan(/\/values-([a-zA-Z\-_]*)\/strings.xml/i).first.try(:first)
|
@@ -29,18 +29,18 @@ module Phrase
|
|
29
29
|
locale_part
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def self.locale_aware?
|
34
34
|
true
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def self.formatted(name)
|
38
38
|
return name unless name.include?("-")
|
39
39
|
parts = name.split("-")
|
40
40
|
"#{parts.first}-r#{parts.last.upcase}"
|
41
41
|
end
|
42
42
|
private_class_method :formatted
|
43
|
-
|
43
|
+
|
44
44
|
def self.extensions
|
45
45
|
[:xml]
|
46
46
|
end
|
data/lib/phrase/formats/yaml.rb
CHANGED
data/lib/phrase/tool.rb
CHANGED
@@ -12,7 +12,7 @@ class Phrase::Tool
|
|
12
12
|
autoload :TagValidator, 'phrase/tool/tag_validator'
|
13
13
|
autoload :EncodingDetector, 'phrase/tool/encoding_detector'
|
14
14
|
autoload :Locale, 'phrase/tool/locale'
|
15
|
-
|
15
|
+
|
16
16
|
def initialize(argv)
|
17
17
|
@args = argv
|
18
18
|
end
|
@@ -20,7 +20,7 @@ class Phrase::Tool
|
|
20
20
|
def run
|
21
21
|
command_name = @args.first
|
22
22
|
@options = Phrase::Tool::Options.new(@args, command_name)
|
23
|
-
|
23
|
+
|
24
24
|
command = case command_name
|
25
25
|
when /init/
|
26
26
|
Phrase::Tool::Commands::Init.new(@options, @args)
|
data/lib/phrase/tool/commands.rb
CHANGED
@@ -6,36 +6,36 @@ module Phrase::Tool::Commands
|
|
6
6
|
@options = options
|
7
7
|
@args = args
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def execute!
|
11
11
|
raise "not implemented"
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def require_auth_token!
|
15
15
|
unless config.secret and config.secret.present?
|
16
16
|
print_error "No auth token present. You need to initialize phrase first."
|
17
17
|
exit_command
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def self.print_error(msg)
|
22
22
|
$stderr.puts msg.red
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def self.print_server_error(msg, location=nil)
|
26
26
|
error_message = "#{msg}"
|
27
27
|
error_message << " (#{location})" unless location.nil?
|
28
28
|
print_error error_message
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def self.print_message(msg)
|
32
32
|
$stdout.puts msg
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def self.exit_command(status = false)
|
36
36
|
exit(status)
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
protected
|
40
40
|
def get_option(name)
|
41
41
|
options.get(name)
|
@@ -44,32 +44,32 @@ module Phrase::Tool::Commands
|
|
44
44
|
def api_client
|
45
45
|
Phrase::Api::Client.new(config.secret)
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def config
|
49
49
|
@config ||= get_config
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
def get_config
|
53
53
|
config = Phrase::Tool::Config.new
|
54
54
|
config.load
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
def options
|
58
58
|
@options
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
def print_error(msg)
|
62
62
|
self.class.print_error(msg)
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
def print_server_error(message, location=nil)
|
66
66
|
self.class.print_server_error(message, location)
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
def print_message(msg)
|
70
70
|
self.class.print_message(msg)
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
def exit_command(status = false)
|
74
74
|
self.class.exit_command(status)
|
75
75
|
end
|
@@ -4,7 +4,7 @@ class Phrase::Tool::Commands::Init < Phrase::Tool::Commands::Base
|
|
4
4
|
def initialize(options, args)
|
5
5
|
super(options, args)
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def execute!
|
9
9
|
secret = get_option(:secret)
|
10
10
|
if secret.present?
|
@@ -23,7 +23,7 @@ class Phrase::Tool::Commands::Init < Phrase::Tool::Commands::Base
|
|
23
23
|
exit_command
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
private
|
28
28
|
def create_locale(name)
|
29
29
|
begin
|
@@ -33,7 +33,7 @@ private
|
|
33
33
|
print_message "Notice: Locale \"#{name}\" could not be created (maybe it already exists)".light_red
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def make_locale_default(name)
|
38
38
|
begin
|
39
39
|
api_client.make_locale_default(name)
|
@@ -43,7 +43,7 @@ private
|
|
43
43
|
print_server_error(e.message)
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
def print_auth_token_error
|
48
48
|
print_error "No auth token was given"
|
49
49
|
print_error "Please provide the --secret=YOUR_SECRET parameter."
|
@@ -3,20 +3,20 @@
|
|
3
3
|
class Phrase::Tool::Commands::Pull < Phrase::Tool::Commands::Base
|
4
4
|
ALLOWED_DOWNLOAD_FORMATS = Phrase::Formats::SUPPORTED_FORMATS.keys.map(&:to_s)
|
5
5
|
DEFAULT_DOWNLOAD_FORMAT = "yml"
|
6
|
-
|
6
|
+
|
7
7
|
def initialize(options, args)
|
8
8
|
super(options, args)
|
9
9
|
require_auth_token!
|
10
|
-
|
10
|
+
|
11
11
|
@locale = @args[1]
|
12
|
-
|
12
|
+
|
13
13
|
# TODO: remove DEFAULT_DOWNLOAD_FORMAT when phrase app has been updated
|
14
14
|
@format = @options.get(:format) || config.format || DEFAULT_DOWNLOAD_FORMAT
|
15
15
|
@target = @options.get(:target)
|
16
16
|
@tag = @options.get(:tag)
|
17
17
|
@target ||= Phrase::Formats.target_directory(@format) if format_valid?(@format)
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def execute!
|
21
21
|
(print_error("Invalid format: #{@format}") and exit_command) unless format_valid?(@format)
|
22
22
|
locales_to_download.compact.each do |locale|
|
@@ -24,7 +24,7 @@ class Phrase::Tool::Commands::Pull < Phrase::Tool::Commands::Base
|
|
24
24
|
fetch_translations_for_locale(locale, @format, @tag)
|
25
25
|
end
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
private
|
29
29
|
def fetch_translations_for_locale(locale, format, tag=nil)
|
30
30
|
begin
|
@@ -35,7 +35,7 @@ private
|
|
35
35
|
print_server_error(e.message)
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def store_content_in_locale_file(locale, content)
|
40
40
|
directory = Phrase::Formats.directory_for_locale_in_format(locale, @format)
|
41
41
|
filename = Phrase::Formats.filename_for_locale_in_format(locale, @format)
|
@@ -56,7 +56,7 @@ private
|
|
56
56
|
def clean_path(str)
|
57
57
|
str.gsub("/./", "/")
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def fetch_locales
|
61
61
|
begin
|
62
62
|
Phrase::Tool::Locale.all
|
@@ -66,15 +66,15 @@ private
|
|
66
66
|
exit_command
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
def format_valid?(format)
|
71
71
|
format.nil? or ALLOWED_DOWNLOAD_FORMATS.include?(format)
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
def base_directory
|
75
75
|
directory = @target
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
# TODO: test
|
79
79
|
def locales_to_download
|
80
80
|
if user_specified_a_locale?
|
@@ -83,19 +83,19 @@ private
|
|
83
83
|
all_locales
|
84
84
|
end
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
# TODO: test
|
88
88
|
def specified_locale
|
89
89
|
locale = all_locales.select { |locale| locale.name == @locale }.first
|
90
90
|
(print_error("Locale #{@locale} does not exist") and exit_command) if locale.nil?
|
91
91
|
locale
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
# TODO: test
|
95
95
|
def all_locales
|
96
96
|
@all_locales_from_server ||= fetch_locales
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
# TODO: test
|
100
100
|
def user_specified_a_locale?
|
101
101
|
@locale and @locale.strip != ''
|
@@ -13,7 +13,7 @@ private
|
|
13
13
|
|
14
14
|
def show_help
|
15
15
|
msg = "usage: phrase <command> [<args>]\n"
|
16
|
-
Phrase::Tool::Commands.possible_commands.each do |command, suffix|
|
16
|
+
Phrase::Tool::Commands.possible_commands.each do |command, suffix|
|
17
17
|
msg << " #{extract_help(command)}\n"
|
18
18
|
end
|
19
19
|
|
@@ -4,13 +4,13 @@ class Phrase::Tool::Commands::ShowVersion < Phrase::Tool::Commands::Base
|
|
4
4
|
def initialize(options, args)
|
5
5
|
super(options, args)
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def execute!
|
9
9
|
show_version
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
private
|
13
|
-
|
13
|
+
|
14
14
|
def show_version
|
15
15
|
print_message "phrase version #{Phrase::VERSION}"
|
16
16
|
end
|
data/lib/phrase/tool/config.rb
CHANGED
@@ -14,7 +14,7 @@ class Phrase::Tool::Config
|
|
14
14
|
end
|
15
15
|
self
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def secret
|
19
19
|
config["secret"]
|
20
20
|
end
|
@@ -50,7 +50,7 @@ class Phrase::Tool::Config
|
|
50
50
|
config["format"] = new_domain
|
51
51
|
save_config!
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def target_directory
|
55
55
|
config["target_directory"]
|
56
56
|
end
|
@@ -78,7 +78,7 @@ class Phrase::Tool::Config
|
|
78
78
|
save_config!
|
79
79
|
end
|
80
80
|
|
81
|
-
private
|
81
|
+
private
|
82
82
|
def config
|
83
83
|
@config ||= {}
|
84
84
|
end
|