strings_xml_localizer 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1cd9018ea9ebf33a57e98dd4a7b6319f08e92537
4
- data.tar.gz: cdf804d306db2c4de66282939702b8dcd1c3c673
3
+ metadata.gz: b78b3a861dc400e9f357d196ce82afc596a679c3
4
+ data.tar.gz: 3aeb7ffbad0e56aa94f991cd68ef44fb460fac22
5
5
  SHA512:
6
- metadata.gz: 226d8842395169dca7b08f9808d5725150837182930abc20fa9f8302f54c7289d478ecd280cdf84b92f9ff803f96578915ade4205ab9d89ca1915c2df44ca8c8
7
- data.tar.gz: 257b8f500486dfc74f50cee93588d8199a80887af8a85cbaffe94b6894fb58c93f7f01d34df477762833d8c0c8fd785a737c7c7efcb7c258c66b5c03c2e41734
6
+ metadata.gz: e277cb84e01b0ca1c856144bf0335ca1e72dbf6a0815f873502ae9397d7b0a72d7c14a959281baafe6dad9ed9d54cd4aad21c83ffb7082f3677e386181e9b440
7
+ data.tar.gz: 12dc51a0c2428e1a7f272e744aba8854c0ff9f07511e6200ea11c62783d5d9fa109a7ec48c428e43c05aaaa2bd4140d4e430775e76f7d32b6668e3e1764535f2
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ script: rspec spec
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # StringsXmlLocalizer
1
+ # StringsXmlLocalizer [<img src="https://travis-ci.org/hoangphanea/strings_xml_localizer.svg" alt="Build Status" />](https://travis-ci.org/hoangphanea/strings_xml_localizer)
2
2
 
3
3
  A very simple gem to translate contents of a strings.xml file from one locale to another. It could be used for localize your app.
4
4
 
@@ -34,7 +34,7 @@ input = %Q(
34
34
  <string name="hi">Hello!</string>
35
35
  </resources>
36
36
  )
37
- StringsXmlLocalizer.string_to_string(input)
37
+ StringsXmlLocalizer.string_to_string(input, tl: :ja)
38
38
 
39
39
  ### OUTPUT
40
40
  # "\n<resources>\n <string name=\"hello\">こんにちは!</string>\n <string name=\"hi\">こんにちは!</string>\n</resources>\n"
@@ -62,6 +62,8 @@ StringsXmlLocalizer.file_to_file(from: 'input.xml', to: 'output.xml')
62
62
  ### Options:
63
63
  - `:from`: File to read from, default: `strings.xml`
64
64
  - `:to`: File to write to, default: `output.xml`
65
+ - `:sl`: Source language, default: `auto`
66
+ - `:tl`: Target language, default: `ja`
65
67
 
66
68
  ## Contributing
67
69
 
@@ -22,25 +22,25 @@ module StringsXmlLocalizer
22
22
  end
23
23
  end
24
24
 
25
- def self.string_to_string(src)
25
+ def self.string_to_string(src, options = {})
26
26
  in_xml = Ox.parse(src)
27
27
  output = Ox::Document.new(version: '1.0', encoding: 'utf-8')
28
28
 
29
29
  in_resources = in_xml.resources
30
- out_resources = generate_out_resources(in_resources)
30
+ out_resources = generate_out_resources(in_resources, options)
31
31
  output << out_resources
32
32
 
33
33
  Ox.dump(output)
34
34
  end
35
35
 
36
- def self.generate_out_resources(in_resources)
36
+ def self.generate_out_resources(in_resources, options = {})
37
37
  out_resources = Ox::Element.new('resources')
38
38
  i = 0
39
39
  while 1
40
40
  begin
41
41
  out = Ox::Element.new('string')
42
42
  out[:name] = in_resources.string(i).attributes[:name]
43
- out << translate_string_at(in_resources, i, :ja)
43
+ out << translate_string_at(in_resources, i, options[:sl], options[:tl])
44
44
  out_resources << out
45
45
  i += 1
46
46
  rescue
@@ -50,14 +50,16 @@ module StringsXmlLocalizer
50
50
  out_resources
51
51
  end
52
52
 
53
- def self.translate_string_at(resources, index, to)
54
- GoTranslator.translate(resources.string(index).text, to: to)
53
+ def self.translate_string_at(resources, index, from, to)
54
+ GoTranslator.translate(resources.string(index).text, from: from, to: to)
55
55
  end
56
56
 
57
57
  def self.default_options
58
58
  {
59
59
  from: DEFAULT_FROM,
60
- to: DEFAULT_TO
60
+ to: DEFAULT_TO,
61
+ sl: DEFAULT_SOURCE_LANGUAGE,
62
+ tl: DEFAULT_TARGET_LANGUANGE
61
63
  }
62
64
  end
63
65
  end
@@ -2,4 +2,6 @@ module StringsXmlLocalizer
2
2
  XML_HEADER = '<?xml version="1.0" encoding="utf-8"?>'
