po_translation 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 008f6c834c4d129212eafd6cfc7daa53465aa55e
4
+ data.tar.gz: 983633ad4698eb033f34cd42a5fdf24a9caa9a3a
5
+ SHA512:
6
+ metadata.gz: 00a3cafd0364a483e2cc8c8bb37942e8d3e0f611d58629db3f6cfe9a7d6908e8f9219f9dc14cb6d3f1849a884a824e1feb05ab21753b37387891b7a7c9e4005d
7
+ data.tar.gz: 2653bffb17e8eaf9d7c8533e725c06235f17ac87b6c75d3df10aabe02aa2b86f65877dce947bd87daf63c4828397b1967675975cd7b1dc62f119a60ffb351f24
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in antigate_api.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Tam Vo
2
+
3
+ MIT License
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
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ # Po Translation
2
+
3
+ Translate your po file (normally used in Wordpress for translation) to
4
+ your languagge. Currently, in this version, it translated from en to vi,
5
+ if you need other languages, you must pull and fix at your own risk :-P.
6
+
7
+ Contact me if you need my help at vo.mita.ov at gmail
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'po_translation'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install po_translation
22
+
23
+ ## Usage
24
+
25
+ ```
26
+ Po::PoTranslation.translate(<po_path>, <output_path>)
27
+ ```
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
36
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,30 @@
1
+ require "mechanize"
2
+ require "active_support/core_ext"
3
+ # require File.expand_path(File.join(File.dirname(__FILE__), "mechanize_helper.rb"))
4
+ include Po::MechanizeHelper
5
+
6
+ module Po
7
+ module GoogleTranslator
8
+ def self.translate(str)
9
+ str = str.strip
10
+ return "" if str.blank?
11
+ params = {
12
+ "client" => "t",
13
+ "sl" => "en",
14
+ "tl" => "vi",
15
+ "hl" => "en",
16
+ "sc" => "2",
17
+ "ie" => "UTF-8",
18
+ "oe" => "UTF-8",
19
+ "oc" => "1",
20
+ "otf" => "2",
21
+ "ssel" => "3",
22
+ "tsel" => "6",
23
+ "q" => str
24
+ }
25
+ result = agent.get("http://translate.google.com.vn/translate_a/t", params)
26
+ json = JSON(result.body.match(/^\[(\[\[.*?\]\])/)[1])
27
+ json[0][0]
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,47 @@
1
+ module Po
2
+ module MechanizeHelper
3
+ def agent(force_new=false)
4
+ if force_new
5
+ @_agent = Mechanize.new
6
+ else
7
+ @_agent ||= Mechanize.new
8
+ end
9
+ @_agent.keep_alive = false
10
+ @_agent.open_timeout = 10
11
+ @_agent.read_timeout = 120
12
+ @_agent.user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:19.0) Gecko/20100101 Firefox/19.0'
13
+ @_agent.ssl_version = 'SSLv3'
14
+ # @_agent.set_proxy("localhost", 8888)
15
+ @_agent
16
+ end
17
+
18
+ def set_timeout(seconds)
19
+ @_agent.open_timeout = seconds
20
+ end
21
+
22
+ def html_page body
23
+ uri = URI 'http://example/'
24
+ Mechanize::Page.new uri, nil, body, 200, agent
25
+ end
26
+
27
+ def post_multipart(url, post_params, headers={})
28
+ post_params = post_params.with_indifferent_access
29
+ page = self.html_page <<-BODY
30
+ <form action="#{url}" enctype="multipart/form-data" method="POST">
31
+ </form>
32
+ BODY
33
+
34
+ page.forms.first.tap do |form|
35
+ post_params.each do |key, value|
36
+ if value.is_a?(IO)
37
+ ul = Mechanize::Form::FileUpload.new({'name' => key.to_s},::File.basename(value.path))
38
+ ul.file_data = value.read
39
+ form.file_uploads << ul
40
+ else
41
+ form.add_field! key.to_s, value
42
+ end
43
+ end
44
+ end.submit nil, headers
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module Po
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,44 @@
1
+ require "po/version"
2
+ require "po/mechanize_helper"
3
+ require "po/google_translator"
4
+
5
+ require 'get_pomo'
6
+ require "active_support/core_ext"
7
+ require "htmlentities"
8
+
9
+ module Po
10
+ class PoTranslation
11
+ class << self
12
+ def standarize(msgid, translated_str)
13
+ return translated_str if translated_str.blank?
14
+ translated_str = HTMLEntities.new.encode(translated_str.gsub("% s", "%s").gsub("\" ", "\"").gsub(/(\w) ([:"\.\?])"$\n/, "\1\2\"").strip)
15
+ if msgid[0] == msgid[0].upcase
16
+ translated_str = translated_str.capitalize
17
+ end
18
+ end
19
+
20
+ def translate(input_file, output_path=nil)
21
+ puts "--- #{input_file}"
22
+ translations = GetPomo::PoFile.parse(File.read(input_file))
23
+ translations.each_with_index do |translation, index|
24
+ next if translation.msgid.blank? || translation.msgid.match(/["']/)
25
+
26
+ msgstr = standarize(translation.msgid, GoogleTranslator.translate(translation.msgid))
27
+ next if msgstr.blank?
28
+
29
+ translation.msgstr = msgstr
30
+ puts translation.msgstr
31
+ if index % 20 == 0
32
+ puts index
33
+ sleep 2
34
+ end
35
+ end
36
+
37
+ unless output_path
38
+ output_path = File.dirname(input_file)
39
+ end
40
+ File.write(File.join(output_path, "#{File.basename(input_file, ".*")}-trans.po"), GetPomo::PoFile.to_text(translations))
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'po/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "po_translation"
8
+ gem.license = "MIT"
9
+ gem.version = Po::VERSION
10
+ gem.authors = ["Tam Vo"]
11
+ gem.email = ["vo.mita.ov@gmail.com"]
12
+ gem.description = %q{Using google translate to translate your po file}
13
+ gem.summary = %q{Using google translate to translate your po file}
14
+ gem.homepage = "http://github.com/tamvo/po_translation"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_dependency("mechanize")
22
+ gem.add_dependency("active_support")
23
+ gem.add_dependency("get_pomo")
24
+ gem.add_dependency("htmlentities")
25
+ end
26
+
@@ -0,0 +1,26 @@
1
+ # This file was generated by WPML
2
+ # WPML is a WordPress plugin that can turn any WordPress site into a full featured multilingual content management system.
3
+ # http://wpml.org
4
+ msgid ""
5
+ msgstr "Content-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: 8bit\nProject-Id-Version: \nPOT-Creation-Date: \nPO-Revision-Date: \nLast-Translator: \nLanguage-Team: \nMIME-Version: 1.0\n"
6
+
7
+ msgid "Wishlist"
8
+ msgstr "ưa thích"
9
+
10
+ msgid "Cannot add to the cart as product is Out of Stock!"
11
+ msgstr "Không thể thêm vào giỏ hàng như sản phẩm là hết hàng !"
12
+
13
+ msgid "Wishlist Page"
14
+ msgstr "Trang ưa thích"
15
+
16
+ msgid "Page contents: [yith_wcwl_wishlist]"
17
+ msgstr "Nội dung trang : [ yith_wcwl_wishlist ]"
18
+
19
+ msgid "General Settings"
20
+ msgstr "Thiết lập chung"
21
+
22
+ msgid "Styles"
23
+ msgstr "Phong cách"
24
+
25
+ msgid "Socials &amp; Share"
26
+ msgstr "Xã hội chủ &amp; chia sẻ"
@@ -0,0 +1,35 @@
1
+ # This file was generated by WPML
2
+ # WPML is a WordPress plugin that can turn any WordPress site into a full featured multilingual content management system.
3
+ # http://wpml.org
4
+ msgid ""
5
+ msgstr ""
6
+ "Content-Type: text/plain; charset=utf-8\n"
7
+ "Content-Transfer-Encoding: 8bit\n"
8
+ "Project-Id-Version: \n"
9
+ "POT-Creation-Date: \n"
10
+ "PO-Revision-Date: \n"
11
+ "Last-Translator: \n"
12
+ "Language-Team: \n"
13
+ "MIME-Version: 1.0\n"
14
+
15
+ msgid "Wishlist"
16
+ msgstr ""
17
+
18
+ msgid "Cannot add to the cart as product is Out of Stock!"
19
+ msgstr ""
20
+
21
+ msgid "Wishlist Page"
22
+ msgstr ""
23
+
24
+ msgid "Page contents: [yith_wcwl_wishlist]"
25
+ msgstr ""
26
+
27
+ msgid "General Settings"
28
+ msgstr ""
29
+
30
+ msgid "Styles"
31
+ msgstr ""
32
+
33
+ msgid "Socials &amp; Share"
34
+ msgstr ""
35
+
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: po_translation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tam Vo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mechanize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: active_support
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: get_pomo
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: htmlentities
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Using google translate to translate your po file
70
+ email:
71
+ - vo.mita.ov@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/po/google_translator.rb
82
+ - lib/po/mechanize_helper.rb
83
+ - lib/po/version.rb
84
+ - lib/po_translation.rb
85
+ - po_translation.gemspec
86
+ - sample-trans.po
87
+ - sample.po
88
+ homepage: http://github.com/tamvo/po_translation
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.1
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Using google translate to translate your po file
112
+ test_files: []