babelphish 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -0
- data/LICENSE +20 -0
- data/Manifest.txt +16 -0
- data/PostInstall.txt +2 -0
- data/README.rdoc +47 -0
- data/Rakefile +33 -0
- data/bin/babelphish +18 -0
- data/lib/babelphish.rb +17 -0
- data/lib/babelphish/languages.rb +51 -0
- data/lib/babelphish/translator.rb +76 -0
- data/lib/tasks/babelphish.rake +14 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test/test_babelphish.rb +11 -0
- data/test/test_helper.rb +3 -0
- metadata +103 -0
data/History.txt
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Justin Ball
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
LICENSE
|
2
|
+
History.txt
|
3
|
+
Manifest.txt
|
4
|
+
PostInstall.txt
|
5
|
+
README.rdoc
|
6
|
+
Rakefile
|
7
|
+
bin/babelphish
|
8
|
+
lib/babelphish.rb
|
9
|
+
lib/babelphish/languages.rb
|
10
|
+
lib/babelphish/translator.rb
|
11
|
+
lib/tasks/babelphish.rake
|
12
|
+
script/console
|
13
|
+
script/destroy
|
14
|
+
script/generate
|
15
|
+
test/test_babelphish.rb
|
16
|
+
test/test_helper.rb
|
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
= babelphish
|
2
|
+
|
3
|
+
* http://github.com/jbasdf/babelphish
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
babelphish makes it simple to translate you yaml files into all the languages supported by Google Translate
|
8
|
+
|
9
|
+
== USAGE:
|
10
|
+
|
11
|
+
Translate the en.yml file into all supported languages:
|
12
|
+
babelphish -y ./my/locales/en.yml
|
13
|
+
|
14
|
+
Translate the en.yml file into all supported languages and overwrite other yml files:
|
15
|
+
babelphish -y ./my/locales/en.yml -o
|
16
|
+
|
17
|
+
== INSTALL:
|
18
|
+
|
19
|
+
ya2yaml is required to properly write utf8 yaml files. Install it first.
|
20
|
+
|
21
|
+
* sudo gem install ya2yaml
|
22
|
+
* sudo gem install babelphish
|
23
|
+
|
24
|
+
== LICENSE:
|
25
|
+
|
26
|
+
(The MIT License)
|
27
|
+
|
28
|
+
Copyright (c) 2009 Justin Ball
|
29
|
+
|
30
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
31
|
+
a copy of this software and associated documentation files (the
|
32
|
+
'Software'), to deal in the Software without restriction, including
|
33
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
34
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
35
|
+
permit persons to whom the Software is furnished to do so, subject to
|
36
|
+
the following conditions:
|
37
|
+
|
38
|
+
The above copyright notice and this permission notice shall be
|
39
|
+
included in all copies or substantial portions of the Software.
|
40
|
+
|
41
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
42
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
43
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
44
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
45
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
46
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
47
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
2
|
+
%w[rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
3
|
+
require File.dirname(__FILE__) + '/lib/babelphish'
|
4
|
+
|
5
|
+
# Generate all the Rake tasks
|
6
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
7
|
+
$hoe = Hoe.new('babelphish', Babelphish::VERSION) do |p|
|
8
|
+
p.developer('Justin Ball', 'justinball@gmail.com')
|
9
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
10
|
+
p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
11
|
+
p.rubyforge_name = 'babelphish'
|
12
|
+
p.url = "http://github.com/jbasdf/babelphish"
|
13
|
+
p.summary = "Translate with Google like a fule"
|
14
|
+
p.description = "Babelphish helps you make a quick translation of your application using Google Translate."
|
15
|
+
|
16
|
+
p.extra_deps = [
|
17
|
+
['ya2yaml','>= 0.26'],
|
18
|
+
]
|
19
|
+
p.extra_dev_deps = [
|
20
|
+
['newgem', ">= #{::Newgem::VERSION}"]
|
21
|
+
]
|
22
|
+
|
23
|
+
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
24
|
+
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
25
|
+
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
26
|
+
p.rsync_args = '-av --delete --ignore-errors'
|
27
|
+
end
|
28
|
+
|
29
|
+
require 'newgem/tasks' # load /tasks/*.rake
|
30
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
31
|
+
|
32
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
33
|
+
# task :default => [:spec, :features]
|
data/bin/babelphish
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'babelphish'
|
5
|
+
|
6
|
+
task = :babelphish
|
7
|
+
|
8
|
+
OptionParser.new do |opts|
|
9
|
+
opts.banner = "Usage: babelphish [options]"
|
10
|
+
opts.on('-y', '--yaml yml', "Required. Path to the yml file to be translated") {|yml| ENV['yml'] = yml }
|
11
|
+
opts.on('-o', '--overwrite', "Overwrite existing translations(default 'false')") { ENV['overwrite'] = 'yes' }
|
12
|
+
end.parse!
|
13
|
+
|
14
|
+
if Babelphish.load_tasks
|
15
|
+
Rake::Task[task].invoke
|
16
|
+
else
|
17
|
+
STDERR.puts "Can't find Rakefile. Are we in a Rails folder?"
|
18
|
+
end
|
data/lib/babelphish.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
module Babelphish
|
5
|
+
VERSION = '0.1.1'
|
6
|
+
|
7
|
+
def self.load_tasks
|
8
|
+
if File.exists?('Rakefile')
|
9
|
+
load 'Rakefile'
|
10
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks', '**/*.rake')].each { |rake| load rake }
|
11
|
+
return true
|
12
|
+
else
|
13
|
+
return false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Babelphish
|
2
|
+
module GoogleTranslate
|
3
|
+
|
4
|
+
ARABIC = "ar"
|
5
|
+
BULGARIAN = "bg"
|
6
|
+
CATALAN = "ca"
|
7
|
+
CHINESE = "zh"
|
8
|
+
CHINESE_SIMPLIFIED = "zh-CN"
|
9
|
+
CHINESE_TRADITIONAL = "zh-TW"
|
10
|
+
CROATIAN = "cr"
|
11
|
+
CZECH = "cs"
|
12
|
+
DANISH = "da"
|
13
|
+
DUTCH = "nl"
|
14
|
+
ENGLISH = "en"
|
15
|
+
FILIPINO = "tl"
|
16
|
+
FINNISH = "fi"
|
17
|
+
FRENCH = "fr"
|
18
|
+
GERMAN = "de"
|
19
|
+
GREEK = "el"
|
20
|
+
HEBREW = "iw"
|
21
|
+
HINDI = "hi"
|
22
|
+
INDONESIAN = "id"
|
23
|
+
ITALIAN = "it"
|
24
|
+
JAPANESE = "ja"
|
25
|
+
KOREAN = "ko"
|
26
|
+
LATVIAN = "lv"
|
27
|
+
LITHUANIAN = "lt"
|
28
|
+
NORWEGIAN = "no"
|
29
|
+
POLISH = "pl"
|
30
|
+
PORTUGESE = "pt"
|
31
|
+
ROMANIAN = "ro"
|
32
|
+
RUSSIAN = "ru"
|
33
|
+
SERBIAN = "sr"
|
34
|
+
SLOVAK = "sk"
|
35
|
+
SLOVENIAN = "sl"
|
36
|
+
SPANISH = "es"
|
37
|
+
SWEDISH = "sv"
|
38
|
+
UKRANIAN = "uk"
|
39
|
+
VIETNAMESE = "vi"
|
40
|
+
|
41
|
+
# LANGUAGES = [ARABIC, BULGARIAN, CATALAN, CHINESE, CHINESE_SIMPLIFIED,CHINESE_TRADITIONAL,
|
42
|
+
# CROATIAN, CZECH, DANISH, DUTCH, ENGLISH, FILIPINO, FRENCH, GERMAN, GREEK, HEBREW,
|
43
|
+
# ITALIAN, JAPANESE, KOREAN, LATVIAN, LITHUANIAN, NORWEGIAN, POLISH, PORTUGESE,
|
44
|
+
# ROMANIAN, RUSSIAN, SERBIAN, SLOVAK, SLOVENIAN, SPANISH, SWEDISH, UKRANIAN, VIETNAMESE]
|
45
|
+
|
46
|
+
LANGUAGES = [ARABIC, BULGARIAN, CATALAN, CHINESE, CHINESE_SIMPLIFIED,CHINESE_TRADITIONAL,
|
47
|
+
CZECH, DANISH, DUTCH, ENGLISH, FILIPINO, FRENCH, GERMAN, GREEK, HEBREW,
|
48
|
+
ITALIAN, JAPANESE, KOREAN, LATVIAN, LITHUANIAN, NORWEGIAN, POLISH, PORTUGESE,
|
49
|
+
ROMANIAN, RUSSIAN, SERBIAN, SLOVAK, SLOVENIAN, SPANISH, SWEDISH, UKRANIAN, VIETNAMESE]
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'ya2yaml'
|
3
|
+
require 'babelphish/languages'
|
4
|
+
require 'jcode'
|
5
|
+
|
6
|
+
require 'ruby-debug'
|
7
|
+
|
8
|
+
module Babelphish
|
9
|
+
module Translator
|
10
|
+
class << self
|
11
|
+
|
12
|
+
def translate_yaml(yml, overwrite = false)
|
13
|
+
$KCODE = 'UTF8'
|
14
|
+
language = File.basename(yml, ".yml")
|
15
|
+
if !Babelphish::GoogleTranslate::LANGUAGES.include?(language)
|
16
|
+
STDERR.puts "#{language} is not one of the available languages. Please choose a standard localized yml file. i.e. en.yml."
|
17
|
+
return
|
18
|
+
end
|
19
|
+
Babelphish::GoogleTranslate::LANGUAGES.each do |to|
|
20
|
+
translate_and_write_yml(yml, to, language, overwrite)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def translate_and_write_yml(yml, to, from, overwrite)
|
25
|
+
return if to == from
|
26
|
+
return unless File.exist?(yml)
|
27
|
+
translated_filename = File.join(File.dirname(yml), "#{to}.yml")
|
28
|
+
return if File.exist?(translated_filename) && !overwrite
|
29
|
+
translated_yml = YAML.load_file(yml)
|
30
|
+
translate_keys(translated_yml, to, from)
|
31
|
+
File.open(translated_filename, 'w') { |f| f.write(translated_yml.ya2yaml) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def translate_keys(translate_hash, to, from)
|
35
|
+
translate_hash.each_key do |key|
|
36
|
+
if translate_hash[key].is_a?(Hash)
|
37
|
+
translate_keys(translate_hash[key], to, from)
|
38
|
+
else
|
39
|
+
translate_hash[key] = translate(translate_hash[key], to, from)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# from: http://ruby.geraldbauer.ca/google-translation-api.html
|
45
|
+
def translate(text, to, from = 'en')
|
46
|
+
|
47
|
+
return if to == from
|
48
|
+
|
49
|
+
require 'cgi'
|
50
|
+
require 'json'
|
51
|
+
require 'net/http'
|
52
|
+
|
53
|
+
base = 'http://ajax.googleapis.com/ajax/services/language/translate'
|
54
|
+
# assemble query params
|
55
|
+
params = {
|
56
|
+
:langpair => "#{from}|#{to}",
|
57
|
+
:q => text,
|
58
|
+
:v => 1.0
|
59
|
+
}
|
60
|
+
query = params.map{ |k,v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&')
|
61
|
+
# send get request
|
62
|
+
response = Net::HTTP.get_response( URI.parse( "#{base}?#{query}" ) )
|
63
|
+
json = JSON.parse( response.body )
|
64
|
+
if json['responseStatus'] == 200
|
65
|
+
json['responseData']['translatedText']
|
66
|
+
else
|
67
|
+
puts response
|
68
|
+
puts to
|
69
|
+
puts from
|
70
|
+
raise StandardError, response['responseDetails']
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
desc "Translate files via Google Translate."
|
2
|
+
task :babelphish do
|
3
|
+
require 'babelphish/translator'
|
4
|
+
options={}
|
5
|
+
yml = ENV['yml']
|
6
|
+
overwrite = ENV['overwrite'] == 'yes'
|
7
|
+
|
8
|
+
if yml
|
9
|
+
Babelphish::Translator.translate_yaml(yml, overwrite)
|
10
|
+
else
|
11
|
+
STDERR.puts "Please specify the directory where your files live. i.e. babelphish -d ./my/locales"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/babelphish.rb'}"
|
9
|
+
puts "Loading babelphish gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: babelphish
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Justin Ball
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-19 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: ya2yaml
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0.26"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: newgem
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.4.1
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: hoe
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.8.0
|
44
|
+
version:
|
45
|
+
description: Babelphish helps you make a quick translation of your application using Google Translate.
|
46
|
+
email:
|
47
|
+
- justinball@gmail.com
|
48
|
+
executables:
|
49
|
+
- babelphish
|
50
|
+
extensions: []
|
51
|
+
|
52
|
+
extra_rdoc_files:
|
53
|
+
- History.txt
|
54
|
+
- Manifest.txt
|
55
|
+
- PostInstall.txt
|
56
|
+
- README.rdoc
|
57
|
+
files:
|
58
|
+
- LICENSE
|
59
|
+
- History.txt
|
60
|
+
- Manifest.txt
|
61
|
+
- PostInstall.txt
|
62
|
+
- README.rdoc
|
63
|
+
- Rakefile
|
64
|
+
- bin/babelphish
|
65
|
+
- lib/babelphish.rb
|
66
|
+
- lib/babelphish/languages.rb
|
67
|
+
- lib/babelphish/translator.rb
|
68
|
+
- lib/tasks/babelphish.rake
|
69
|
+
- script/console
|
70
|
+
- script/destroy
|
71
|
+
- script/generate
|
72
|
+
- test/test_babelphish.rb
|
73
|
+
- test/test_helper.rb
|
74
|
+
has_rdoc: true
|
75
|
+
homepage: http://github.com/jbasdf/babelphish
|
76
|
+
post_install_message: PostInstall.txt
|
77
|
+
rdoc_options:
|
78
|
+
- --main
|
79
|
+
- README.rdoc
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: "0"
|
87
|
+
version:
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: "0"
|
93
|
+
version:
|
94
|
+
requirements: []
|
95
|
+
|
96
|
+
rubyforge_project: babelphish
|
97
|
+
rubygems_version: 1.3.1
|
98
|
+
signing_key:
|
99
|
+
specification_version: 2
|
100
|
+
summary: Translate with Google like a fule
|
101
|
+
test_files:
|
102
|
+
- test/test_babelphish.rb
|
103
|
+
- test/test_helper.rb
|