locca 0.9.4 → 0.9.5
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 +4 -4
- data/bin/locca +1 -2
- data/lib/locca.rb +12 -24
- data/lib/locca/actions/build_action.rb +1 -1
- data/lib/locca/actions/onesky_sync_action.rb +7 -7
- data/lib/locca/android_collection_writer.rb +81 -0
- data/lib/locca/android_collections_generator.rb +47 -0
- data/lib/locca/android_strings_parser.rb +59 -0
- data/lib/locca/collection_builder.rb +1 -1
- data/lib/locca/collection_item.rb +8 -0
- data/lib/locca/collections_generator.rb +4 -3
- data/lib/locca/projects/android_project.rb +81 -0
- data/lib/locca/{project.rb → projects/project.rb} +25 -15
- data/lib/locca/{project_dir_locator.rb → projects/project_dir_locator.rb} +0 -0
- data/lib/locca/{project_factory.rb → projects/project_factory.rb} +7 -7
- data/lib/locca/projects/xcode_project.rb +80 -0
- data/lib/locca/sync/onesky.rb +2 -2
- data/lib/locca/version.rb +1 -1
- metadata +24 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 184b6cefe3ca2452b2c4bdc102fcbd09ea2cad2a
|
4
|
+
data.tar.gz: e925c505ba4e6fc1ab27606bd611f41eb2fb2386
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b41bbd7d5d909882cd0550d78b336dba9cecd400b0999d32a1718aa5ba34ccafe01ce063cbf4e5b398eed02aac5cf434bbe8ea1d903d8525f5e53fd9bdba4833
|
7
|
+
data.tar.gz: 08cdcfbac26a8874f2d0a0638eb8ae1e957bcb0f3b318b61ecaff96ea2a2516a5e54e6eb550067acc309cc4bda732f3113a3536290f99a2c9c0b2590592824d8
|
data/bin/locca
CHANGED
@@ -117,8 +117,7 @@ end
|
|
117
117
|
def project_in_dir(dir)
|
118
118
|
project_dir_locator = Locca::ProjectDirLocator.new()
|
119
119
|
config_reader = Locca::ConfigReader.new()
|
120
|
-
|
121
|
-
project_factory = Locca::ProjectFactory.new(project_dir_locator, config_reader, config_validator)
|
120
|
+
project_factory = Locca::ProjectFactory.new(project_dir_locator, config_reader)
|
122
121
|
|
123
122
|
project = project_factory.new_project(dir)
|
124
123
|
end
|
data/lib/locca.rb
CHANGED
@@ -24,9 +24,11 @@
|
|
24
24
|
|
25
25
|
require 'locca/version'
|
26
26
|
|
27
|
-
require 'locca/
|
28
|
-
require 'locca/
|
29
|
-
require 'locca/
|
27
|
+
require 'locca/projects/project_dir_locator'
|
28
|
+
require 'locca/projects/project_factory'
|
29
|
+
require 'locca/projects/project'
|
30
|
+
require 'locca/projects/xcode_project'
|
31
|
+
require 'locca/projects/android_project'
|
30
32
|
|
31
33
|
require 'locca/config_reader'
|
32
34
|
require 'locca/config_validator'
|
@@ -45,6 +47,10 @@ require 'locca/collection_writer'
|
|
45
47
|
require 'locca/collection_item_condensed_formatter'
|
46
48
|
require 'locca/collection_item_default_formatter'
|
47
49
|
|
50
|
+
require 'locca/android_collection_writer'
|
51
|
+
require 'locca/android_collections_generator'
|
52
|
+
require 'locca/android_strings_parser'
|
53
|
+
|
48
54
|
require 'locca/genstrings'
|
49
55
|
|
50
56
|
require 'babelyoda/strings_lexer'
|
@@ -90,36 +96,18 @@ module Locca
|
|
90
96
|
lang = project.base_lang
|
91
97
|
end
|
92
98
|
|
93
|
-
|
94
|
-
action = TranslateAction.new(project, lang, collection_builder, collection_writer(), collection_merger())
|
99
|
+
action = TranslateAction.new(project, lang, project.collection_builder, project.collection_writer, collection_merger())
|
95
100
|
action.execute()
|
96
101
|
end
|
97
102
|
|
98
103
|
def build_action(project)
|
99
|
-
|
100
|
-
collection_builder = collection_builder()
|
101
|
-
collections_generator = CollectionsGenerator.new(genstrings, collection_builder)
|
102
|
-
|
103
|
-
return BuildAction.new(project, collection_builder, collection_writer(), collections_generator, collection_merger())
|
104
|
+
return BuildAction.new(project, project.collection_builder(), project.collection_writer(), project.collections_generator(), collection_merger())
|
104
105
|
end
|
105
106
|
|
106
107
|
def one_sky_action(project)
|
107
|
-
genstrings = Genstrings.new()
|
108
|
-
collection_builder = collection_builder()
|
109
|
-
collections_generator = CollectionsGenerator.new(genstrings, collection_builder)
|
110
|
-
|
111
108
|
onesky = Onesky.new(project.config_value_for_key('onesky_project_id'), project.config_value_for_key('onesky_public_key'), project.config_value_for_key('onesky_secret_key'))
|
112
109
|
|
113
|
-
return OneskySyncAction.new(project, onesky, collection_builder(), collection_writer(), collections_generator, collection_merger())
|
114
|
-
end
|
115
|
-
|
116
|
-
def collection_builder()
|
117
|
-
parser = Babelyoda::StringsParser.new(Babelyoda::StringsLexer.new())
|
118
|
-
return CollectionBuilder.new(File, parser)
|
119
|
-
end
|
120
|
-
|
121
|
-
def collection_writer()
|
122
|
-
return CollectionWriter.new(File, CollectionItemDefaultFormatter.new())
|
110
|
+
return OneskySyncAction.new(project, onesky, project.collection_builder(), project.collection_writer(), project.collections_generator(), collection_merger())
|
123
111
|
end
|
124
112
|
|
125
113
|
def collection_merger()
|
@@ -35,7 +35,7 @@ module Locca
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def execute()
|
38
|
-
generated_collections = @collections_generator.generate(
|
38
|
+
generated_collections = @collections_generator.generate()
|
39
39
|
langs = @project.langs()
|
40
40
|
|
41
41
|
generated_collections.each do |generated_collection|
|
@@ -40,22 +40,22 @@ module Locca
|
|
40
40
|
@onesky = onesky
|
41
41
|
|
42
42
|
@langs = @project.langs()
|
43
|
-
@generated_collections = @collections_generator.generate(
|
43
|
+
@generated_collections = @collections_generator.generate()
|
44
44
|
end
|
45
45
|
|
46
46
|
def fetch()
|
47
47
|
# 1
|
48
48
|
@generated_collections.each do |generated_collection|
|
49
49
|
@langs.each do |lang|
|
50
|
-
print "[*] fetch: #{lang}/#{generated_collection.name}
|
51
|
-
data = @onesky.fetch_translations(lang,
|
50
|
+
print "[*] fetch: #{lang}/#{generated_collection.name}\n"
|
51
|
+
data = @onesky.fetch_translations(lang, @project.full_collection_name(generated_collection.name))
|
52
52
|
fetched_collection = @collection_builder.collection_from_datastring(data)
|
53
53
|
|
54
54
|
local_collection_path = @project.path_for_collection(generated_collection.name, lang)
|
55
55
|
local_collection = @collection_builder.collection_at_path(local_collection_path)
|
56
56
|
|
57
57
|
# 2
|
58
|
-
print "[*] merge: onesky -> #{lang}/#{generated_collection.name}
|
58
|
+
print "[*] merge: onesky -> #{lang}/#{generated_collection.name}\n"
|
59
59
|
@collection_merger.merge(fetched_collection, local_collection, CollectionMerger::ACTION_ADD | CollectionMerger::ACTION_UPDATE)
|
60
60
|
@collection_writer.write_to_path(local_collection, local_collection_path)
|
61
61
|
end
|
@@ -68,7 +68,7 @@ module Locca
|
|
68
68
|
# 3
|
69
69
|
@generated_collections.each do |generated_collection|
|
70
70
|
@langs.each do |lang|
|
71
|
-
print "[*] merge: code -> #{lang}/#{generated_collection.name}
|
71
|
+
print "[*] merge: code -> #{lang}/#{generated_collection.name}\n"
|
72
72
|
|
73
73
|
collection_path = @project.path_for_collection(generated_collection.name, lang)
|
74
74
|
collection = @collection_builder.collection_at_path(collection_path)
|
@@ -79,9 +79,9 @@ module Locca
|
|
79
79
|
|
80
80
|
# 4
|
81
81
|
@generated_collections.each do |generated_collection|
|
82
|
-
print "[*] upload: #{@project.base_lang}/#{generated_collection.name}
|
82
|
+
print "[*] upload: #{@project.base_lang}/#{generated_collection.name}\n"
|
83
83
|
collection_path = @project.path_for_collection(generated_collection.name, @project.base_lang())
|
84
|
-
@onesky.upload_file(collection_path)
|
84
|
+
@onesky.upload_file(collection_path, @project.one_sky_file_format)
|
85
85
|
end
|
86
86
|
end
|
87
87
|
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
#
|
2
|
+
# The MIT License (MIT)
|
3
|
+
#
|
4
|
+
# Copyright (c) 2015 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 'nokogiri'
|
26
|
+
|
27
|
+
module Locca
|
28
|
+
|
29
|
+
class AndroidCollectionWriter
|
30
|
+
|
31
|
+
def initialize(file_manager)
|
32
|
+
@file_manager = file_manager
|
33
|
+
end
|
34
|
+
|
35
|
+
def write_to_path(collection, filepath)
|
36
|
+
if not filepath
|
37
|
+
raise ArgumentException, 'filepath can\'t be nil'
|
38
|
+
end
|
39
|
+
|
40
|
+
FileUtils.mkdir_p(@file_manager.dirname(filepath))
|
41
|
+
|
42
|
+
|
43
|
+
document = Nokogiri::XML("")
|
44
|
+
document.encoding = "UTF-8"
|
45
|
+
|
46
|
+
resources = Nokogiri::XML::Node.new('resources', document)
|
47
|
+
|
48
|
+
collection.sorted_each do |item|
|
49
|
+
if item.comment
|
50
|
+
resources.add_child(Nokogiri::XML::Comment.new(document, " #{item.comment} "))
|
51
|
+
end
|
52
|
+
|
53
|
+
if item.plural?
|
54
|
+
node = Nokogiri::XML::Node.new('plurals', document)
|
55
|
+
node["name"] = item.key
|
56
|
+
|
57
|
+
item.value.each do |key, value|
|
58
|
+
nodeItem = Nokogiri::XML::Node.new('item', document)
|
59
|
+
nodeItem["quantity"] = key
|
60
|
+
nodeItem.content = value
|
61
|
+
node.add_child(nodeItem)
|
62
|
+
end
|
63
|
+
|
64
|
+
resources.add_child(node)
|
65
|
+
else
|
66
|
+
node = Nokogiri::XML::Node.new('string', document)
|
67
|
+
node["name"] = item.key
|
68
|
+
node.content = item.value
|
69
|
+
resources.add_child(node)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
document.root = resources
|
74
|
+
|
75
|
+
@file_manager.open(filepath, "w") do |io|
|
76
|
+
io << document.to_xml
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#
|
2
|
+
# The MIT License (MIT)
|
3
|
+
#
|
4
|
+
# Copyright (c) 2015 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
|
+
module Locca
|
26
|
+
|
27
|
+
class AndroidCollectionsGenerator
|
28
|
+
|
29
|
+
def initialize(project, collection_builder)
|
30
|
+
@collection_builder = collection_builder
|
31
|
+
@project = project
|
32
|
+
end
|
33
|
+
|
34
|
+
def generate()
|
35
|
+
result = Array.new()
|
36
|
+
|
37
|
+
@project.collection_names.each do |collection_name|
|
38
|
+
collection_path = @project.path_for_collection(collection_name, @project.base_lang)
|
39
|
+
collection = @collection_builder.collection_at_path(collection_path)
|
40
|
+
result.push(collection)
|
41
|
+
end
|
42
|
+
|
43
|
+
return result
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#
|
2
|
+
# The MIT License (MIT)
|
3
|
+
#
|
4
|
+
# Copyright (c) 2015 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 'nokogiri'
|
26
|
+
|
27
|
+
module Locca
|
28
|
+
|
29
|
+
class AndroidStringsParser
|
30
|
+
|
31
|
+
def initialize()
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def parse(str, &block)
|
36
|
+
doc = Nokogiri::XML(str)
|
37
|
+
comment = nil
|
38
|
+
|
39
|
+
for node in doc.root.children
|
40
|
+
if node.comment?
|
41
|
+
comment = node.text.strip
|
42
|
+
elsif node.element?
|
43
|
+
if node.name == "string"
|
44
|
+
block.call(node["name"], node.text, comment)
|
45
|
+
comment = nil
|
46
|
+
elsif node.name == "plurals"
|
47
|
+
values = Hash.new()
|
48
|
+
for pluralItem in node.xpath('.//item')
|
49
|
+
values[pluralItem["quantity"]] = pluralItem.text
|
50
|
+
end
|
51
|
+
block.call(node["name"], values, comment)
|
52
|
+
comment = nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -36,7 +36,7 @@ module Locca
|
|
36
36
|
|
37
37
|
@file_manager.open(path, 'rb:BOM|UTF-8:UTF-8') do |file|
|
38
38
|
collection = collection_from_datastring(file.read())
|
39
|
-
collection.name = File.basename(path,
|
39
|
+
collection.name = File.basename(path, File.extname(path))
|
40
40
|
end
|
41
41
|
|
42
42
|
return collection
|
@@ -24,14 +24,15 @@
|
|
24
24
|
|
25
25
|
module Locca
|
26
26
|
class CollectionsGenerator
|
27
|
-
def initialize(genstrings, collection_builder)
|
27
|
+
def initialize(project, genstrings, collection_builder)
|
28
|
+
@project = project
|
28
29
|
@genstrings = genstrings
|
29
30
|
@collection_builder = collection_builder
|
30
31
|
end
|
31
32
|
|
32
|
-
def generate(
|
33
|
+
def generate()
|
33
34
|
result = Array.new()
|
34
|
-
@genstrings.generate(code_dir) do |filepath|
|
35
|
+
@genstrings.generate(@project.code_dir) do |filepath|
|
35
36
|
collection = @collection_builder.collection_at_path(filepath)
|
36
37
|
result.push(collection)
|
37
38
|
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
#
|
2
|
+
# The MIT License (MIT)
|
3
|
+
#
|
4
|
+
# Copyright (c) 2015 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_relative 'project'
|
26
|
+
|
27
|
+
module Locca
|
28
|
+
class AndroidProject < Project
|
29
|
+
|
30
|
+
def initialize(dir, config)
|
31
|
+
super(dir, config)
|
32
|
+
end
|
33
|
+
|
34
|
+
def langs
|
35
|
+
result = Set.new()
|
36
|
+
result.add(self.base_lang)
|
37
|
+
|
38
|
+
Dir.glob(File.join(@lang_dir, 'values-*')) do |filepath|
|
39
|
+
result.add(File.basename(filepath).split('-', 2).last)
|
40
|
+
end
|
41
|
+
|
42
|
+
return result
|
43
|
+
end
|
44
|
+
|
45
|
+
def collection_names
|
46
|
+
result = Set.new()
|
47
|
+
result.add('strings');
|
48
|
+
return result
|
49
|
+
end
|
50
|
+
|
51
|
+
def full_collection_name(collection_name)
|
52
|
+
return "#{collection_name}.xml"
|
53
|
+
end
|
54
|
+
|
55
|
+
def path_for_collection(collection_name, lang)
|
56
|
+
if (lang == self.base_lang)
|
57
|
+
return File.join(@lang_dir, "values", "#{collection_name}.xml")
|
58
|
+
else
|
59
|
+
return File.join(@lang_dir, "values-#{lang}", "#{collection_name}.xml")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def collection_builder()
|
64
|
+
parser = AndroidStringsParser.new()
|
65
|
+
return CollectionBuilder.new(File, parser)
|
66
|
+
end
|
67
|
+
|
68
|
+
def collection_writer()
|
69
|
+
return AndroidCollectionWriter.new(File)
|
70
|
+
end
|
71
|
+
|
72
|
+
def collections_generator()
|
73
|
+
return AndroidCollectionsGenerator.new(self, collection_builder())
|
74
|
+
end
|
75
|
+
|
76
|
+
def one_sky_file_format
|
77
|
+
return "ANDROID_XML"
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
@@ -25,7 +25,6 @@
|
|
25
25
|
module Locca
|
26
26
|
class Project
|
27
27
|
attr_reader :dir
|
28
|
-
attr_reader :code_dir
|
29
28
|
attr_reader :lang_dir
|
30
29
|
|
31
30
|
attr_reader :base_lang
|
@@ -34,35 +33,46 @@ module Locca
|
|
34
33
|
@dir = dir
|
35
34
|
@config = config
|
36
35
|
|
37
|
-
@code_dir = File.join(dir, config['code_dir'])
|
38
36
|
@lang_dir = File.join(dir, config['lang_dir'])
|
39
37
|
|
40
38
|
@base_lang = config['base_lang']
|
41
39
|
end
|
42
40
|
|
41
|
+
def config_value_for_key(key)
|
42
|
+
return @config[key]
|
43
|
+
end
|
44
|
+
|
43
45
|
def langs
|
44
|
-
|
45
|
-
Dir.glob(File.join(@lang_dir, '*.lproj')) do |filepath|
|
46
|
-
result.add(File.basename(filepath, '.lproj'))
|
47
|
-
end
|
48
|
-
return result
|
46
|
+
# implement in subclass
|
49
47
|
end
|
50
48
|
|
51
49
|
def collection_names
|
52
|
-
|
53
|
-
|
54
|
-
result.add(File.basename(filepath, '.strings'))
|
55
|
-
end
|
50
|
+
# implement in subclass
|
51
|
+
end
|
56
52
|
|
57
|
-
|
53
|
+
def full_collection_name(collection_name)
|
54
|
+
# implement in subclass
|
58
55
|
end
|
59
56
|
|
60
57
|
def path_for_collection(collection_name, lang)
|
61
|
-
|
58
|
+
# implement in subclass
|
62
59
|
end
|
63
60
|
|
64
|
-
def
|
65
|
-
|
61
|
+
def collection_builder
|
62
|
+
# implement in subclass
|
66
63
|
end
|
64
|
+
|
65
|
+
def collection_writer
|
66
|
+
# implement in subclass
|
67
|
+
end
|
68
|
+
|
69
|
+
def collections_generator
|
70
|
+
# implement in subclass
|
71
|
+
end
|
72
|
+
|
73
|
+
def one_sky_file_format
|
74
|
+
# implement in subclass
|
75
|
+
end
|
76
|
+
|
67
77
|
end
|
68
78
|
end
|
File without changes
|
@@ -21,7 +21,7 @@
|
|
21
21
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
22
|
# SOFTWARE.
|
23
23
|
#
|
24
|
-
require_relative '
|
24
|
+
require_relative 'xcode_project'
|
25
25
|
|
26
26
|
module Locca
|
27
27
|
class ProjectNotFoundError < RuntimeError
|
@@ -35,10 +35,9 @@ module Locca
|
|
35
35
|
|
36
36
|
class ProjectFactory
|
37
37
|
|
38
|
-
def initialize(project_dir_locator, config_reader
|
38
|
+
def initialize(project_dir_locator, config_reader)
|
39
39
|
@project_dir_locator = project_dir_locator
|
40
40
|
@config_reader = config_reader
|
41
|
-
@config_validator = config_validator
|
42
41
|
end
|
43
42
|
|
44
43
|
def new_project(project_dir)
|
@@ -52,11 +51,12 @@ module Locca
|
|
52
51
|
raise ConfigNotFoundError, 'Can\'t find .locca/config'
|
53
52
|
end
|
54
53
|
|
55
|
-
if
|
56
|
-
|
54
|
+
if Dir.glob("#{project_dir}/**/AndroidManifest.xml").length > 0
|
55
|
+
return AndroidProject.new(project_dir, config)
|
56
|
+
else
|
57
|
+
return XcodeProject.new(project_dir, config)
|
57
58
|
end
|
58
|
-
|
59
|
-
return Project.new(project_dir, config)
|
59
|
+
|
60
60
|
end
|
61
61
|
|
62
62
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
#
|
2
|
+
# The MIT License (MIT)
|
3
|
+
#
|
4
|
+
# Copyright (c) 2015 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_relative 'project'
|
26
|
+
|
27
|
+
module Locca
|
28
|
+
class XcodeProject < Project
|
29
|
+
attr_reader :code_dir
|
30
|
+
|
31
|
+
def initialize(dir, config)
|
32
|
+
super(dir, config)
|
33
|
+
@code_dir = File.join(dir, config['code_dir'])
|
34
|
+
end
|
35
|
+
|
36
|
+
def langs
|
37
|
+
result = Set.new()
|
38
|
+
Dir.glob(File.join(@lang_dir, '*.lproj')) do |filepath|
|
39
|
+
result.add(File.basename(filepath, '.lproj'))
|
40
|
+
end
|
41
|
+
|
42
|
+
return result
|
43
|
+
end
|
44
|
+
|
45
|
+
def collection_names
|
46
|
+
result = Set.new()
|
47
|
+
Dir.glob(File.join(@lang_dir, "#{@base_lang}.lproj", '*.strings')) do |filepath|
|
48
|
+
result.add(File.basename(filepath, '.strings'))
|
49
|
+
end
|
50
|
+
|
51
|
+
return result
|
52
|
+
end
|
53
|
+
|
54
|
+
def full_collection_name(collection_name)
|
55
|
+
return "#{collection_name}.strings"
|
56
|
+
end
|
57
|
+
|
58
|
+
def path_for_collection(collection_name, lang)
|
59
|
+
return File.join(@lang_dir, "#{lang}.lproj", "#{collection_name}.strings")
|
60
|
+
end
|
61
|
+
|
62
|
+
def collection_builder()
|
63
|
+
parser = Babelyoda::StringsParser.new(Babelyoda::StringsLexer.new())
|
64
|
+
return CollectionBuilder.new(File, parser)
|
65
|
+
end
|
66
|
+
|
67
|
+
def collection_writer()
|
68
|
+
return CollectionWriter.new(File, CollectionItemDefaultFormatter.new())
|
69
|
+
end
|
70
|
+
|
71
|
+
def collections_generator()
|
72
|
+
return CollectionsGenerator.new(self, Genstrings.new(), collection_builder())
|
73
|
+
end
|
74
|
+
|
75
|
+
def one_sky_file_format
|
76
|
+
return "IOS_STRINGS"
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
data/lib/locca/sync/onesky.rb
CHANGED
@@ -34,8 +34,8 @@ module Locca
|
|
34
34
|
@secret_key = secret_key
|
35
35
|
end
|
36
36
|
|
37
|
-
def upload_file(file_path)
|
38
|
-
fetch_response(:post, "files", {'file' => File.new(file_path), 'file_format' =>
|
37
|
+
def upload_file(file_path, file_format)
|
38
|
+
fetch_response(:post, "files", {'file' => File.new(file_path), 'file_format' => file_format, 'is_keeping_all_strings' => 'false'})
|
39
39
|
end
|
40
40
|
|
41
41
|
def fetch_translations(lang, file_name)
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shurakov Evgeny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: nokogiri
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description:
|
98
112
|
email: inbox@shurakov.name
|
99
113
|
executables:
|
@@ -109,6 +123,9 @@ files:
|
|
109
123
|
- lib/locca/actions/merge_action.rb
|
110
124
|
- lib/locca/actions/onesky_sync_action.rb
|
111
125
|
- lib/locca/actions/translate_action.rb
|
126
|
+
- lib/locca/android_collection_writer.rb
|
127
|
+
- lib/locca/android_collections_generator.rb
|
128
|
+
- lib/locca/android_strings_parser.rb
|
112
129
|
- lib/locca/collection.rb
|
113
130
|
- lib/locca/collection_builder.rb
|
114
131
|
- lib/locca/collection_item.rb
|
@@ -120,9 +137,11 @@ files:
|
|
120
137
|
- lib/locca/config_reader.rb
|
121
138
|
- lib/locca/config_validator.rb
|
122
139
|
- lib/locca/genstrings.rb
|
123
|
-
- lib/locca/
|
124
|
-
- lib/locca/
|
125
|
-
- lib/locca/
|
140
|
+
- lib/locca/projects/android_project.rb
|
141
|
+
- lib/locca/projects/project.rb
|
142
|
+
- lib/locca/projects/project_dir_locator.rb
|
143
|
+
- lib/locca/projects/project_factory.rb
|
144
|
+
- lib/locca/projects/xcode_project.rb
|
126
145
|
- lib/locca/sync/onesky.rb
|
127
146
|
- lib/locca/version.rb
|
128
147
|
- lib/locca.rb
|