bisu 1.0.2 → 1.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 27aa9e1bc6a0eb2218bc99a5d06f1bebc63c9db5
4
- data.tar.gz: 8ff3ce596fbfce168e2296082cd34b59c1dc9f4e
3
+ metadata.gz: e490a4eb1f3f5aa61b9dc20f112f7ab1715114db
4
+ data.tar.gz: ad057133b9eb8fc9abc73442030e4a89a4126e41
5
5
  SHA512:
6
- metadata.gz: 61c5974e3619d06838df1856a4ce4e1cb758adc68de07ce987127725e91c59f04e6d1757e108b08434c25dc18a01aaf8809e8e45bbcc783610b797af617492c9
7
- data.tar.gz: 7d242608af60a2bb3fe75ee11dcb68edbe9e81b99da62a5c5595b22b67af5e88ebaa0f253b34d4d612dda9351647e208627e67021a9560b3803651a779a8d373
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
- - language: english
41
- folder: path/to/en.lproj/
42
- - language: korean
43
- folder: path/to/ko.lproj/
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.2'
4
- s.date = '2015-02-25'
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
@@ -38,6 +38,7 @@ module Bisu
38
38
  uri = URI.parse(uri)
39
39
  http = Net::HTTP.new(uri.host, uri.port)
40
40
  http.use_ssl = true
41
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
41
42
  data = http.get(uri.path, headers)
42
43
  XmlSimple.xml_in(data.body, 'KeyAttr' => 'name')
43
44
  end
@@ -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, out_folder)
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.upcase)
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
- def self.run
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
- trans = Bisu::Translator.new(kbase, config[:type])
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
- trans.translate(out[:language], in_path, out[:folder])
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: iOS
1
+ type: BisuOS
2
2
 
3
3
  sheet_id: abc1234567890
4
4
  keys_column: key_name
5
5
 
6
6
  in:
7
- - folder/file_1.translatable
8
- - folder/file_2.translatable
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
- - language: english
12
- folder: hole19/en.lproj/
13
- - language: portuguese
14
- folder: hole19/pt.lproj/
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
@@ -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], "iOS"
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
- "folder/file_1.translatable",
15
- "folder/file_2.translatable"
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
- { language: "english", folder: "hole19/en.lproj/" },
20
- { language: "portuguese", folder: "hole19/pt.lproj/" }
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: ["PT"],
11
+ languages: [@lang],
9
12
  keys: {
10
- "kRegularKey" => { "PT" => "Não sabes nada João das Neves" },
11
- "kIOSKey" => { "PT" => "Não sabes nada \"João das Neves\"" },
12
- "kAndroidKey1" => { "PT" => "Não sabes nada 'João das Neves'" },
13
- "kAndroidKey2" => { "PT" => "Não sabes nada João das Neves..." },
14
- "kAndroidKey3" => { "PT" => "Não sabes nada João das Neves & Pícaros" },
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: $kRegularKey$"
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: PT"
31
- loc4 = "4: Não sabes nada João das Neves"
32
-
33
- assert_equal @tios.send(:localize, orig1, "PT"), loc1
34
- assert_equal @tios.send(:localize, orig2, "PT"), loc2
35
- assert_equal @tios.send(:localize, orig3, "PT"), loc3
36
- assert_equal @tios.send(:localize, orig4, "PT"), loc4
37
-
38
- assert_equal @tand.send(:localize, orig1, "PT"), loc1
39
- assert_equal @tand.send(:localize, orig2, "PT"), loc2
40
- assert_equal @tand.send(:localize, orig3, "PT"), loc3
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$", "PT"), "1: Não sabes nada \\\"João das Neves\\\""
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$", "PT"), "1: Não sabes nada \\'João das Neves\\'"
50
- assert_equal @tand.send(:localize, "2: $kAndroidKey2$", "PT"), "2: Não sabes nada João das Neves…"
51
- assert_equal @tand.send(:localize, "3: $kAndroidKey3$", "PT"), "3: Não sabes nada João das Neves &amp; Pícaros"
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 &amp; 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.2
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-02-25 00:00:00.000000000 Z
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