bisu 1.2.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3653a0a2945c287e0d77426b0701596ecbc626e7
4
- data.tar.gz: c1c4ea04cedda5020ffd836589e885a482ddeef5
3
+ metadata.gz: 26ad7d61670e9ff3ad16fd40743a7d3d9a7543ba
4
+ data.tar.gz: 257a0a78ac010b9be31fbf1f4e76676189b50419
5
5
  SHA512:
6
- metadata.gz: a9e3bf46581c3d02f52e1ba3820680be3dfb07190c1171ecd29d66e4ec4f3725d8b39caca86f4379e8427e8801d622577d1ec4a98a2d69a8862bcb2691820f9f
7
- data.tar.gz: ecb9703fd7ef9c39b9fbaf537824554fee0acb9ada737ae0bcc3002fd76fff61cc420e29641cbbb5b40fd55d6b24512f213c033b4f1e27b5f5cefdf043ac3584
6
+ metadata.gz: c2e4b66ceac94f6b4d2274225af7e4780c9c6b85e64a9e38cd403aa447d54f27c078cf7683ecadd86cbd7e2089575ca12e44c296056dc5a1bac848587b9e1acf
7
+ data.tar.gz: 81eff7ef5103393fb0fbc7295c70a9c1dedbb9b224491e7a68d18ebdc9b0e9fee1616d080d6809a1c492f7f2d492c4294bc43c0a2d020d35ad00823ee6a3ba6d
data/README.md CHANGED
@@ -60,8 +60,7 @@ Configuration
60
60
  "klGeneral_Delete" = "$kDelete$";
61
61
  "klGeneral_Cancel" = "$kCancel$";
62
62
  "klGeneral_Close" = "$kClose$";
