mi_hermano 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mi_hermano.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2012 Rémi Prévost
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ ## Installation
2
+
3
+ Installing the gem is fairly easy. In your `Gemfile`:
4
+
5
+ ```ruby
6
+ gem "mi_hermano"
7
+ ```
8
+
9
+ ## Usage
10
+
11
+ To use Mi Hermano, you’ll have to create an empty Google Spreadsheet and use its *key* (found in its URL) when calling `setup`:
12
+
13
+ ```ruby
14
+ MiHermano.setup({
15
+ :username => "me@gmail.com",
16
+ :password => "my_secret_password",
17
+ :spreadsheet_key => "nxBFQGKpnzObbVyyIkGtajktMFAhDRGFiEdM66Vacmjz",
18
+ })
19
+ ```
20
+
21
+ After that, you can use `translate` to translate strings:
22
+
23
+ ```ruby
24
+ MiHermano.translate("Hello, my friends!", :en, :fr)
25
+ ```
26
+
27
+ ## Options
28
+
29
+ You can define a default source language and a default target language when initializing Mi Hermano. These settings will be used if you do not specify a source or a target when calling `translate`.
30
+
31
+ ```ruby
32
+ MiHermano.setup({
33
+ :username => "me@gmail.com",
34
+ :password => "my_secret_password",
35
+ :spreadsheet_key => "nxBFQGKpnzObbVyyIkGtajktMFAhDRGFiEdM66Vacmjz",
36
+ :default_source => :en,
37
+ :default_target => :es
38
+ })
39
+
40
+ MiHermano.translate("Hello, my friends!")
41
+ ```
42
+
43
+ ## License
44
+
45
+ Mi Hermano is © 2012 [Rémi Prévost](http://exomel.com) and may be freely distributed under the [MIT license](https://github.com/remiprev/mi_hermano/blob/master/LICENSE). See the `LICENSE` file.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/mi_hermano.rb ADDED
@@ -0,0 +1,33 @@
1
+ require "mi_hermano/version"
2
+ require "google_spreadsheet"
3
+
4
+ class MiHermano
5
+ def self.setup(attrs)
6
+ @@default = new(attrs)
7
+ end
8
+
9
+ def self.translate(text, source=nil, target=nil)
10
+ @@default.translate(text, source, target)
11
+ end
12
+
13
+ def initialize(attrs)
14
+ @spreadsheet_key = attrs[:spreadsheet_key]
15
+ @username = attrs[:username]
16
+ @password = attrs[:password]
17
+ @default_source = attrs[:default_source] || :en
18
+ @default_target = attrs[:default_target] || :fr
19
+
20
+ @session = GoogleSpreadsheet.login(@username, @password)
21
+ @worksheet = @session.spreadsheet_by_key(@spreadsheet_key).worksheets[0]
22
+ end
23
+
24
+ def translate(text, source=nil, target=nil)
25
+ source ||= @default_source
26
+ target ||= @default_target
27
+
28
+ @worksheet[1, 1] = '=GoogleTranslate("'+text+'"; "'+source.to_s+'"; "'+target.to_s+'")'
29
+ @worksheet.save
30
+ @worksheet.reload
31
+ @worksheet[1, 1]
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ class MiHermano
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "mi_hermano/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "mi_hermano"
7
+ s.version = MiHermano::VERSION
8
+ s.authors = ["Rémi Prévost"]
9
+ s.email = ["remi@exomel.com"]
10
+ s.homepage = "http://github.com/remiprev/mi_hermano"
11
+ s.summary = "Did you know that “fratello” means “brother” in Italian? Strange I know that. I took four years of Spanish."
12
+ s.description = "Mi Hermano translates strings using the Google Spreadsheets API (since the Translate API is no longer available)."
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_runtime_dependency "google-spreadsheet-ruby", "0.2.1"
20
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mi_hermano
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rémi Prévost
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-19 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: google-spreadsheet-ruby
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.2.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.2.1
30
+ description: Mi Hermano translates strings using the Google Spreadsheets API (since
31
+ the Translate API is no longer available).
32
+ email:
33
+ - remi@exomel.com
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - lib/mi_hermano.rb
44
+ - lib/mi_hermano/version.rb
45
+ - mi_hermano.gemspec
46
+ homepage: http://github.com/remiprev/mi_hermano
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 1.8.18
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Did you know that “fratello” means “brother” in Italian? Strange I know that.
70
+ I took four years of Spanish.
71
+ test_files: []
72
+ has_rdoc: