lingohub 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/lingohub/commands/help.rb +3 -13
- data/lib/lingohub/commands/project.rb +1 -25
- data/lib/lingohub/commands/resource.rb +3 -11
- data/lib/lingohub/models/project.rb +5 -52
- data/lib/lingohub/models/projects.rb +0 -4
- data/lib/lingohub/version.rb +1 -1
- metadata +2 -117
- data/lib/lingohub/commands/collaborator.rb +0 -44
- data/lib/lingohub/models/collaborator.rb +0 -25
- data/lib/patches/rails3/i18n/i18n.rb +0 -66
@@ -44,17 +44,7 @@ module Lingohub::Command
|
|
44
44
|
|
45
45
|
group 'Project Commands' do |group|
|
46
46
|
group.command 'project:list', 'list your projects'
|
47
|
-
group.command 'project:create <name>', 'create a new project'
|
48
|
-
group.command 'project:info --project <name>', 'show project info, like web url and number of translations'
|
49
47
|
group.command 'project:open --project <name>', 'open the project in a web browser'
|
50
|
-
group.command 'project:rename <oldname> <newname>', 'rename the project'
|
51
|
-
group.space
|
52
|
-
end
|
53
|
-
|
54
|
-
group 'Collaborator Commands' do |group|
|
55
|
-
group.command 'collaborator:list --project <name>', 'list project collaborators'
|
56
|
-
group.command 'collaborator:invite <email> --project <name>', 'invite the collaborator'
|
57
|
-
group.command 'collaborator:remove <email> --project <name>', 'remove the collaborator'
|
58
48
|
group.space
|
59
49
|
end
|
60
50
|
|
@@ -62,13 +52,13 @@ module Lingohub::Command
|
|
62
52
|
group.command 'resource:down --all --directory <path> --project <name>', 'download all resource files'
|
63
53
|
group.command 'resource:down --locale <iso2_code> --all --directory <path> --project <name>', 'download all resource files, using the given locale as filter'
|
64
54
|
group.command 'resource:down <file1> <file2> ... --directory <path> --project <name>', 'download specific resource files'
|
65
|
-
|
55
|
+
|
66
56
|
up_command = 'resource:up <file1> <file2> ... --locale <iso2_code> --project <name>'
|
67
|
-
|
57
|
+
|
68
58
|
strategy_desc = ""
|
69
59
|
Lingohub::Command::Resource::EXPECTED_STRATEGY_PARAMETERS.each do |parameter|
|
70
60
|
strategy_desc << " --#{parameter} true|false"
|
71
|
-
end
|
61
|
+
end
|
72
62
|
|
73
63
|
group.command "resource:up <file1> <file2> ... --locale <iso2_code> --project <name> [#{strategy_desc}]", "upload specific resource files, a locale may be specified to tell lingohub the locale of file content"
|
74
64
|
group.space
|
@@ -17,37 +17,13 @@ module Lingohub::Command
|
|
17
17
|
if list.size > 0
|
18
18
|
display "Projects:\n"
|
19
19
|
list.each_pair { |name, project|
|
20
|
-
|
21
|
-
display "- #{name} #{inactive_str}"
|
20
|
+
display "- #{name}"
|
22
21
|
}
|
23
22
|
else
|
24
23
|
display "You have no projects."
|
25
24
|
end
|
26
25
|
end
|
27
26
|
|
28
|
-
def create
|
29
|
-
title = args.shift.strip rescue nil
|
30
|
-
lingohub.projects.create title
|
31
|
-
display("Created #{title}")
|
32
|
-
end
|
33
|
-
|
34
|
-
def rename
|
35
|
-
oldtitle = args[0].strip rescue raise(CommandFailed, "Invalid old project name")
|
36
|
-
newtitle = args[1].strip rescue raise(CommandFailed, "Invalid new project name")
|
37
|
-
|
38
|
-
project(oldtitle).update(:title => newtitle)
|
39
|
-
display("Project renamed from #{oldtitle} to #{newtitle}")
|
40
|
-
end
|
41
|
-
|
42
|
-
def info
|
43
|
-
display "=== #{project.title}"
|
44
|
-
display "Web URL: #{project.weburl}"
|
45
|
-
display "Owner: #{project.owner}"
|
46
|
-
display "Opensource: #{project.opensource}"
|
47
|
-
display "Locales: #{project.project_locales}"
|
48
|
-
display "Description: #{project.description}"
|
49
|
-
end
|
50
|
-
|
51
27
|
def open
|
52
28
|
Launchy.open project.weburl
|
53
29
|
end
|
@@ -30,14 +30,6 @@ module Lingohub::Command
|
|
30
30
|
|
31
31
|
private
|
32
32
|
|
33
|
-
def rails_environment?
|
34
|
-
true #TODO
|
35
|
-
end
|
36
|
-
|
37
|
-
def rails_locale_dir
|
38
|
-
Dir.pwd + "/conf/locales"
|
39
|
-
end
|
40
|
-
|
41
33
|
def extract_directory_from_args
|
42
34
|
return @directory if defined? @directory
|
43
35
|
@directory = extract_option('--directory', false)
|
@@ -53,15 +45,15 @@ module Lingohub::Command
|
|
53
45
|
end
|
54
46
|
|
55
47
|
def extract_strategy_parameters
|
56
|
-
result = {}
|
57
|
-
|
48
|
+
result = {}
|
49
|
+
|
58
50
|
EXPECTED_STRATEGY_PARAMETERS.each do |parameter|
|
59
51
|
value = extract_option("--#{parameter}", nil)
|
60
52
|
if value
|
61
53
|
bool_value = to_bool(value, parameter)
|
62
54
|
result.merge!({ parameter => value })
|
63
55
|
end
|
64
|
-
end
|
56
|
+
end
|
65
57
|
result
|
66
58
|
end
|
67
59
|
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Lingohub
|
2
2
|
module Models
|
3
3
|
require 'lingohub/models/resource'
|
4
|
-
require 'lingohub/models/collaborator'
|
5
4
|
|
6
5
|
class Project
|
7
6
|
def self.lazy_attr_accessor(*params)
|
@@ -18,39 +17,14 @@ module Lingohub
|
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
:translations_url, :search_url, :activate_url, :owner, :description, :opensource, :project_locales)
|
20
|
+
lazy_attr_accessor(:title, :link, :weburl, :resources_url,
|
21
|
+
:translations_url, :search_url, :owner, :description, :project_locales)
|
24
22
|
|
25
23
|
def initialize(client, link)
|
26
24
|
@client = client
|
27
25
|
@link = link
|
28
26
|
end
|
29
27
|
|
30
|
-
def create!(attributes={ })
|
31
|
-
self.title = attributes[:title]
|
32
|
-
end
|
33
|
-
|
34
|
-
def destroy
|
35
|
-
@client.delete self.link
|
36
|
-
end
|
37
|
-
|
38
|
-
def activate
|
39
|
-
@client.put self.activate_url, {}
|
40
|
-
end
|
41
|
-
|
42
|
-
def update(attributes={ })
|
43
|
-
@client.put self.link, { :project => attributes }
|
44
|
-
end
|
45
|
-
|
46
|
-
def invite_collaborator(email)
|
47
|
-
@client.post(self.invitations_url, :invitation => { :email => email })
|
48
|
-
end
|
49
|
-
|
50
|
-
def inactive?
|
51
|
-
!deactivated_at.nil?
|
52
|
-
end
|
53
|
-
|
54
28
|
def resources
|
55
29
|
unless defined? @resources
|
56
30
|
@resources = { }
|
@@ -64,24 +38,6 @@ module Lingohub
|
|
64
38
|
@resources
|
65
39
|
end
|
66
40
|
|
67
|
-
def collaborators
|
68
|
-
unless defined? @collaborators
|
69
|
-
@collaborators = []
|
70
|
-
response = @client.get(self.collaborators_url)
|
71
|
-
resource_hash = JSON.parse(response)
|
72
|
-
members = resource_hash["members"]
|
73
|
-
members.each do |member|
|
74
|
-
link = member["link"]["href"] rescue ""
|
75
|
-
collaborator = Lingohub::Models::Collaborator.new(@client, link)
|
76
|
-
collaborator.email = member["email"]
|
77
|
-
collaborator.display_name = member["display_name"]
|
78
|
-
collaborator.roles = member["roles"]
|
79
|
-
@collaborators << collaborator
|
80
|
-
end
|
81
|
-
end
|
82
|
-
@collaborators
|
83
|
-
end
|
84
|
-
|
85
41
|
def download_resource(directory, filename, locale_as_filter = nil)
|
86
42
|
raise "Project does not contain that file." unless self.resources.has_key?(filename)
|
87
43
|
resource = self.resources[filename]
|
@@ -121,16 +77,13 @@ module Lingohub
|
|
121
77
|
weburl = links[1]["href"]
|
122
78
|
translations_url = links[2]["href"]
|
123
79
|
resources_url = links[3]["href"]
|
124
|
-
|
125
|
-
invitations_url = links[5]["href"]
|
126
|
-
search_url = links[6]["href"]
|
80
|
+
search_url = links[4]["href"]
|
127
81
|
|
128
82
|
init_attributes :title => project_hash["title"], :link => link,
|
129
|
-
:
|
83
|
+
:weburl => weburl,
|
130
84
|
:owner => project_hash["owner_email"], :description => project_hash["description"],
|
131
|
-
:
|
85
|
+
:project_locales => project_hash["project_locales"],
|
132
86
|
:translations_url => translations_url, :resources_url => resources_url,
|
133
|
-
:collaborators_url => collaborators_url, :invitations_url => invitations_url,
|
134
87
|
:search_url => search_url
|
135
88
|
end
|
136
89
|
|
data/lib/lingohub/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lingohub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-02-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -59,118 +59,6 @@ dependencies:
|
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 1.3.2
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: rake
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ~>
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: 0.9.2
|
70
|
-
type: :development
|
71
|
-
prerelease: false
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ~>
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: 0.9.2
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
name: rspec
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
|
-
requirements:
|
83
|
-
- - ~>
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: 2.8.0
|
86
|
-
type: :development
|
87
|
-
prerelease: false
|
88
|
-
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ~>
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: 2.8.0
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
|
-
name: fakefs
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
|
-
requirements:
|
99
|
-
- - ~>
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: 0.4.0
|
102
|
-
type: :development
|
103
|
-
prerelease: false
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
|
-
requirements:
|
107
|
-
- - ~>
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: 0.4.0
|
110
|
-
- !ruby/object:Gem::Dependency
|
111
|
-
name: taps
|
112
|
-
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
|
-
requirements:
|
115
|
-
- - ~>
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: 0.3.23
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
|
-
requirements:
|
123
|
-
- - ~>
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
version: 0.3.23
|
126
|
-
- !ruby/object:Gem::Dependency
|
127
|
-
name: webmock
|
128
|
-
requirement: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
|
-
requirements:
|
131
|
-
- - ~>
|
132
|
-
- !ruby/object:Gem::Version
|
133
|
-
version: 1.8.0
|
134
|
-
type: :development
|
135
|
-
prerelease: false
|
136
|
-
version_requirements: !ruby/object:Gem::Requirement
|
137
|
-
none: false
|
138
|
-
requirements:
|
139
|
-
- - ~>
|
140
|
-
- !ruby/object:Gem::Version
|
141
|
-
version: 1.8.0
|
142
|
-
- !ruby/object:Gem::Dependency
|
143
|
-
name: i18n
|
144
|
-
requirement: !ruby/object:Gem::Requirement
|
145
|
-
none: false
|
146
|
-
requirements:
|
147
|
-
- - ~>
|
148
|
-
- !ruby/object:Gem::Version
|
149
|
-
version: 0.6.0
|
150
|
-
type: :development
|
151
|
-
prerelease: false
|
152
|
-
version_requirements: !ruby/object:Gem::Requirement
|
153
|
-
none: false
|
154
|
-
requirements:
|
155
|
-
- - ~>
|
156
|
-
- !ruby/object:Gem::Version
|
157
|
-
version: 0.6.0
|
158
|
-
- !ruby/object:Gem::Dependency
|
159
|
-
name: vcr
|
160
|
-
requirement: !ruby/object:Gem::Requirement
|
161
|
-
none: false
|
162
|
-
requirements:
|
163
|
-
- - ~>
|
164
|
-
- !ruby/object:Gem::Version
|
165
|
-
version: 2.0.0
|
166
|
-
type: :development
|
167
|
-
prerelease: false
|
168
|
-
version_requirements: !ruby/object:Gem::Requirement
|
169
|
-
none: false
|
170
|
-
requirements:
|
171
|
-
- - ~>
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: 2.0.0
|
174
62
|
description: Client library and command-line tool to translate Ruby based apps with
|
175
63
|
lingohub.
|
176
64
|
email:
|
@@ -184,13 +72,11 @@ files:
|
|
184
72
|
- lib/lingohub/command.rb
|
185
73
|
- lib/lingohub/commands/auth.rb
|
186
74
|
- lib/lingohub/commands/base.rb
|
187
|
-
- lib/lingohub/commands/collaborator.rb
|
188
75
|
- lib/lingohub/commands/help.rb
|
189
76
|
- lib/lingohub/commands/project.rb
|
190
77
|
- lib/lingohub/commands/resource.rb
|
191
78
|
- lib/lingohub/commands/version.rb
|
192
79
|
- lib/lingohub/helpers.rb
|
193
|
-
- lib/lingohub/models/collaborator.rb
|
194
80
|
- lib/lingohub/models/project.rb
|
195
81
|
- lib/lingohub/models/projects.rb
|
196
82
|
- lib/lingohub/models/resource.rb
|
@@ -198,7 +84,6 @@ files:
|
|
198
84
|
- lib/lingohub/rails3/railtie.rb
|
199
85
|
- lib/lingohub/version.rb
|
200
86
|
- lib/lingohub.rb
|
201
|
-
- lib/patches/rails3/i18n/i18n.rb
|
202
87
|
- lib/vendor/okjson.rb
|
203
88
|
- bin/lingohub
|
204
89
|
- LICENSE
|
@@ -1,44 +0,0 @@
|
|
1
|
-
module Lingohub::Command
|
2
|
-
class Collaborator < Base
|
3
|
-
def list
|
4
|
-
list = project.collaborators
|
5
|
-
if list.size > 0
|
6
|
-
display "Collaborators:\n"
|
7
|
-
list.each { |c| display("- #{c.display_name} | #{c.email} | #{c.permissions}") }
|
8
|
-
else
|
9
|
-
display "No collaborators found"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def invite
|
14
|
-
email = extract_email_from_args
|
15
|
-
project.invite_collaborator(email)
|
16
|
-
|
17
|
-
display("Invitation sent to #{email}")
|
18
|
-
rescue RestClient::BadRequest
|
19
|
-
display("Error sending invitation to '#{email}'")
|
20
|
-
end
|
21
|
-
|
22
|
-
def remove
|
23
|
-
email = extract_email_from_args
|
24
|
-
collaborator = project.collaborators.find { |c| c.email == email }
|
25
|
-
|
26
|
-
if collaborator.nil?
|
27
|
-
display("Collaborator with email '#{email}' not found")
|
28
|
-
else
|
29
|
-
collaborator.destroy
|
30
|
-
display("Collaborator with email #{email} was removed")
|
31
|
-
end
|
32
|
-
rescue RestClient::BadRequest
|
33
|
-
display("Error removing collaborator with email '#{email}'")
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def extract_email_from_args
|
39
|
-
email = args.shift
|
40
|
-
raise(CommandFailed, "You must specify a invitee email after --email") if email == false
|
41
|
-
email
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module Lingohub
|
2
|
-
module Models
|
3
|
-
class Collaborator
|
4
|
-
attr_accessor :email, :display_name, :roles
|
5
|
-
|
6
|
-
ROLES_NAMES = { "project_admin" => "Project admin", "developer" => "Developer" }
|
7
|
-
|
8
|
-
def initialize(client, link)
|
9
|
-
@client = client
|
10
|
-
@link = link
|
11
|
-
end
|
12
|
-
|
13
|
-
def destroy
|
14
|
-
@client.delete @link
|
15
|
-
end
|
16
|
-
|
17
|
-
def permissions
|
18
|
-
return "None" if self.roles.nil? or self.roles.empty?
|
19
|
-
|
20
|
-
self.roles.find_all { |role| ROLES_NAMES.has_key?(role) }.join(", ")
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
require "stringex"
|
3
|
-
|
4
|
-
module I18n
|
5
|
-
class << self
|
6
|
-
alias :base_translate :translate
|
7
|
-
alias :base_localize :localize
|
8
|
-
|
9
|
-
def translate(key, options={ })
|
10
|
-
result = base_translate(key, options)
|
11
|
-
wysiwyt_enabled = options.has_key?(:wysiwyt) ? options.delete(:wysiwyt) : true
|
12
|
-
if wysiwyt_enabled && enabled?
|
13
|
-
result = wrap_with_wysiwyt(key, result)
|
14
|
-
result.html_safe
|
15
|
-
else
|
16
|
-
result
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def localize(object, options = { })
|
21
|
-
result = base_localize(object, options)
|
22
|
-
wysiwyt_enabled = options.has_key?(:wysiwyt) ? options.delete(:wysiwyt) : true
|
23
|
-
if wysiwyt_enabled && enabled?
|
24
|
-
result = wrap_with_wysiwyt(object, result)
|
25
|
-
result.html_safe
|
26
|
-
else
|
27
|
-
result
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
alias :t :translate
|
32
|
-
alias :l :localize
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def enabled?
|
37
|
-
Lingohub.environments.include?(current_env) rescue false
|
38
|
-
end
|
39
|
-
|
40
|
-
def current_env
|
41
|
-
defined?(Rails) ? Rails.env.to_sym : nil
|
42
|
-
end
|
43
|
-
|
44
|
-
def wrap_with_wysiwyt(translation_title, translation_phrase)
|
45
|
-
"<span data-translation_url=\"#{link_to_translation_phrase(translation_title)}\" >#{translation_phrase}</span>"
|
46
|
-
end
|
47
|
-
|
48
|
-
def link_to_translation_phrase(translation_title)
|
49
|
-
username = option_to_url(Lingohub.username)
|
50
|
-
project = option_to_url(Lingohub.project)
|
51
|
-
translation_title = translation_title.to_s.to_url
|
52
|
-
|
53
|
-
"#{Lingohub.protocol}://#{Lingohub.host}/#{username}/#{project}/translations/#{translation_title}/phrases/#{locale}"
|
54
|
-
end
|
55
|
-
|
56
|
-
def option_to_url(option)
|
57
|
-
if option.nil?
|
58
|
-
""
|
59
|
-
elsif Lingohub.default_value?(option)
|
60
|
-
option
|
61
|
-
else
|
62
|
-
option.to_url
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|