auto_localize 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.travis.yml +14 -0
- data/CONTRIBUTORS +1 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/auto_localize.gemspec +23 -0
- data/lib/auto_localize.rb +5 -0
- data/lib/auto_localize/railtie.rb +13 -0
- data/lib/auto_localize/tasks/auto_localize.rake +28 -0
- data/lib/auto_localize/version.rb +3 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ab36d1aba5d59c940acc7106ff3d03cad3cd577b
|
4
|
+
data.tar.gz: 7ddb16c0189ea73e8f6fb7ef3850abc7cb606b84
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1e3cb5fb8c6f8927ebb1c8a4de9ffebfc36f9b7ba32f837684a3f9fd9712f76fd9377a24bddb50e4d47e41962d40fcc9daced6a69b461a427c0f4fb4a99636ad
|
7
|
+
data.tar.gz: 7f1157e59c52dca00522a3ab3ca2ea8f9709297710e33a41df8a638f897c399d10de332c99b0ac20b6f66f3bf274d6a6347dadefa0eda27b497ec15a5a84a97f
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CONTRIBUTORS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Caio Almeida
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Caio Almeida
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Auto Localize
|
2
|
+
|
3
|
+
[](https://travis-ci.org/caiosba/auto_localize)
|
4
|
+
[](http://badge.fury.io/rb/auto_localize)
|
5
|
+
|
6
|
+
|
7
|
+
Machine-translates an application, by generating a `config/locales/<target-language>.yml` file from a `config/locales/<source-language>.yml` using Bing to translate strings from the source file automatically. Existing translations are not overwritten by default.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add the `auto_localize` gem to your Gemfile:
|
12
|
+
|
13
|
+
gem "auto_localize"
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install auto_localize
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
After the gem is installed, you'll have a new rake task available. You need to pass the following arguments as environment variables:
|
26
|
+
|
27
|
+
* BING_ID: Bing id to be used (mandatory)
|
28
|
+
* BING_SECRET: Bing secret to be used (mandatory)
|
29
|
+
* TARGET_LANGUAGES: List of languages to which the source file should be translated, separated by commas (mandatory)
|
30
|
+
* SOURCE_LANGUAGE: Which source language to be used - assumes that a file at `config/locales/<source>.yml` exists (defaults to "en")
|
31
|
+
* FORCE: If true, existing translations are overwritten (defaults to `FALSE`)
|
32
|
+
|
33
|
+
Example:
|
34
|
+
|
35
|
+
`BING_ID=yourbingid BING_SECRET=yourbingsecret SOURCE_LANGUAGE=en TARGET_LANGUAGES=pt,es FORCE=true rake auto_localize`
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create new Pull Request
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'auto_localize/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'auto_localize'
|
8
|
+
spec.version = AutoLocalize::VERSION
|
9
|
+
spec.authors = ['Caio Almeida']
|
10
|
+
spec.email = ['caiosba@gmail.com']
|
11
|
+
spec.description = 'Machine-translates an application, by generating a config/locales/<target-language>.yml file from a config/locales/<source-language>.yml using Bing to translate strings from the source file automatically',
|
12
|
+
spec.summary = 'Machine-translates an application, by generating a config/locales/<target-language>.yml file from a config/locales/<source-language>.yml using Bing to translate strings from the source file automatically',
|
13
|
+
spec.homepage = 'https://github.com/caiosba/auto_localize'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
|
19
|
+
spec.add_development_dependency 'bundler'
|
20
|
+
spec.add_development_dependency 'gem-release'
|
21
|
+
|
22
|
+
spec.add_dependency 'bing_translator'
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'auto_localize'
|
2
|
+
require 'rails'
|
3
|
+
|
4
|
+
module AutoLocalize
|
5
|
+
TASKS = Dir[File.join(File.dirname(__FILE__), 'tasks/*.rake')]
|
6
|
+
|
7
|
+
class Railtie < Rails::Railtie
|
8
|
+
railtie_name :auto_localize
|
9
|
+
rake_tasks do
|
10
|
+
AutoLocalize::TASKS.each { |f| load f }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'bing_translator'
|
2
|
+
|
3
|
+
desc "Machine-translates an application, by generating a config/locales/<target-language>.yml file from a config/locales/<source-language>.yml using Bing to translate strings from the source file automatically"
|
4
|
+
task auto_localize: [:environment] do
|
5
|
+
translator = BingTranslator.new(ENV['BING_ID'], ENV['BING_SECRET'])
|
6
|
+
source = ENV['SOURCE_LANGUAGE'] || 'en'
|
7
|
+
|
8
|
+
ENV['TARGET_LANGUAGES'].split(',').each do |lang|
|
9
|
+
path = File.join(Rails.root, 'config', 'locales', "#{lang}.yml")
|
10
|
+
|
11
|
+
strings = File.exists?(path) ? YAML.load_file(path)[lang].keys : []
|
12
|
+
|
13
|
+
output = File.open(path, 'a+')
|
14
|
+
|
15
|
+
output.puts("#{lang}:") if strings.empty?
|
16
|
+
|
17
|
+
base = YAML.load_file("#{Rails.root}/config/locales/#{source}.yml")[source]
|
18
|
+
|
19
|
+
base.each do |key, value|
|
20
|
+
next if strings.include?(key) && !ENV['FORCE']
|
21
|
+
puts "Translating #{value} to #{lang}..."
|
22
|
+
translated = translator.translate(value, from: source, to: lang)
|
23
|
+
output.puts(" #{key}: \"#{translated}\"")
|
24
|
+
end
|
25
|
+
|
26
|
+
output.close
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: auto_localize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Caio Almeida
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-20 00:00:00.000000000 Z
|
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: '0'
|
20
|
+
type: :development
|
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: gem-release
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bing_translator
|
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
|
+
description: '["Machine-translates an application, by generating a config/locales/<target-language>.yml
|
56
|
+
file from a config/locales/<source-language>.yml using Bing to translate strings
|
57
|
+
from the source file automatically", "Machine-translates an application, by generating
|
58
|
+
a config/locales/<target-language>.yml file from a config/locales/<source-language>.yml
|
59
|
+
using Bing to translate strings from the source file automatically", "https://github.com/caiosba/auto_localize"]'
|
60
|
+
email:
|
61
|
+
- caiosba@gmail.com
|
62
|
+
executables: []
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- .gitignore
|
67
|
+
- .travis.yml
|
68
|
+
- CONTRIBUTORS
|
69
|
+
- Gemfile
|
70
|
+
- LICENSE.txt
|
71
|
+
- README.md
|
72
|
+
- auto_localize.gemspec
|
73
|
+
- lib/auto_localize.rb
|
74
|
+
- lib/auto_localize/railtie.rb
|
75
|
+
- lib/auto_localize/tasks/auto_localize.rake
|
76
|
+
- lib/auto_localize/version.rb
|
77
|
+
homepage: https://github.com/caiosba/auto_localize
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.0.14
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Machine-translates an application, by generating a config/locales/<target-language>.yml
|
101
|
+
file from a config/locales/<source-language>.yml using Bing to translate strings
|
102
|
+
from the source file automatically
|
103
|
+
test_files: []
|