bisu 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -7
- data/bisu.gemspec +2 -2
- data/generic.translatable.yml +27 -0
- data/lib/bisu/knowledge_base.rb +1 -0
- data/lib/bisu/translator.rb +8 -14
- data/lib/bisu.rb +22 -3
- data/test/support/sample_translatable.yml +11 -7
- data/test/test_bisu_config.rb +8 -5
- data/test/test_bisu_translator.rb +27 -23
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e490a4eb1f3f5aa61b9dc20f112f7ab1715114db
|
4
|
+
data.tar.gz: ad057133b9eb8fc9abc73442030e4a89a4126e41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb9fddca4965aa22d9cc3101f9cb407aa994ee9fc55c476b1cdd685cfe68391dd7a96f7b8f39ad4d0a5f173fd5165eb664812cba18fa8b9c489c6f8fb76b56e3
|
7
|
+
data.tar.gz: 035ad2f3bd974d9d38564074095d6046174a442fc99e954b29c9d295b893648a9e7869130bd17adc1774e002ccba846320c92b8d70b9e190a2bea367d7aff520
|
data/README.md
CHANGED
@@ -27,7 +27,7 @@ Configuration
|
|
27
27
|
1. Create in your **iOS/Android** app project base folder a translatable.yml:
|
28
28
|
|
29
29
|
```
|
30
|
-
type: <iOS/Android>
|
30
|
+
type: <iOS/Android/RoR>
|
31
31
|
|
32
32
|
sheet_id: <GOOGLE-DRIVE-SHEET-ID>
|
33
33
|
keys_column: <GOOGLE-DRIVE-KEY-COLUMN-TITLE>
|
@@ -36,11 +36,13 @@ Configuration
|
|
36
36
|
- path/to/1st/file.translatable
|
37
37
|
- path/to/2nd/file.translatable
|
38
38
|
|
39
|
+
out_path: path/to/%{locale}.lproj/%{out_name}
|
39
40
|
out:
|
40
|
-
-
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
- locale: en
|
42
|
+
language: english
|
43
|
+
path: default_path/%{out_name}
|
44
|
+
- locale: ko
|
45
|
+
language: korean
|
44
46
|
```
|
45
47
|
|
46
48
|
1. Create a \*.translatable version for your **iOS** localization files:
|
@@ -49,7 +51,7 @@ Configuration
|
|
49
51
|
// $specialKComment1$
|
50
52
|
// $specialKComment2$
|
51
53
|
|
52
|
-
// $specialKLanguage$
|
54
|
+
// Locale: $specialKLocale$; Language used: $specialKLanguage$
|
53
55
|
|
54
56
|
/***********
|
55
57
|
* General
|
@@ -67,7 +69,7 @@ Configuration
|
|
67
69
|
|
68
70
|
<!-- $specialKComment1$ -->
|
69
71
|
<!-- $specialKComment2$ -->
|
70
|
-
<!-- $specialKLanguage$ -->
|
72
|
+
<!-- Locale: $specialKLocale$; Language used: $specialKLanguage$ -->
|
71
73
|
|
72
74
|
<resources>
|
73
75
|
<string name="delete">$kDelete$</string>
|
@@ -75,3 +77,13 @@ Configuration
|
|
75
77
|
<string name="close">$kClose$</string>
|
76
78
|
</resources>
|
77
79
|
```
|
80
|
+
|
81
|
+
1. Create a \*.translatable version for your **RoR** localization files:
|
82
|
+
|
83
|
+
```
|
84
|
+
$specialKLocale$:
|
85
|
+
resources:
|
86
|
+
delete: $kDelete$
|
87
|
+
cancel: $kCancel$
|
88
|
+
close: $kClose$
|
89
|
+
```
|
data/bisu.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'bisu'
|
3
|
-
s.version = '1.0
|
4
|
-
s.date = '2015-
|
3
|
+
s.version = '1.1.0'
|
4
|
+
s.date = '2015-07-01'
|
5
5
|
s.summary = 'A localization automation service'
|
6
6
|
s.description = 'Bisu manages your app iOS and Android localization files for you. No more copy+paste induced errors!'
|
7
7
|
s.authors = ['joaoffcosta']
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# supported types are iOS/Android/RoR
|
2
|
+
type: iOS
|
3
|
+
|
4
|
+
sheet_id: knownledge-base-sheet-id
|
5
|
+
keys_column: column-with-translation-keys
|
6
|
+
|
7
|
+
in:
|
8
|
+
- path/to/file/to/1.ext.translatable
|
9
|
+
- path/to/file/to/2.ext.translatable
|
10
|
+
- path/to/file/to/3.ext.translatable
|
11
|
+
|
12
|
+
# you may define a generic out_path common for all files
|
13
|
+
# or a more specific one in out:path
|
14
|
+
#
|
15
|
+
# when generating the out path you can use two variables:
|
16
|
+
# - locale: replaced by the out:locale
|
17
|
+
# - out_name: replaced by the input file name without .translatable
|
18
|
+
|
19
|
+
out_path: path/to/final-%{locale}/%{out_name}
|
20
|
+
out:
|
21
|
+
- locale: en
|
22
|
+
kb_language: english
|
23
|
+
path: path/to/default/%{out_name}
|
24
|
+
- locale: pt
|
25
|
+
kb_language: portuguese
|
26
|
+
- locale: pt-PT
|
27
|
+
kb_language: portuguese
|
data/lib/bisu/knowledge_base.rb
CHANGED
data/lib/bisu/translator.rb
CHANGED
@@ -6,34 +6,25 @@ module Bisu
|
|
6
6
|
@kb = knowledge_base
|
7
7
|
@type = type.downcase.to_sym
|
8
8
|
|
9
|
-
unless [:ios, :android].include?(@type)
|
9
|
+
unless [:ios, :android, :ror].include?(@type)
|
10
10
|
Logger.error("Unknown type #{@type}")
|
11
11
|
raise
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
def translate(language, in_path,
|
15
|
+
def translate(language, locale, in_path, out_path)
|
16
16
|
unless @kb.has_language?(language)
|
17
17
|
Logger.error("Unknown language #{language}")
|
18
18
|
return false
|
19
19
|
end
|
20
20
|
|
21
|
-
in_name = File.basename(in_path)
|
22
|
-
out_name = in_name.gsub(/\.translatable$/, "")
|
23
|
-
out_path = "#{out_folder}#{out_name}"
|
24
|
-
|
25
|
-
unless in_name.match /\.translatable$/
|
26
|
-
Logger.error("Expected .translatable file. Got '#{in_name}'")
|
27
|
-
return false
|
28
|
-
end
|
29
|
-
|
30
21
|
return false unless in_file = open_file(in_path, "r", true)
|
31
22
|
return false unless out_file = open_file(out_path, "w", false)
|
32
23
|
|
33
24
|
Logger.info("Translating #{in_path} to #{language} > #{out_path}...")
|
34
25
|
|
35
26
|
in_file.each_line do |line|
|
36
|
-
out_file.write(localize(line, language))
|
27
|
+
out_file.write(localize(line, language, locale))
|
37
28
|
end
|
38
29
|
|
39
30
|
out_file.flush
|
@@ -58,9 +49,10 @@ module Bisu
|
|
58
49
|
File.open(File.expand_path(file_name), method)
|
59
50
|
end
|
60
51
|
|
61
|
-
def localize(text, language)
|
52
|
+
def localize(text, language, locale)
|
62
53
|
t = text
|
63
|
-
t = t.gsub("$specialKLanguage$", language
|
54
|
+
t = t.gsub("$specialKLanguage$", language)
|
55
|
+
t = t.gsub("$specialKLocale$", locale)
|
64
56
|
t = t.gsub("$specialKComment1$", "This file was automatically generated based on a translation template.")
|
65
57
|
t = t.gsub("$specialKComment2$", "Remember to CHANGE THE TEMPLATE and not this file!")
|
66
58
|
|
@@ -86,6 +78,8 @@ module Bisu
|
|
86
78
|
elsif @type.eql?(:ios)
|
87
79
|
text = text.gsub(/\"/, "\\\\\"")
|
88
80
|
end
|
81
|
+
|
82
|
+
text
|
89
83
|
end
|
90
84
|
end
|
91
85
|
end
|
data/lib/bisu.rb
CHANGED
@@ -4,18 +4,37 @@ require 'bisu/knowledge_base'
|
|
4
4
|
require 'bisu/translator'
|
5
5
|
|
6
6
|
module Bisu
|
7
|
-
|
7
|
+
extend self
|
8
|
+
|
9
|
+
def run
|
8
10
|
if config = Bisu::Config.parse("translatable.yml")
|
9
11
|
kbase = Bisu::GoogleDriveKB.new(config[:sheet_id], config[:keys_column])
|
10
|
-
|
12
|
+
translator = Bisu::Translator.new(kbase, config[:type])
|
11
13
|
|
12
14
|
config[:in].each do |in_path|
|
13
15
|
config[:out].each do |out|
|
14
|
-
|
16
|
+
localize(translator, out[:locale], out[:kb_language], in_path, out[:path] || config[:out_path])
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
21
|
Bisu::Logger.print_summary
|
20
22
|
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def localize(translator, locale, language, in_path, out_path)
|
27
|
+
in_name = File.basename(in_path)
|
28
|
+
out_name = in_name.gsub(/\.translatable$/, "")
|
29
|
+
|
30
|
+
unless in_name.match /\.translatable$/
|
31
|
+
Logger.error("Expected .translatable file. Got '#{in_name}'")
|
32
|
+
return false
|
33
|
+
end
|
34
|
+
|
35
|
+
out_path = out_path % { locale: locale, out_name: out_name }
|
36
|
+
|
37
|
+
translator.translate(language, locale, in_path, out_path)
|
38
|
+
end
|
39
|
+
|
21
40
|
end
|
@@ -1,14 +1,18 @@
|
|
1
|
-
type:
|
1
|
+
type: BisuOS
|
2
2
|
|
3
3
|
sheet_id: abc1234567890
|
4
4
|
keys_column: key_name
|
5
5
|
|
6
6
|
in:
|
7
|
-
-
|
8
|
-
-
|
7
|
+
- path/to/file/to/1.ext.translatable
|
8
|
+
- path/to/file/to/2.ext.translatable
|
9
9
|
|
10
|
+
out_path: path/to/final-%{locale}/%{out_name}
|
10
11
|
out:
|
11
|
-
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
- locale: en
|
13
|
+
kb_language: english
|
14
|
+
path: path/to/default/%{out_name}
|
15
|
+
- locale: pt
|
16
|
+
kb_language: portuguese
|
17
|
+
- locale: pt-PT
|
18
|
+
kb_language: portuguese
|
data/test/test_bisu_config.rb
CHANGED
@@ -6,18 +6,21 @@ class BisuConfigTest < Minitest::Test
|
|
6
6
|
def test_parse
|
7
7
|
config = Bisu::Config.parse("test/support/sample_translatable.yml")
|
8
8
|
|
9
|
-
assert_equal config[:type], "
|
9
|
+
assert_equal config[:type], "BisuOS"
|
10
10
|
assert_equal config[:sheet_id], "abc1234567890"
|
11
11
|
assert_equal config[:keys_column], "key_name"
|
12
12
|
|
13
13
|
assert_equal config[:in], [
|
14
|
-
"
|
15
|
-
"
|
14
|
+
"path/to/file/to/1.ext.translatable",
|
15
|
+
"path/to/file/to/2.ext.translatable"
|
16
16
|
]
|
17
17
|
|
18
|
+
assert_equal config[:out_path], "path/to/final-%{locale}/%{out_name}"
|
19
|
+
|
18
20
|
assert_equal config[:out], [
|
19
|
-
{
|
20
|
-
{
|
21
|
+
{ locale: "en", kb_language: "english", path: "path/to/default/%{out_name}" },
|
22
|
+
{ locale: "pt", kb_language: "portuguese" },
|
23
|
+
{ locale: "pt-PT", kb_language: "portuguese" }
|
21
24
|
]
|
22
25
|
end
|
23
26
|
end
|
@@ -4,50 +4,54 @@ require 'bisu/translator'
|
|
4
4
|
class BisuTranslatorTest < Minitest::Test
|
5
5
|
|
6
6
|
def setup
|
7
|
+
@lang = "portuguese"
|
8
|
+
@locale = "portuguese"
|
9
|
+
|
7
10
|
kb = Bisu::KnowledgeBase.new({
|
8
|
-
languages: [
|
11
|
+
languages: [@lang],
|
9
12
|
keys: {
|
10
|
-
"kRegularKey" => {
|
11
|
-
"kIOSKey" => {
|
12
|
-
"kAndroidKey1" => {
|
13
|
-
"kAndroidKey2" => {
|
14
|
-
"kAndroidKey3" => {
|
13
|
+
"kRegularKey" => { @lang => "Não sabes nada João das Neves" },
|
14
|
+
"kIOSKey" => { @lang => "Não sabes nada \"João das Neves\"" },
|
15
|
+
"kAndroidKey1" => { @lang => "Não sabes nada 'João das Neves'" },
|
16
|
+
"kAndroidKey2" => { @lang => "Não sabes nada João das Neves..." },
|
17
|
+
"kAndroidKey3" => { @lang => "Não sabes nada João das Neves & Pícaros" },
|
15
18
|
}
|
16
19
|
})
|
17
20
|
|
18
21
|
@tios = Bisu::Translator.new(kb, :ios)
|
19
22
|
@tand = Bisu::Translator.new(kb, :android)
|
23
|
+
@tror = Bisu::Translator.new(kb, :ror)
|
20
24
|
end
|
21
25
|
|
22
26
|
def test_simple_translate
|
23
27
|
orig1 = "1: $specialKComment1$"
|
24
28
|
orig2 = "2: $specialKComment2$"
|
25
29
|
orig3 = "3: $specialKLanguage$"
|
26
|
-
orig4 = "4: $
|
30
|
+
orig4 = "4: $specialKLocale$"
|
31
|
+
orig5 = "5: $kRegularKey$"
|
27
32
|
|
28
33
|
loc1 = "1: This file was automatically generated based on a translation template."
|
29
34
|
loc2 = "2: Remember to CHANGE THE TEMPLATE and not this file!"
|
30
|
-
loc3 = "3:
|
31
|
-
loc4 = "4:
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
assert_equal @tand.send(:localize, orig4, "PT"), loc4
|
35
|
+
loc3 = "3: #{@lang}"
|
36
|
+
loc4 = "4: #{@locale}"
|
37
|
+
loc5 = "5: Não sabes nada João das Neves"
|
38
|
+
|
39
|
+
[@tios, @tand, @tror].each do |translator|
|
40
|
+
assert_equal translator.send(:localize, orig1, @lang, @locale), loc1
|
41
|
+
assert_equal translator.send(:localize, orig2, @lang, @locale), loc2
|
42
|
+
assert_equal translator.send(:localize, orig3, @lang, @locale), loc3
|
43
|
+
assert_equal translator.send(:localize, orig4, @lang, @locale), loc4
|
44
|
+
assert_equal translator.send(:localize, orig5, @lang, @locale), loc5
|
45
|
+
end
|
42
46
|
end
|
43
47
|
|
44
48
|
def test_ios_translate
|
45
|
-
assert_equal @tios.send(:localize, "1: $kIOSKey$",
|
49
|
+
assert_equal @tios.send(:localize, "1: $kIOSKey$", @lang, @locale), "1: Não sabes nada \\\"João das Neves\\\""
|
46
50
|
end
|
47
51
|
|
48
52
|
def test_android_translate
|
49
|
-
assert_equal @tand.send(:localize, "1: $kAndroidKey1$",
|
50
|
-
assert_equal @tand.send(:localize, "2: $kAndroidKey2$",
|
51
|
-
assert_equal @tand.send(:localize, "3: $kAndroidKey3$",
|
53
|
+
assert_equal @tand.send(:localize, "1: $kAndroidKey1$", @lang, @locale), "1: Não sabes nada \\'João das Neves\\'"
|
54
|
+
assert_equal @tand.send(:localize, "2: $kAndroidKey2$", @lang, @locale), "2: Não sabes nada João das Neves…"
|
55
|
+
assert_equal @tand.send(:localize, "3: $kAndroidKey3$", @lang, @locale), "3: Não sabes nada João das Neves & Pícaros"
|
52
56
|
end
|
53
57
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bisu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- joaoffcosta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: safe_yaml
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- Rakefile
|
79
79
|
- bin/bisu
|
80
80
|
- bisu.gemspec
|
81
|
+
- generic.translatable.yml
|
81
82
|
- lib/bisu.rb
|
82
83
|
- lib/bisu/config.rb
|
83
84
|
- lib/bisu/knowledge_base.rb
|