locca 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/locca +12 -0
- data/lib/locca.rb +15 -0
- data/lib/locca/actions/translate_action.rb +77 -0
- data/lib/locca/project.rb +9 -0
- data/lib/locca/sync/onesky.rb +0 -1
- data/lib/locca/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59c4dfcb6f714c36e0e945658fde5705de3bb971
|
4
|
+
data.tar.gz: ac9cdc3cf716780c68acabaa7a22fec331722501
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dab801c6e1d3e582ce3285bbfffa1afcb8f5ca111f48a07dfe0d828115b995589a747ee9b87b5445afdc843bec8c145fea9c1057298deabbddbba8a11f66e58
|
7
|
+
data.tar.gz: aaa95ea21cbf1c66ae5eec112753c27566d04a3bc19f0d69f8b17d93dd7485e468fe0b1249d3c0ba07c48b1b9dd79b71f092859de031d88a1d82eb9efdda4997
|
data/bin/locca
CHANGED
@@ -72,6 +72,18 @@ command :sync do |c|
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
desc 'Translate the untranslated'
|
76
|
+
command :translate do |c|
|
77
|
+
c.action do |global_options, options, args|
|
78
|
+
work_dir = global_options['work-dir'.to_sym]
|
79
|
+
if not work_dir
|
80
|
+
work_dir = Dir.getwd
|
81
|
+
end
|
82
|
+
|
83
|
+
$locca.translate(project_in_dir(work_dir), args[0])
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
75
87
|
pre do |global, command, options, args|
|
76
88
|
$locca = Locca::Locca.new()
|
77
89
|
true
|
data/lib/locca.rb
CHANGED
@@ -34,6 +34,7 @@ require 'locca/config_validator'
|
|
34
34
|
require 'locca/actions/build_action'
|
35
35
|
require 'locca/actions/merge_action'
|
36
36
|
require 'locca/actions/sync_action'
|
37
|
+
require 'locca/actions/translate_action'
|
37
38
|
|
38
39
|
require 'locca/sync/onesky'
|
39
40
|
|
@@ -84,6 +85,20 @@ module Locca
|
|
84
85
|
action.execute()
|
85
86
|
end
|
86
87
|
|
88
|
+
def translate(project, lang = nil)
|
89
|
+
if not project
|
90
|
+
raise 'Can\'t initialize Locca with nil project'
|
91
|
+
end
|
92
|
+
|
93
|
+
if not lang
|
94
|
+
lang = project.base_lang
|
95
|
+
end
|
96
|
+
|
97
|
+
collection_builder = collection_builder()
|
98
|
+
action = TranslateAction.new(project, lang, collection_builder, collection_writer(), collection_merger())
|
99
|
+
action.execute()
|
100
|
+
end
|
101
|
+
|
87
102
|
def collection_builder()
|
88
103
|
parser = Babelyoda::StringsParser.new(Babelyoda::StringsLexer.new())
|
89
104
|
return CollectionBuilder.new(File, parser)
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#
|
2
|
+
# The MIT License (MIT)
|
3
|
+
#
|
4
|
+
# Copyright (c) 2014 Evgeny Shurakov
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in all
|
14
|
+
# copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
# SOFTWARE.
|
23
|
+
#
|
24
|
+
|
25
|
+
require 'tempfile'
|
26
|
+
require 'open3'
|
27
|
+
|
28
|
+
module Locca
|
29
|
+
class TranslateAction
|
30
|
+
def initialize(project, lang, collection_builder, collection_writer, collection_merger)
|
31
|
+
@project = project
|
32
|
+
@lang = lang
|
33
|
+
@collection_merger = collection_merger
|
34
|
+
@collection_builder = collection_builder
|
35
|
+
@collection_writer = collection_writer
|
36
|
+
end
|
37
|
+
|
38
|
+
def execute()
|
39
|
+
editor = ENV['EDITOR']
|
40
|
+
if !editor
|
41
|
+
raise ArgumentError, 'EDITOR variable should be defined'
|
42
|
+
end
|
43
|
+
|
44
|
+
@project.collection_names().each do |collection_name|
|
45
|
+
collection_path = @project.path_for_collection(collection_name, @lang)
|
46
|
+
collection = @collection_builder.collection_at_path(collection_path)
|
47
|
+
|
48
|
+
tmpCollection = Collection.new()
|
49
|
+
|
50
|
+
collection.sorted_each do |item|
|
51
|
+
if item.translated?
|
52
|
+
next
|
53
|
+
end
|
54
|
+
|
55
|
+
tmpCollection.add_item(item)
|
56
|
+
end
|
57
|
+
|
58
|
+
if tmpCollection.count == 0
|
59
|
+
next
|
60
|
+
end
|
61
|
+
|
62
|
+
tmpFile = Tempfile.new("#{collection_name}.#{@lang}.tmp")
|
63
|
+
|
64
|
+
@collection_writer.write_to_path(tmpCollection, tmpFile.path)
|
65
|
+
command = "#{editor} #{tmpFile.path}"
|
66
|
+
stdout,stderr,status = Open3.capture3(command)
|
67
|
+
if status.success?
|
68
|
+
translated_collection = @collection_builder.collection_at_path(tmpFile.path)
|
69
|
+
@collection_merger.merge(translated_collection, collection, (CollectionMerger::ACTION_UPDATE))
|
70
|
+
@collection_writer.write_to_path(collection, collection_path)
|
71
|
+
end
|
72
|
+
tmpFile.close
|
73
|
+
tmpFile.unlink
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/lib/locca/project.rb
CHANGED
@@ -48,6 +48,15 @@ module Locca
|
|
48
48
|
return result
|
49
49
|
end
|
50
50
|
|
51
|
+
def collection_names
|
52
|
+
result = Set.new()
|
53
|
+
Dir.glob(File.join(@lang_dir, "#{@base_lang}.lproj", '*.strings')) do |filepath|
|
54
|
+
result.add(File.basename(filepath, '.strings'))
|
55
|
+
end
|
56
|
+
|
57
|
+
return result
|
58
|
+
end
|
59
|
+
|
51
60
|
def path_for_collection(collection_name, lang)
|
52
61
|
return File.join(@lang_dir, "#{lang}.lproj", "#{collection_name}.strings")
|
53
62
|
end
|
data/lib/locca/sync/onesky.rb
CHANGED
data/lib/locca/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: locca
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shurakov Evgeny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rest-client
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description:
|
84
98
|
email: inbox@shurakov.name
|
85
99
|
executables:
|
@@ -94,6 +108,7 @@ files:
|
|
94
108
|
- lib/locca/actions/build_action.rb
|
95
109
|
- lib/locca/actions/merge_action.rb
|
96
110
|
- lib/locca/actions/sync_action.rb
|
111
|
+
- lib/locca/actions/translate_action.rb
|
97
112
|
- lib/locca/collection.rb
|
98
113
|
- lib/locca/collection_builder.rb
|
99
114
|
- lib/locca/collection_item.rb
|