autolang 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.md +6 -20
- data/VERSION +1 -1
- data/autolang.gemspec +4 -2
- data/bin/autolang +30 -0
- data/lib/autolang.rb +5 -6
- data/spec/autolang_spec.rb +9 -17
- metadata +8 -8
- data/lib/tasks/autolang.rake +0 -33
data/Readme.md
CHANGED
@@ -1,33 +1,19 @@
|
|
1
1
|
Autolang
|
2
2
|
========
|
3
3
|
|
4
|
-
Goal
|
5
|
-
====
|
6
4
|
- Kick-start your translation!
|
7
5
|
- Translate all your Gettext - msgids to another language using google-translate.
|
8
|
-
- Provide a simple interface for other translation tasks
|
9
|
-
|
10
6
|
|
11
|
-
|
12
|
-
|
7
|
+
Usage
|
8
|
+
=====
|
13
9
|
|
14
10
|
gem install autolang
|
15
11
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
OR as Rails plugin
|
20
|
-
rails plugin install git://github.com/grosser/autolang.git
|
21
|
-
|
22
|
-
OR copy rake tasks
|
23
|
-
curl https://github.com/grosser/autolang/raw/master/lib/tasks/autolang.rake > lib/tasks/autolang.rake
|
24
|
-
|
25
|
-
Usage
|
26
|
-
=====
|
27
|
-
Translate your pot file to any other language:
|
12
|
+
autolang /path/to/app.pot <language-code>
|
13
|
+
autolang /path/to/app.pot es
|
28
14
|
|
29
|
-
|
30
|
-
|
15
|
+
language-code are 2 letter [ISO 639](http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) codes<br/>
|
16
|
+
if you have no .pot file, use gettext and updatepo first (google helps...)
|
31
17
|
|
32
18
|
Translation examples
|
33
19
|
====================
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/autolang.gemspec
CHANGED
@@ -5,12 +5,14 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{autolang}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Chris Blackburn", "Michael Grosser"]
|
12
12
|
s.date = %q{2011-03-19}
|
13
|
+
s.default_executable = %q{autolang}
|
13
14
|
s.email = %q{michael@grosser.it}
|
15
|
+
s.executables = ["autolang"]
|
14
16
|
s.files = [
|
15
17
|
"Gemfile",
|
16
18
|
"Gemfile.lock",
|
@@ -18,8 +20,8 @@ Gem::Specification.new do |s|
|
|
18
20
|
"Readme.md",
|
19
21
|
"VERSION",
|
20
22
|
"autolang.gemspec",
|
23
|
+
"bin/autolang",
|
21
24
|
"lib/autolang.rb",
|
22
|
-
"lib/tasks/autolang.rake",
|
23
25
|
"spec/autolang_spec.rb"
|
24
26
|
]
|
25
27
|
s.homepage = %q{http://github.com/grosser/autolang}
|
data/bin/autolang
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
|
6
|
+
require 'autolang'
|
7
|
+
|
8
|
+
OptionParser.new do |opts|
|
9
|
+
opts.banner = <<BANNER
|
10
|
+
|
11
|
+
Usage:
|
12
|
+
autolang /path/to/app.pot <language-code>
|
13
|
+
autolang /path/to/app.pot es
|
14
|
+
|
15
|
+
language-code are 2 letter ISO 639 codes
|
16
|
+
if you do not have a pot file, use gettext and updatepo first (google helps...)
|
17
|
+
|
18
|
+
|
19
|
+
Options:
|
20
|
+
BANNER
|
21
|
+
opts.on("-h", "--help","Show this.") { puts opts; exit }
|
22
|
+
opts.on('-v', '--version','Show Version'){ puts Autolang::VERSION; exit}
|
23
|
+
end.parse!
|
24
|
+
|
25
|
+
if ARGV.size < 2 or not File.exist?(ARGV.first)
|
26
|
+
puts "Usage instructions: autolang --help"
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
|
30
|
+
Autolang.translate_into_new_language(*ARGV)
|
data/lib/autolang.rb
CHANGED
@@ -26,17 +26,17 @@ class Autolang
|
|
26
26
|
`msginit -i #{pot_file} -o #{po_file} -l #{language} --no-translator`
|
27
27
|
end
|
28
28
|
|
29
|
-
lines = translate_po_file_content(File.readlines(po_file))
|
29
|
+
lines = translate_po_file_content(File.readlines(po_file), language)
|
30
30
|
File.open(po_file, "w+"){|f| f.write(lines*"\n") }
|
31
31
|
end
|
32
32
|
|
33
|
-
def self.translate_po_file_content(lines)
|
33
|
+
def self.translate_po_file_content(lines, language)
|
34
34
|
msgstr = ""
|
35
35
|
puts "Translating..."
|
36
36
|
lines.map do |line|
|
37
37
|
#read string to translate
|
38
38
|
if msgid = extract_msgid(line)
|
39
|
-
msgstr = translate(msgid)
|
39
|
+
msgstr = translate(msgid, language)
|
40
40
|
|
41
41
|
puts msgid
|
42
42
|
puts msgstr
|
@@ -51,11 +51,10 @@ class Autolang
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
def self.translate(text)
|
54
|
+
def self.translate(text, language)
|
55
55
|
e = TranslationEscaper.new(text)
|
56
|
-
|
57
56
|
@translator = Translate::RTranslate.new unless @translator
|
58
|
-
e.unescape @translator.translate(e.escaped, :from => 'ENGLISH', :to =>
|
57
|
+
e.unescape @translator.translate(e.escaped, :from => 'ENGLISH', :to => language, :userip => '127.0.0.1')
|
59
58
|
end
|
60
59
|
|
61
60
|
# protects text from evil translation robots
|
data/spec/autolang_spec.rb
CHANGED
@@ -5,8 +5,6 @@ require 'mocha'
|
|
5
5
|
$LOAD_PATH.unshift 'lib'
|
6
6
|
require 'autolang'
|
7
7
|
|
8
|
-
load 'lib/tasks/autolang.rake'
|
9
|
-
|
10
8
|
describe Autolang do
|
11
9
|
it "has a VERSION" do
|
12
10
|
Autolang::VERSION.should =~ /^\d+\.\d+\.\d+$/
|
@@ -27,32 +25,28 @@ describe Autolang do
|
|
27
25
|
end
|
28
26
|
|
29
27
|
describe :translate do
|
30
|
-
before do
|
31
|
-
ENV['L']='es'
|
32
|
-
end
|
33
|
-
|
34
28
|
it "translates a word" do
|
35
|
-
Autolang.translate('hello').should == 'hola'
|
29
|
+
Autolang.translate('hello', 'es').should == 'hola'
|
36
30
|
end
|
37
31
|
|
38
32
|
it "converts html entities" do
|
39
|
-
Autolang.translate('sales & tax').should == 'impuesto sobre ventas y'
|
33
|
+
Autolang.translate('sales & tax', 'es').should == 'impuesto sobre ventas y'
|
40
34
|
end
|
41
35
|
|
42
36
|
it "converts html entities back" do
|
43
|
-
Autolang.translate('"&&&"').should == '"Andandand"'
|
37
|
+
Autolang.translate('"&&&"', 'es').should == '"Andandand"'
|
44
38
|
end
|
45
39
|
|
46
40
|
it "translates with strange signs" do
|
47
|
-
Autolang.translate('production').should == 'producción'
|
41
|
+
Autolang.translate('production', 'es').should == 'producción'
|
48
42
|
end
|
49
43
|
|
50
44
|
it "translates with | " do
|
51
|
-
Autolang.translate('Auto|hello').should == 'hola'
|
45
|
+
Autolang.translate('Auto|hello', 'es').should == 'hola'
|
52
46
|
end
|
53
47
|
|
54
48
|
it "translates with %{}" do
|
55
|
-
Autolang.translate('hello %{name}').should == 'hola %{name}'
|
49
|
+
Autolang.translate('hello %{name}', 'es').should == 'hola %{name}'
|
56
50
|
end
|
57
51
|
end
|
58
52
|
end
|
@@ -92,15 +86,13 @@ describe 'translate pot file' do
|
|
92
86
|
after &delete
|
93
87
|
|
94
88
|
before do
|
95
|
-
pot = 'spec/fixtures/xxx.pot'
|
96
|
-
File.open(pot, 'w'){|f| f.write(%Q{msgid "hello"\nmsgstr ""}) }
|
97
|
-
ENV['POT_FILE'] = pot
|
98
|
-
ENV['L'] = 'de'
|
89
|
+
@pot = 'spec/fixtures/xxx.pot'
|
90
|
+
File.open(@pot, 'w'){|f| f.write(%Q{msgid "hello"\nmsgstr ""}) }
|
99
91
|
@po = 'spec/fixtures/de/de.po'
|
100
92
|
end
|
101
93
|
|
102
94
|
it "translates all msgids" do
|
103
|
-
|
95
|
+
`./bin/autolang #{@pot} de`
|
104
96
|
File.read(@po).should include(%Q{msgid "hello"\nmsgstr "hallo"})
|
105
97
|
end
|
106
98
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autolang
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Chris Blackburn
|
@@ -17,7 +17,7 @@ bindir: bin
|
|
17
17
|
cert_chain: []
|
18
18
|
|
19
19
|
date: 2011-03-19 00:00:00 +01:00
|
20
|
-
default_executable:
|
20
|
+
default_executable: autolang
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
23
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
@@ -49,8 +49,8 @@ dependencies:
|
|
49
49
|
prerelease: false
|
50
50
|
description:
|
51
51
|
email: michael@grosser.it
|
52
|
-
executables:
|
53
|
-
|
52
|
+
executables:
|
53
|
+
- autolang
|
54
54
|
extensions: []
|
55
55
|
|
56
56
|
extra_rdoc_files: []
|
@@ -62,8 +62,8 @@ files:
|
|
62
62
|
- Readme.md
|
63
63
|
- VERSION
|
64
64
|
- autolang.gemspec
|
65
|
+
- bin/autolang
|
65
66
|
- lib/autolang.rb
|
66
|
-
- lib/tasks/autolang.rake
|
67
67
|
- spec/autolang_spec.rb
|
68
68
|
has_rdoc: true
|
69
69
|
homepage: http://github.com/grosser/autolang
|
data/lib/tasks/autolang.rake
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
# Copyright © 2008 Chris Blackburn <cblackburn : at : cbciweb.com>
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
# a copy of this software and associated documentation files (the
|
7
|
-
# “Software”), to deal in the Software without restriction, including
|
8
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
# the following conditions:
|
12
|
-
#
|
13
|
-
# The above copyright notice and this permission notice shall be
|
14
|
-
# included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
require 'autolang'
|
17
|
-
|
18
|
-
namespace :autolang do
|
19
|
-
desc "Translate strings into a new language."
|
20
|
-
task :translate do
|
21
|
-
if !ENV['L'] or !ENV['POT_FILE']
|
22
|
-
puts "Usage: L=language_code POT_FILE=po/my_app.pot rake autolang:translate"
|
23
|
-
puts " language_codes are 2 letter ISO 639 codes "
|
24
|
-
puts " if you do not have a pot file, use gettext and updatepo first (google helps...)"
|
25
|
-
puts ""
|
26
|
-
puts "Example: Translate all msgids into Spanish."
|
27
|
-
puts " L=es POT_FILE=po/my_app.pot rake autolang:translate"
|
28
|
-
exit
|
29
|
-
end
|
30
|
-
|
31
|
-
Autolang.translate_into_new_language(ENV['POT_FILE'], ENV['L'])
|
32
|
-
end
|
33
|
-
end
|