interpres 0.0.1
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +19 -0
- data/bin/interpull +7 -0
- data/bin/interpush +11 -0
- data/lib/interpres.rb +13 -0
- data/lib/interpres/api.rb +45 -0
- data/lib/interpres/cache.rb +29 -0
- data/lib/interpres/extractor.rb +26 -0
- data/lib/interpres/parser/jinja2.rb +65 -0
- data/lib/interpres/pull.rb +10 -0
- data/lib/interpres/push.rb +18 -0
- data/lib/interpres/version.rb +5 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ae2e3ffcedbdbd0809cb7972c8b8b30294314cf2
|
4
|
+
data.tar.gz: 60dc3a5db8d1b9a08a888825460bf17f621d8f9d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ed240aab3c7a50670c425025caa424242c6ceba07da9ab6577b71ecd56ed4cefa4022ea53fa6e8e8b07d43bc1b80286b5d31a2ab7a116b26388b8d9020986ee6
|
7
|
+
data.tar.gz: 07ed6b70b7789dda101b5241ee95885876b4931dbc70b63e7d597e07d844d8d0e46f648d6aca49bb6dcc571437f9daaa5f564316152c06f2c74936dc2d7c4e0f
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 Daniel Cruz Horts
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
desc 'Gem debugging'
|
2
|
+
task :console do
|
3
|
+
sh 'pry -I lib -r interpres'
|
4
|
+
end
|
5
|
+
|
6
|
+
namespace :interpres do
|
7
|
+
|
8
|
+
desc 'Download translation files'
|
9
|
+
task :download, :path do |t, args|
|
10
|
+
require 'interpres'
|
11
|
+
Interpres::Pull.run(args['path'])
|
12
|
+
end
|
13
|
+
|
14
|
+
desc 'Upload translation texts'
|
15
|
+
task :upload, :path, :inclusion, :exclusion do |t, args|
|
16
|
+
require 'interpres'
|
17
|
+
Interpres::Push.run(args['path'], args['inclusion'], args['exclusion'])
|
18
|
+
end
|
19
|
+
end
|
data/bin/interpull
ADDED
data/bin/interpush
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Usage:
|
3
|
+
# interpush /path/to/find/translations [files_to_include [files_to_exclude]]
|
4
|
+
# - files_to_include is optional, and by default {app,lib}/**/*.{rb,erb,haml}
|
5
|
+
# - files_to_exclude is optional, and by default nil
|
6
|
+
|
7
|
+
require 'interpres'
|
8
|
+
|
9
|
+
args = [ARGV[0], ARGV[1], ARGV[2]]
|
10
|
+
|
11
|
+
Interpres::Push.run(*args.compact)
|
data/lib/interpres.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Gem dependencies
|
2
|
+
require 'faraday'
|
3
|
+
require 'oj'
|
4
|
+
require 'gettext/tools/rgettext'
|
5
|
+
|
6
|
+
# Gem code
|
7
|
+
require 'interpres/parser/jinja2'
|
8
|
+
require 'interpres/api'
|
9
|
+
require 'interpres/cache'
|
10
|
+
require 'interpres/extractor'
|
11
|
+
require 'interpres/pull'
|
12
|
+
require 'interpres/push'
|
13
|
+
require 'interpres/version'
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Interpres
|
2
|
+
class Api
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@token = ENV['INTERPRES_TOKEN'] or raise "Can't continue without a token"
|
6
|
+
end
|
7
|
+
|
8
|
+
def upload(texts)
|
9
|
+
texts.each do |literal|
|
10
|
+
connection.post '/texts', {text: {literal: literal}, app_token: @token}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def download(language, path)
|
15
|
+
Dir.mkdir(path) unless File.directory? path
|
16
|
+
f = File.open "#{path}/#{language}.po", 'w'
|
17
|
+
f.write get('/texts.po', {iso: language})
|
18
|
+
f.close
|
19
|
+
end
|
20
|
+
|
21
|
+
def enabled_languages
|
22
|
+
Oj.load get('/apps/enabled_languages')
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def connection
|
28
|
+
return @connection if @connection
|
29
|
+
|
30
|
+
@connection = Faraday.new(url: ENV['INTERPRES_URL'])
|
31
|
+
if ENV['INTERPRES_USER'] && !ENV['INTERPRES_USER'].empty?
|
32
|
+
@connection.basic_auth(ENV['INTERPRES_USER'], ENV['INTERPRES_PASSWORD'])
|
33
|
+
end
|
34
|
+
@connection
|
35
|
+
end
|
36
|
+
|
37
|
+
def get(url, resource = {})
|
38
|
+
request = connection.get url, {app_token: @token}.merge(resource)
|
39
|
+
|
40
|
+
raise 'Problem requesting #{url}: check env vars' if request.status != 200
|
41
|
+
|
42
|
+
request.body
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Interpres
|
2
|
+
class Cache
|
3
|
+
|
4
|
+
CACHE = '.interpres_cache.json'
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
mode = File.file?(CACHE) ? 'r' : 'w+'
|
8
|
+
file = File.open(CACHE, mode)
|
9
|
+
@cached_texts = Oj.load(file.read) || []
|
10
|
+
file.close
|
11
|
+
end
|
12
|
+
|
13
|
+
def read
|
14
|
+
@cached_texts
|
15
|
+
end
|
16
|
+
|
17
|
+
def write(texts)
|
18
|
+
file = File.open(CACHE, 'w')
|
19
|
+
file.write(Oj.dump texts)
|
20
|
+
file.close
|
21
|
+
@cached_texts = texts
|
22
|
+
end
|
23
|
+
|
24
|
+
def diff(texts)
|
25
|
+
texts - @cached_texts
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
GetText::RGetText.add_parser GetText::Jinja2Parser
|
2
|
+
|
3
|
+
module Interpres
|
4
|
+
class Extractor
|
5
|
+
|
6
|
+
def initialize(inclusion, exclusion = nil)
|
7
|
+
@inclusion = inclusion
|
8
|
+
@exclusion = exclusion
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
GetText::RGetText.parse(file_list).map(&:msgid).sort
|
13
|
+
end
|
14
|
+
|
15
|
+
def file_list
|
16
|
+
return base_file_list unless @exclusion
|
17
|
+
|
18
|
+
base_file_list.reject { |filename| filename =~ @exclusion }
|
19
|
+
end
|
20
|
+
|
21
|
+
def base_file_list
|
22
|
+
Dir.glob(@inclusion)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
=begin
|
4
|
+
parser/jinja2.rb - parser for Jinja2 templates
|
5
|
+
Based upon gettext-2.2.1/lib/gettext/tools/parser/glade.rb by Masao Mutoh
|
6
|
+
|
7
|
+
Copyright (C) 2014 Daniel Cruz Horts
|
8
|
+
|
9
|
+
You may redistribute under MIT license terms.
|
10
|
+
=end
|
11
|
+
|
12
|
+
module GetText
|
13
|
+
module Jinja2Parser
|
14
|
+
extend GetText
|
15
|
+
extend self
|
16
|
+
|
17
|
+
bindtextdomain('rgettext')
|
18
|
+
|
19
|
+
def parse(file, targets = []) # :nodoc:
|
20
|
+
lines = IO.readlines(file)
|
21
|
+
parse_lines(file, lines, targets)
|
22
|
+
end
|
23
|
+
|
24
|
+
#from ary of lines.
|
25
|
+
def parse_lines(file, lines, targets) # :nodoc:
|
26
|
+
line_no = 0
|
27
|
+
|
28
|
+
loop do
|
29
|
+
line = lines.shift
|
30
|
+
break unless line
|
31
|
+
|
32
|
+
line_no += 1
|
33
|
+
if matches = line.scan(/{% trans %}(.*?){% endtrans %}/)
|
34
|
+
matches.each do |match|
|
35
|
+
add_target(match.first, file, line_no, targets)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
targets
|
40
|
+
end
|
41
|
+
|
42
|
+
def target?(file) # :nodoc:
|
43
|
+
true
|
44
|
+
end
|
45
|
+
|
46
|
+
def add_target(val, file, line_no, targets) # :nodoc:
|
47
|
+
return unless val.size > 0
|
48
|
+
assoc_data = targets.assoc(val)
|
49
|
+
val = CGI.unescapeHTML(val)
|
50
|
+
if assoc_data
|
51
|
+
targets[targets.index(assoc_data)] = assoc_data << "#{file}:#{line_no}"
|
52
|
+
else
|
53
|
+
targets << [val, "#{file}:#{line_no}"]
|
54
|
+
end
|
55
|
+
targets
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
if __FILE__ == $0
|
61
|
+
# ex) ruby jinja2.rb file1.html file2.html
|
62
|
+
ARGV.each do |file|
|
63
|
+
p GetText::Jinja2Parser.parse(file)
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Interpres
|
2
|
+
class Push
|
3
|
+
def self.run(path, inclusion = '{app,lib}/**/*.{rb,erb,haml}', exclusion = nil)
|
4
|
+
inclusion = File.join(path, inclusion)
|
5
|
+
exclusion = exclusion ? File.join(path, exclusion) : nil
|
6
|
+
|
7
|
+
cache = Interpres::Cache.new
|
8
|
+
|
9
|
+
texts = Interpres::Extractor.new(inclusion, exclusion).run
|
10
|
+
|
11
|
+
Interpres::Api.new.upload cache.diff(texts)
|
12
|
+
|
13
|
+
puts "#{cache.diff(texts).count} new text strings"
|
14
|
+
|
15
|
+
cache.write(texts)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: interpres
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Cruz Horts
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: oj
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.10'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.9'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: gettext
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.3'
|
83
|
+
description: CLI interface to the Interpres server
|
84
|
+
email:
|
85
|
+
executables:
|
86
|
+
- interpull
|
87
|
+
- interpush
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- MIT-LICENSE
|
92
|
+
- Rakefile
|
93
|
+
- bin/interpull
|
94
|
+
- bin/interpush
|
95
|
+
- lib/interpres.rb
|
96
|
+
- lib/interpres/api.rb
|
97
|
+
- lib/interpres/cache.rb
|
98
|
+
- lib/interpres/extractor.rb
|
99
|
+
- lib/interpres/parser/jinja2.rb
|
100
|
+
- lib/interpres/pull.rb
|
101
|
+
- lib/interpres/push.rb
|
102
|
+
- lib/interpres/version.rb
|
103
|
+
homepage: https://github.com/dncrht/interpres-cli
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.2.2
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Push/pull translations from the command line
|
127
|
+
test_files: []
|
128
|
+
has_rdoc:
|