3
3
  DEFAULT_FROM = 'strings.xml'
4
4
  DEFAULT_TO = 'output.xml'
5
+ DEFAULT_SOURCE_LANGUAGE = :auto
6
+ DEFAULT_TARGET_LANGUANGE = :en
5
7
  end
@@ -1,3 +1,3 @@
1
1
  module StringsXmlLocalizer
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -15,6 +15,10 @@ describe StringsXmlLocalizer do
15
15
  let(:from) { 'from.xml' }
16
16
  let(:to) { 'to.xml' }
17
17
 
18
+ before do
19
+ allow(GoTranslator).to receive(:translate).and_return('こんにちは!')
20
+ end
21
+
18
22
  it 'has a version number' do
19
23
  expect(StringsXmlLocalizer::VERSION).not_to be nil
20
24
  end
@@ -28,7 +32,7 @@ describe StringsXmlLocalizer do
28
32
  end
29
33
 
30
34
  after do
31
- StringsXmlLocalizer.file_to_file(from: from, to: to)
35
+ StringsXmlLocalizer.file_to_file(from: from, to: to, tl: :ja)
32
36
  end
33
37
 
34
38
  it 'writes correct string' do
@@ -45,7 +49,7 @@ describe StringsXmlLocalizer do
45
49
  end
46
50
 
47
51
  after do
48
- StringsXmlLocalizer.string_to_file(src, to: to)
52
+ StringsXmlLocalizer.string_to_file(src, to: to, tl: :ja)
49
53
  end
50
54
 
51
55
  it 'writes correct string' do
@@ -60,13 +64,13 @@ describe StringsXmlLocalizer do
60
64
  end
61
65
 
62
66
  it 'returns correct string' do
63
- expect(StringsXmlLocalizer.file_to_string(from: from)).to eq expected_result
67
+ expect(StringsXmlLocalizer.file_to_string(from: from, tl: :ja)).to eq expected_result
64
68
  end
65
69
  end
66
70
 
67
71
  describe '.string_to_string' do
68
72
  it 'returns correct string' do
69
- expect(StringsXmlLocalizer.string_to_string(src)).to eq expected_result
73
+ expect(StringsXmlLocalizer.string_to_string(src, tl: :ja)).to eq expected_result
70
74
  end
71
75
  end
72
76
 
@@ -88,16 +92,17 @@ describe StringsXmlLocalizer do
88
92
  let(:resources) { double }
89
93
  let(:index) { 1 }
90
94
  let(:text) { 'text' }
95
+ let(:source) { :en }
91
96
  let(:target) { :ja }
92
97
  let(:result) { 'result' }
93
98
 
94
99
  before do
95
100
  expect(resources).to receive(:string).with(index).and_return(double(text: text))
96
- expect(GoTranslator).to receive(:translate).with(text, to: target).and_return(result)
101
+ expect(GoTranslator).to receive(:translate).with(text, from: source, to: target).and_return(result)
97
102
  end
98
103
 
99
104
  it 'returns correct result' do
100
- expect(StringsXmlLocalizer.translate_string_at(resources, index, target)).to eq result
105
+ expect(StringsXmlLocalizer.translate_string_at(resources, index, source, target)).to eq result
101
106
  end
102
107
  end
103
108
 
@@ -105,7 +110,9 @@ describe StringsXmlLocalizer do
105
110
  let(:expected_result) do
106
111
  {
107
112
  from: StringsXmlLocalizer::DEFAULT_FROM,
108
- to: StringsXmlLocalizer::DEFAULT_TO
113
+ to: StringsXmlLocalizer::DEFAULT_TO,
114
+ sl: StringsXmlLocalizer::DEFAULT_SOURCE_LANGUAGE,
115
+ tl: StringsXmlLocalizer::DEFAULT_TARGET_LANGUANGE
109
116
  }
110
117
  end
111
118
 
@@ -18,8 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.5"
22
- spec.add_development_dependency "rake"
23
21
  spec.add_development_dependency "rspec"
24
22
 
25
23
  spec.add_dependency "ox"
metadata CHANGED
@@ -1,43 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strings_xml_localizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hoang Phan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-19 00:00:00.000000000 Z
11
+ date: 2015-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.5'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.5'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
13
  - !ruby/object:Gem::Dependency
42
14
  name: rspec
43
15
  requirement: !ruby/object:Gem::Requirement
@@ -88,10 +60,10 @@ extensions: []
88
60
  extra_rdoc_files: []
89
61
  files:
90
62
  - ".gitignore"
63
+ - ".travis.yml"
91
64
  - Gemfile
92
65
  - LICENSE.txt
93
66
  - README.md
94
- - Rakefile
95
67
  - lib/strings_xml_localizer.rb
96
68
  - lib/strings_xml_localizer/constants.rb
97
69
  - lib/strings_xml_localizer/version.rb
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- require "bundler/gem_tasks"