phrase 0.4.8 → 0.4.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/lib/phrase/tool/commands.rb +36 -0
- data/lib/phrase/tool/commands/base.rb +4 -4
- data/lib/phrase/tool/commands/push.rb +19 -19
- data/lib/phrase/tool/commands/show_help.rb +11 -15
- data/lib/phrase/tool/options.rb +1 -31
- data/lib/phrase/tool/options_factory.rb +10 -0
- data/lib/phrase/version.rb +1 -1
- data/phrase.gemspec +1 -1
- metadata +26 -26
data/.gitignore
CHANGED
data/lib/phrase/tool/commands.rb
CHANGED
@@ -1,6 +1,42 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
|
3
3
|
module Phrase::Tool::Commands
|
4
|
+
def self.possible_commands_with_options
|
5
|
+
{
|
6
|
+
default: {
|
7
|
+
version: false,
|
8
|
+
help: false
|
9
|
+
},
|
10
|
+
init: {
|
11
|
+
secret: "",
|
12
|
+
default_locale: "en",
|
13
|
+
domain: "phrase",
|
14
|
+
format: nil,
|
15
|
+
locale_filename: nil,
|
16
|
+
locale_directory: nil,
|
17
|
+
target_directory: nil
|
18
|
+
},
|
19
|
+
push: {
|
20
|
+
tags: [],
|
21
|
+
recursive: false,
|
22
|
+
locale: nil,
|
23
|
+
format: nil,
|
24
|
+
update_translations: false
|
25
|
+
},
|
26
|
+
pull: {
|
27
|
+
format: nil,
|
28
|
+
target: nil,
|
29
|
+
tag: nil
|
30
|
+
},
|
31
|
+
tags: {
|
32
|
+
list: true
|
33
|
+
}
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.possible_commands
|
38
|
+
self.possible_commands_with_options.keys
|
39
|
+
end
|
4
40
|
end
|
5
41
|
|
6
42
|
require "phrase/tool/commands/base"
|
@@ -32,8 +32,8 @@ module Phrase::Tool::Commands
|
|
32
32
|
$stdout.puts msg
|
33
33
|
end
|
34
34
|
|
35
|
-
def self.exit_command
|
36
|
-
exit()
|
35
|
+
def self.exit_command(status = false)
|
36
|
+
exit(status)
|
37
37
|
end
|
38
38
|
|
39
39
|
protected
|
@@ -70,8 +70,8 @@ module Phrase::Tool::Commands
|
|
70
70
|
self.class.print_message(msg)
|
71
71
|
end
|
72
72
|
|
73
|
-
def exit_command
|
74
|
-
self.class.exit_command
|
73
|
+
def exit_command(status = false)
|
74
|
+
self.class.exit_command(status)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
@@ -3,11 +3,11 @@
|
|
3
3
|
class Phrase::Tool::Commands::Push < Phrase::Tool::Commands::Base
|
4
4
|
FORMATS_CONTAINING_LOCALE = %q(po yml qph ts xlf)
|
5
5
|
RAILS_DEFAULT_FOLDER = "./config/locales/"
|
6
|
-
|
6
|
+
|
7
7
|
def initialize(options, args)
|
8
8
|
super(options, args)
|
9
9
|
require_auth_token!
|
10
|
-
|
10
|
+
|
11
11
|
@file_names = @args[1..-1]
|
12
12
|
@locale = @options.get(:locale)
|
13
13
|
@format = @options.get(:format)
|
@@ -15,13 +15,13 @@ class Phrase::Tool::Commands::Push < Phrase::Tool::Commands::Base
|
|
15
15
|
@recursive = @options.get(:recursive)
|
16
16
|
@update_translations = @options.get(:update_translations)
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def execute!
|
20
20
|
unless @tags.empty? or valid_tags_are_given?(@tags)
|
21
21
|
print_error "Invalid tags: Only letters, numbers, underscores and dashes are allowed"
|
22
22
|
exit_command
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
files = choose_files_to_upload(@file_names, @recursive)
|
26
26
|
|
27
27
|
if files.empty?
|
@@ -31,7 +31,7 @@ class Phrase::Tool::Commands::Push < Phrase::Tool::Commands::Base
|
|
31
31
|
upload_files(files)
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
private
|
36
36
|
def choose_files_to_upload(file_names, recursive=false)
|
37
37
|
files = []
|
@@ -40,14 +40,14 @@ private
|
|
40
40
|
if rails_default_locale_folder_available?
|
41
41
|
file_names = [RAILS_DEFAULT_FOLDER]
|
42
42
|
print_message "No file or directory specified, using #{RAILS_DEFAULT_FOLDER}"
|
43
|
-
else
|
43
|
+
else
|
44
44
|
print_error "Need either a file or directory:"
|
45
45
|
print_error "phrase push FILE"
|
46
46
|
print_error "phrase push DIRECTORY"
|
47
47
|
exit_command
|
48
48
|
end
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
file_names.each do |file_name|
|
52
52
|
if File.directory?(file_name)
|
53
53
|
pattern = recursive ? "#{File.expand_path(file_name)}/**/*" : "#{File.expand_path(file_name)}/**"
|
@@ -55,13 +55,13 @@ private
|
|
55
55
|
else
|
56
56
|
files << file_name
|
57
57
|
end
|
58
|
-
end
|
58
|
+
end
|
59
59
|
|
60
|
-
files
|
60
|
+
files.reject { |file| File.directory?(file) }
|
61
61
|
end
|
62
62
|
|
63
63
|
def upload_files(files)
|
64
|
-
files.each do |file|
|
64
|
+
files.each do |file|
|
65
65
|
if file_exists?(file)
|
66
66
|
upload_file(file)
|
67
67
|
else
|
@@ -69,7 +69,7 @@ private
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
def upload_file(file)
|
74
74
|
if file_valid?(file)
|
75
75
|
begin
|
@@ -91,25 +91,25 @@ private
|
|
91
91
|
print_error "Notice: Could not upload #{file} (type not supported)"
|
92
92
|
end
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
def file_content(file)
|
96
96
|
content = File.open(file).read
|
97
97
|
content = utf16_to_utf8(content) if file_seems_to_be_utf16?(file)
|
98
98
|
content
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
def force_use_of_default_locale?(file_path)
|
102
102
|
not Phrase::Formats.file_format_exposes_locale?(file_path)
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
def utf16_to_utf8(string)
|
106
106
|
string.encode("UTF-8", "UTF-16")
|
107
107
|
end
|
108
|
-
|
108
|
+
|
109
109
|
def file_seems_to_be_utf16?(file)
|
110
110
|
Phrase::Tool::EncodingDetector.file_seems_to_be_utf16?(file)
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
def file_valid?(filepath)
|
114
114
|
extension = filepath.split('.').last
|
115
115
|
allowed_file_extensions.include?(extension)
|
@@ -118,15 +118,15 @@ private
|
|
118
118
|
def file_exists?(file)
|
119
119
|
File.exist?(file)
|
120
120
|
end
|
121
|
-
|
121
|
+
|
122
122
|
def valid_tags_are_given?(tags)
|
123
123
|
tags.all? { |tag| Phrase::Tool::TagValidator.valid?(tag) }
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
def rails_default_locale_folder_available?
|
127
127
|
File.exist?(RAILS_DEFAULT_FOLDER) && File.directory?(RAILS_DEFAULT_FOLDER)
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
130
|
def detect_locale_name_from_file_path(file_path)
|
131
131
|
Phrase::Formats.detect_locale_name_from_file_path(file_path)
|
132
132
|
end
|
@@ -4,27 +4,23 @@ class Phrase::Tool::Commands::ShowHelp < 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_help
|
10
10
|
end
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def show_help
|
15
|
-
print_message <<USAGE
|
16
|
-
usage: phrase <command> [<args>]
|
17
|
-
|
18
|
-
phrase init --secret=<YOUR SECRET> --default-locale=<DEFAULT LOCALE, e.g. en> --default-format=<FORMAT, e.g. yml> --default-target=<TARGET, default is ./phrase/locales/>
|
19
11
|
|
20
|
-
|
21
|
-
phrase push DIRECTORY [--tags=<tags>] [--locale=<locale>]
|
12
|
+
private
|
22
13
|
|
23
|
-
|
14
|
+
def show_help
|
15
|
+
msg = "usage: phrase <command> [<args>]\n"
|
16
|
+
Phrase::Tool::Commands.possible_commands.each do |command, suffix|
|
17
|
+
msg << " #{extract_help(command)}\n"
|
18
|
+
end
|
24
19
|
|
25
|
-
|
20
|
+
print_message msg
|
21
|
+
end
|
26
22
|
|
27
|
-
|
28
|
-
|
23
|
+
def extract_help(command)
|
24
|
+
OptionsFactory.options_for(command, {}).help
|
29
25
|
end
|
30
26
|
end
|
data/lib/phrase/tool/options.rb
CHANGED
@@ -5,37 +5,7 @@ require File.expand_path('../options_factory', __FILE__)
|
|
5
5
|
class Phrase::Tool::Options
|
6
6
|
def initialize(args, command="")
|
7
7
|
@command = command
|
8
|
-
|
9
|
-
@data = {
|
10
|
-
default: {
|
11
|
-
version: false,
|
12
|
-
help: false
|
13
|
-
},
|
14
|
-
init: {
|
15
|
-
secret: "",
|
16
|
-
default_locale: "en",
|
17
|
-
domain: "phrase",
|
18
|
-
format: nil,
|
19
|
-
locale_filename: nil,
|
20
|
-
locale_directory: nil,
|
21
|
-
target_directory: nil
|
22
|
-
},
|
23
|
-
push: {
|
24
|
-
tags: [],
|
25
|
-
recursive: false,
|
26
|
-
locale: nil,
|
27
|
-
format: nil,
|
28
|
-
update_translations: false
|
29
|
-
},
|
30
|
-
pull: {
|
31
|
-
format: nil,
|
32
|
-
target: nil,
|
33
|
-
tag: nil
|
34
|
-
},
|
35
|
-
tags: {
|
36
|
-
list: true
|
37
|
-
}
|
38
|
-
}
|
8
|
+
@data = Phrase::Tool::Commands.possible_commands_with_options
|
39
9
|
options.parse!(args)
|
40
10
|
end
|
41
11
|
|
@@ -8,6 +8,8 @@ class OptionsFactory
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.init(opts, set)
|
11
|
+
opts.banner = "phrase init"
|
12
|
+
|
11
13
|
opts.on("--secret=YOUR_AUTH_TOKEN", String, "Your auth token") do |secret|
|
12
14
|
set[:secret] = secret
|
13
15
|
end
|
@@ -39,6 +41,8 @@ class OptionsFactory
|
|
39
41
|
private_class_method :init
|
40
42
|
|
41
43
|
def self.push(opts, set)
|
44
|
+
opts.banner = "phrase push FILE|DIRECTORY"
|
45
|
+
|
42
46
|
opts.on("--tags=foo,bar", Array, "List of tags for phrase push (separated by comma)") do |tags|
|
43
47
|
set[:tags] = tags
|
44
48
|
end
|
@@ -62,6 +66,8 @@ class OptionsFactory
|
|
62
66
|
private_class_method :push
|
63
67
|
|
64
68
|
def self.pull(opts, set)
|
69
|
+
opts.banner = "phrase pull [LOCALE]"
|
70
|
+
|
65
71
|
opts.on("--format=yml", String, "See documentation for list of allowed formats") do |format|
|
66
72
|
set[:format] = format
|
67
73
|
end
|
@@ -77,6 +83,8 @@ class OptionsFactory
|
|
77
83
|
private_class_method :pull
|
78
84
|
|
79
85
|
def self.tags(opts, set)
|
86
|
+
opts.banner = "phrase tags"
|
87
|
+
|
80
88
|
opts.on("-l", "--list", "List all tags") do |list|
|
81
89
|
set[:list] = list
|
82
90
|
end
|
@@ -84,6 +92,8 @@ class OptionsFactory
|
|
84
92
|
private_class_method :tags
|
85
93
|
|
86
94
|
def self.default(opts, set)
|
95
|
+
opts.banner = ""
|
96
|
+
|
87
97
|
opts.on_tail("-v", "--version", "Show version number") do |version|
|
88
98
|
set[:version] = true
|
89
99
|
end
|
data/lib/phrase/version.rb
CHANGED
data/phrase.gemspec
CHANGED
@@ -22,9 +22,9 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.require_paths = ["lib"]
|
23
23
|
s.add_dependency('colorize')
|
24
24
|
s.add_dependency('json')
|
25
|
+
s.add_dependency('i18n')
|
25
26
|
s.add_development_dependency('rake')
|
26
27
|
s.add_development_dependency('rspec')
|
27
|
-
s.add_development_dependency('i18n')
|
28
28
|
s.add_development_dependency('webmock')
|
29
29
|
s.add_development_dependency('vcr')
|
30
30
|
s.add_development_dependency('timecop')
|
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.4.
|
4
|
+
version: 0.4.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: colorize
|
16
|
-
requirement: &
|
16
|
+
requirement: &70209041741460 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70209041741460
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: json
|
27
|
-
requirement: &
|
27
|
+
requirement: &70209041741000 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,21 +32,21 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70209041741000
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
38
|
-
requirement: &
|
37
|
+
name: i18n
|
38
|
+
requirement: &70209041740540 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: '0'
|
44
|
-
type: :
|
44
|
+
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70209041740540
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
49
|
-
requirement: &
|
48
|
+
name: rake
|
49
|
+
requirement: &70209041740100 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70209041740100
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
|
-
name:
|
60
|
-
requirement: &
|
59
|
+
name: rspec
|
60
|
+
requirement: &70209041739580 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70209041739580
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: webmock
|
71
|
-
requirement: &
|
71
|
+
requirement: &70209041739080 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70209041739080
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: vcr
|
82
|
-
requirement: &
|
82
|
+
requirement: &70209041738420 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70209041738420
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: timecop
|
93
|
-
requirement: &
|
93
|
+
requirement: &70209041737620 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70209041737620
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: genspec
|
104
|
-
requirement: &
|
104
|
+
requirement: &70209041737200 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70209041737200
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: rails
|
115
|
-
requirement: &
|
115
|
+
requirement: &70209041736740 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,7 +120,7 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70209041736740
|
124
124
|
description: phrase allows you to edit translations in-place on the page itself. More
|
125
125
|
information at phraseapp.com
|
126
126
|
email:
|