63
-
64
- "klRequestName" = "$kRequestName%{user_name: %@}$";
63
+ "klRequestName" = "$kRequestName%{user_name: %@}$";
65
64
  ```
66
65
 
67
66
  1. Create a \*.translatable version for your **Android** localization files:
data/bin/bisu CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'bisu'
4
- Bisu.run
4
+ Bisu.run(ARGV)
data/bisu.gemspec CHANGED
@@ -1,7 +1,9 @@
1
+ require_relative "lib/bisu/version"
2
+
1
3
  Gem::Specification.new do |s|
2
4
  s.name = 'bisu'
3
- s.version = '1.2.0'
4
- s.date = '2015-07-01'
5
+ s.version = Bisu::VERSION
6
+ s.date = Bisu::VERSION_UPDATED_AT
5
7
  s.summary = 'A localization automation service'
6
8
  s.description = 'Bisu manages your app iOS and Android localization files for you. No more copy+paste induced errors!'
7
9
  s.authors = ['joaoffcosta']
@@ -12,7 +12,7 @@ module Bisu
12
12
  end
13
13
  end
14
14
 
15
- def translate(language, locale, in_path, out_path)
15
+ def translate(language, locale, in_path, out_path, default_language=nil)
16
16
  unless @kb.has_language?(language)
17
17
  Logger.error("Unknown language #{language}")
18
18
  return false
@@ -24,7 +24,7 @@ module Bisu
24
24
  Logger.info("Translating #{in_path} to #{language} > #{out_path}...")
25
25
 
26
26
  in_file.each_line do |line|
27
- out_file.write(localize(line, language, locale))
27
+ out_file.write(localize(line, language, locale, default_language))
28
28
  end
29
29
 
30
30
  out_file.flush
@@ -49,7 +49,7 @@ module Bisu
49
49
  File.open(File.expand_path(file_name), method)
50
50
  end
51
51
 
52
- def localize(text, language, locale)
52
+ def localize(text, language, locale, default_language=nil)
53
53
  t = text
54
54
  t = t.gsub("$specialKLanguage$", language)
55
55
  t = t.gsub("$specialKLocale$", locale)
@@ -57,7 +57,7 @@ module Bisu
57
57
  t = t.gsub("$specialKComment2$", "Remember to CHANGE THE TEMPLATE and not this file!")
58
58
 
59
59
  if l = localization_params(t)
60
- if localized = @kb.localize(l[:loc_key], language)
60
+ if localized = @kb.localize(l[:loc_key], language) || @kb.localize(l[:loc_key], default_language)
61
61
  l[:loc_vars].each do |param, value|
62
62
  localized = localized.gsub("%{#{param}}", value)
63
63
  end
@@ -0,0 +1,4 @@
1
+ module Bisu
2
+ VERSION = '1.2.1'
3
+ VERSION_UPDATED_AT = '2015-07-31'
4
+ end
data/lib/bisu.rb CHANGED
@@ -2,18 +2,22 @@ require 'bisu/logger'
2
2
  require 'bisu/config'
3
3
  require 'bisu/knowledge_base'
4
4
  require 'bisu/translator'
5
+ require 'bisu/version'
6
+ require 'optparse'
5
7
 
6
8
  module Bisu
7
9
  extend self
8
10
 
9
- def run
11
+ def run(opts)
12
+ options = command_line_options(opts)
13
+
10
14
  if config = Bisu::Config.parse("translatable.yml")
11
15
  kbase = Bisu::GoogleDriveKB.new(config[:sheet_id], config[:keys_column])
12
16
  translator = Bisu::Translator.new(kbase, config[:type])
13
17
 
14
18
  config[:in].each do |in_path|
15
19
  config[:out].each do |out|
16
- localize(translator, out[:locale], out[:kb_language], in_path, out[:path] || config[:out_path])
20
+ localize(translator, out[:locale], out[:kb_language], options[:default_language], in_path, out[:path] || config[:out_path])
17
21
  end
18
22
  end
19
23
  end
@@ -23,7 +27,30 @@ module Bisu
23
27
 
24
28
  private
25
29
 
26
- def localize(translator, locale, language, in_path, out_path)
30
+ def command_line_options(options)
31
+ options = {}
32
+
33
+ opts_parser = OptionParser.new do |opts|
34
+ opts.on("-d LANGUAGE", "--default LANGUAGE", "Language to use when there is no available translation") do |language|
35
+ options[:default_language] = language
36
+ end
37
+
38
+ opts.on_tail("-h", "--help", "Show this message") do
39
+ puts opts
40
+ exit
41
+ end
42
+
43
+ opts.on_tail("-v", "--version", "Show version") do
44
+ puts Bisu::VERSION
45
+ exit
46
+ end
47
+ end
48
+
49
+ opts_parser.parse!(ARGV)
50
+ options
51
+ end
52
+
53
+ def localize(translator, locale, language, default_language, in_path, out_path)
27
54
  in_name = File.basename(in_path)
28
55
  out_name = in_name.gsub(/\.translatable$/, "")
29
56
 
@@ -34,7 +61,7 @@ module Bisu
34
61
 
35
62
  out_path = out_path % { locale: locale, android_locale: locale.gsub("-", "-r"), out_name: out_name }
36
63
 
37
- translator.translate(language, locale, in_path, out_path)
64
+ translator.translate(language, locale, in_path, out_path, default_language)
38
65
  end
39
66
 
40
67
  end
@@ -4,13 +4,15 @@ require 'bisu/translator'
4
4
  class BisuTranslatorTest < Minitest::Test
5
5
 
6
6
  def setup
7
- @lang = "portuguese"
8
- @locale = "portuguese"
7
+ @lang = "portuguese"
8
+ @incomplete_lang = "english"
9
+ @locale = "PT-PT"
9
10
 
10
11
  kb = Bisu::KnowledgeBase.new({
11
- languages: [@lang],
12
+ languages: [@lang, @missing_lang],
12
13
  keys: {
13
- "kRegularKey" => { @lang => "Não sabes nada João das Neves" },
14
+ "kRegularKey1" => { @lang => "Não sabes nada João das Neves", @incomplete_lang => "You know nothing John Snow" },
15
+ "kRegularKey2" => { @lang => "Não sabes isto João das Neves" },
14
16
  "kIOSKey" => { @lang => "Não sabes nada \"João das Neves\"" },
15
17
  "kAndroidKey1" => { @lang => "Não sabes nada 'João das Neves'" },
16
18
  "kAndroidKey2" => { @lang => "Não sabes nada João das Neves..." },
@@ -23,20 +25,31 @@ class BisuTranslatorTest < Minitest::Test
23
25
  @tios = Bisu::Translator.new(kb, :ios)
24
26
  @tand = Bisu::Translator.new(kb, :android)
25
27
  @tror = Bisu::Translator.new(kb, :ror)
28
+
29
+ Bisu::Logger.silent_mode = true
30
+ end
31
+
32
+ def teardown
33
+ Bisu::Logger.silent_mode = false
26
34
  end
27
35
 
28
36
  def test_simple_translate
37
+ orig0 = "0: $kUnknownKey$"
29
38
  orig1 = "1: $specialKComment1$"
30
39
  orig2 = "2: $specialKComment2$"
31
40
  orig3 = "3: $specialKLanguage$"
32
41
  orig4 = "4: $specialKLocale$"
33
- orig5 = "5: $kRegularKey$"
42
+ orig5 = "5: $kRegularKey1$"
34
43
  orig6_1 = "6.1: $k1ParameterKey$"
35
44
  orig6_2 = "6.2: $k1ParameterKey{name:%1$s}$"
36
45
  orig7_1 = "7.1: $k2ParametersKey$"
37
46
  orig7_2 = "7.2: $k2ParametersKey{percentage:%2$d, name:%1$s}$"
38
47
  orig7_3 = "7.3: $k2ParametersKey{name:%1$s, percentage:%2$d}$"
48
+ orig8_1 = "8.1: $kRegularKey1$"
49
+ orig8_2 = "8.2: $kRegularKey2$"
50
+ orig8_3 = "8.3: $kRegularKey2$"
39
51
 
52
+ loc0 = "0: $kUnknownKey$"
40
53
  loc1 = "1: This file was automatically generated based on a translation template."
41
54
  loc2 = "2: Remember to CHANGE THE TEMPLATE and not this file!"
42
55
  loc3 = "3: #{@lang}"
@@ -47,8 +60,12 @@ class BisuTranslatorTest < Minitest::Test
47
60
  loc7_1 = "7.1: Sabes %{percentage} por cento %{name}."
48
61
  loc7_2 = "7.2: Sabes %2$d por cento %1$s."
49
62
  loc7_3 = "7.3: Sabes %2$d por cento %1$s."
63
+ loc8_1 = "8.1: You know nothing John Snow"
64
+ loc8_2 = "8.2: Não sabes isto João das Neves"
65
+ loc8_3 = "8.3: $kRegularKey2$"
50
66
 
51
67
  [@tios, @tand, @tror].each do |translator|
68
+ assert_equal translator.send(:localize, orig0, @lang, @locale), loc0
52
69
  assert_equal translator.send(:localize, orig1, @lang, @locale), loc1
53
70
  assert_equal translator.send(:localize, orig2, @lang, @locale), loc2
54
71
  assert_equal translator.send(:localize, orig3, @lang, @locale), loc3
@@ -59,6 +76,10 @@ class BisuTranslatorTest < Minitest::Test
59
76
  assert_equal translator.send(:localize, orig7_1, @lang, @locale), loc7_1
60
77
  assert_equal translator.send(:localize, orig7_2, @lang, @locale), loc7_2
61
78
  assert_equal translator.send(:localize, orig7_3, @lang, @locale), loc7_3
79
+
80
+ assert_equal translator.send(:localize, orig8_1, @incomplete_lang, @locale, @lang), loc8_1
81
+ assert_equal translator.send(:localize, orig8_2, @incomplete_lang, @locale, @lang), loc8_2
82
+ assert_equal translator.send(:localize, orig8_3, @incomplete_lang, @locale ), loc8_3
62
83
  end
63
84
  end
64
85
 
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.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - joaoffcosta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-01 00:00:00.000000000 Z
11
+ date: 2015-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: safe_yaml
@@ -84,6 +84,7 @@ files:
84
84
  - lib/bisu/knowledge_base.rb
85
85
  - lib/bisu/logger.rb
86
86
  - lib/bisu/translator.rb
87
+ - lib/bisu/version.rb
87
88
  - test/support/sample_kb_public_info.html
88
89
  - test/support/sample_kb_public_sheet.html
89
90
  - test/support/sample_translatable.yml