babel_bot 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +12 -0
- data/README.md +90 -0
- data/Rakefile +17 -0
- data/babel_bot.gemspec +48 -0
- data/bin/babel-bot +13 -0
- data/bin/console +18 -0
- data/bin/setup +15 -0
- data/doc/google-doc-id.png +0 -0
- data/examples/config.json +8 -0
- data/lib/babel_bot.rb +16 -0
- data/lib/babel_bot/cli.rb +38 -0
- data/lib/babel_bot/csv_loader.rb +96 -0
- data/lib/babel_bot/runner.rb +21 -0
- data/lib/babel_bot/twine_generator.rb +63 -0
- data/lib/babel_bot/version.rb +10 -0
- metadata +206 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8db6aaadeef45cd839810903e94ed2adaaf70e85
|
4
|
+
data.tar.gz: f6bed216769e98b43d7607974ba05a6138218d01
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f37ebdaa51b134b80290163397d4cdc4fe29310bbcc091cf571d92d020516d4a218b10830c6c12ed60c1b9cd2b469dc9e718d21b53ba9d60b5cbfab99afbc3b4
|
7
|
+
data.tar.gz: 2de6006165f9d8048663f3e28af411cbde57857bbcdea00ccb5846dbe9758bf572c7ff7b5e6d7e20bbabf4bcd9f18e1f0253ae2838ebda965960380f6e6625f8
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.0
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2016, salesforce.com, inc.
|
3
|
+
# All rights reserved.
|
4
|
+
# Licensed under the BSD 3-Clause license.
|
5
|
+
# For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
6
|
+
#
|
7
|
+
|
8
|
+
source 'https://rubygems.org'
|
9
|
+
|
10
|
+
# Specify your gem's dependencies in babel_bot.gemspec
|
11
|
+
gemspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
Copyright (c) 2016, Salesforce.com, Inc.
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
5
|
+
|
6
|
+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
7
|
+
|
8
|
+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
9
|
+
|
10
|
+
* Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
11
|
+
|
12
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# Babel Bot
|
2
|
+
|
3
|
+
Babel Bot facilitates the collaboration between developers and content writers to provide application ready content across languages. Developers and content providers share a Google spreadsheet where new keys can quickly be added and translations can be quickly modified. A single executable can be run to pull down the content and convert it into the application required string file format.
|
4
|
+
|
5
|
+
Babel Bot relies heavily on the fantastic [twine](https://github.com/mobiata/twine) gem. However, instead of sharing a Twine formatted file across applications, a Google spreadsheet is used for easier collaboration across departments and companies.
|
6
|
+
|
7
|
+
Babel Bot has only been tested on iOS and Android projects, but should work with the other formats supported by the twine gem.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem "babel_bot"
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
## Google Drive API Configuration
|
22
|
+
|
23
|
+
In order to fetch the Google spreadsheet content, a project will need to be enabled for API access.
|
24
|
+
|
25
|
+
- Head to the [Google Developers Console](https://console.developers.google.com)
|
26
|
+
- Create a new project
|
27
|
+
- Navigate to the "Credentials" section and create credentials.
|
28
|
+
- Proceed through the consent screen and select "Web Application" as the application type
|
29
|
+
- When prompted, select "OAuth client ID" as the credential type
|
30
|
+
- When asked to provided "Redirect URIs", enter "http://localhost:9292/"
|
31
|
+
- Download the credentials file
|
32
|
+
- Place this file in your project home directory and name it `client_secrets.json`
|
33
|
+
- It is recommended to change the permissions on `client_secrets.json` to readonly for all users
|
34
|
+
- Navigate to "Google Drive API" and enable the API
|
35
|
+
|
36
|
+
## Create Your Project Config
|
37
|
+
|
38
|
+
Each project should have a configuration checked in to be shared among the developers. [An example config can be found in the examples folder.](examples/config.json). Below is a brief explanation of each configuration param
|
39
|
+
|
40
|
+
- `googleAppName` - The application name of the Google Project created above.
|
41
|
+
- `fileId` - The Google doc ID. This can be found in the document URI between the `/d/` and `/edit` path components
|
42
|
+
|
43
|
+
![alt tag](doc/google-doc-id.png)
|
44
|
+
|
45
|
+
- `apiCachePath` - Path to cache Google Drive discovery API.
|
46
|
+
- `credentialsCachePath` - Path to cache OAuth2 tokens
|
47
|
+
- `twineFilePath` - Path to store intermediate Twine file
|
48
|
+
- `projectLocalesPath` - Project path to directory containing locale specific subdirectories. For iOS, this is the directory containing the `LOCALE.lproj` directories. For Android, this is the directory containing the `values-LOCALE` directories
|
49
|
+
|
50
|
+
Make sure all paths specified already exist.
|
51
|
+
|
52
|
+
## Generating Strings
|
53
|
+
|
54
|
+
With your configuration in place, run
|
55
|
+
|
56
|
+
$ bundle exec babel-bot generate-strings PATH_TO_CONFIG
|
57
|
+
|
58
|
+
If you are using Bundler, you can run using `bundle exec` to eliminate the JSON version warnings caused by the Google API client.
|
59
|
+
|
60
|
+
## Google Spreadsheet Format
|
61
|
+
|
62
|
+
There are three column headers required:
|
63
|
+
|
64
|
+
- `Key` - This is the key referenced in code
|
65
|
+
- `Comment` - A comment providing some context to the key
|
66
|
+
- `en` - The development locale. Currently, this is hardcoded to `en`, but could be configurable in later versions
|
67
|
+
|
68
|
+
Additional headers can be added and will be treated as new locales. In [this sample](https://docs.google.com/spreadsheets/d/1t-_CUS5A35gbRvFd3mjfTyPEXF0-zcMrqdcFPVFS-fo/edit?usp=sharing), string files will be generated for English, French and German.
|
69
|
+
|
70
|
+
## Known Issues
|
71
|
+
|
72
|
+
### I am being asked to authenticate every time the executable runs
|
73
|
+
|
74
|
+
Google's OAuth API only returns a refresh token the first time you authenticate and create a connected app. If you lose your cached oauth tokens, you will need to revoke and regrant application access. Instructions to do so can be found [here](http://stackoverflow.com/questions/10827920/google-oauth-refresh-token-is-not-being-received)
|
75
|
+
|
76
|
+
## Development
|
77
|
+
|
78
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
79
|
+
|
80
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
81
|
+
|
82
|
+
## Contributing
|
83
|
+
|
84
|
+
Bug reports and pull requests are welcome via GitHub. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
85
|
+
|
86
|
+
|
87
|
+
## License
|
88
|
+
|
89
|
+
The gem is available as open source under the terms of the [BSD-3-Clause](./LICENSE.txt).
|
90
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2016, salesforce.com, inc.
|
3
|
+
# All rights reserved.
|
4
|
+
# Licensed under the BSD 3-Clause license.
|
5
|
+
# For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
6
|
+
#
|
7
|
+
|
8
|
+
require "bundler/gem_tasks"
|
9
|
+
require "rake/testtask"
|
10
|
+
|
11
|
+
Rake::TestTask.new(:test) do |t|
|
12
|
+
t.libs << "test"
|
13
|
+
t.libs << "lib"
|
14
|
+
t.test_files = FileList['test/**/*_test.rb']
|
15
|
+
end
|
16
|
+
|
17
|
+
task :default => :test
|
data/babel_bot.gemspec
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2016, salesforce.com, inc.
|
5
|
+
# All rights reserved.
|
6
|
+
# Licensed under the BSD 3-Clause license.
|
7
|
+
# For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
8
|
+
#
|
9
|
+
|
10
|
+
lib = File.expand_path('../lib', __FILE__)
|
11
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
12
|
+
require 'babel_bot/version'
|
13
|
+
|
14
|
+
Gem::Specification.new do |spec|
|
15
|
+
spec.name = "babel_bot"
|
16
|
+
spec.version = BabelBot::VERSION
|
17
|
+
spec.authors = ["Nick Changnon"]
|
18
|
+
spec.email = ["nchangnon@salesforce.com"]
|
19
|
+
|
20
|
+
spec.summary = %q{gem to generate localization string files from a Google Spreadsheet}
|
21
|
+
spec.homepage = "https://github.com/salesforce/BabelBot"
|
22
|
+
spec.license = "BSD-3-Clause"
|
23
|
+
|
24
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
25
|
+
# delete this section to allow pushing this gem to any host.
|
26
|
+
# if spec.respond_to?(:metadata)
|
27
|
+
# spec.metadata['allowed_push_host'] = ""
|
28
|
+
# else
|
29
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
30
|
+
# end
|
31
|
+
|
32
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
33
|
+
spec.bindir = "bin"
|
34
|
+
spec.executables = ["babel-bot"]
|
35
|
+
spec.require_paths = ["lib"]
|
36
|
+
|
37
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
38
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
39
|
+
spec.add_development_dependency "minitest"
|
40
|
+
spec.add_development_dependency "pry-byebug"
|
41
|
+
spec.add_development_dependency "minitest-reporters"
|
42
|
+
spec.add_development_dependency "mocha"
|
43
|
+
spec.add_development_dependency "activesupport", "~> 4.2.4"
|
44
|
+
|
45
|
+
spec.add_runtime_dependency "google-api-client", "~> 0.8.6"
|
46
|
+
spec.add_runtime_dependency "slop", "~> 3.6.0"
|
47
|
+
spec.add_runtime_dependency "twine", "~> 0.6.0"
|
48
|
+
end
|
data/bin/babel-bot
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2016, salesforce.com, inc.
|
5
|
+
# All rights reserved.
|
6
|
+
# Licensed under the BSD 3-Clause license.
|
7
|
+
# For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
8
|
+
#
|
9
|
+
|
10
|
+
require "bundler/setup"
|
11
|
+
require "babel_bot"
|
12
|
+
|
13
|
+
BabelBot::CLI.run
|
data/bin/console
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2016, salesforce.com, inc.
|
5
|
+
# All rights reserved.
|
6
|
+
# Licensed under the BSD 3-Clause license.
|
7
|
+
# For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
8
|
+
#
|
9
|
+
|
10
|
+
require "bundler/setup"
|
11
|
+
require "babel_bot"
|
12
|
+
|
13
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
14
|
+
# with your gem easier. You can also use a different console, if you like.
|
15
|
+
|
16
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
17
|
+
require "pry"
|
18
|
+
Pry.start
|
data/bin/setup
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2016, salesforce.com, inc.
|
5
|
+
# All rights reserved.
|
6
|
+
# Licensed under the BSD 3-Clause license.
|
7
|
+
# For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
8
|
+
#
|
9
|
+
|
10
|
+
set -euo pipefail
|
11
|
+
IFS=$'\n\t'
|
12
|
+
|
13
|
+
bundle install
|
14
|
+
|
15
|
+
# Do any other automated setup that you need to do here
|
Binary file
|
@@ -0,0 +1,8 @@
|
|
1
|
+
{
|
2
|
+
"googleAppName" : "BabelBot",
|
3
|
+
"fileId" : "xxxxSFU6l6Eovktv5IQyqJK_MiJjvkcoMj0plOHoxxxx",
|
4
|
+
"apiCachePath" : "tmp/drive.cache",
|
5
|
+
"credentialsCachePath" : "tmp/oauth2.json",
|
6
|
+
"twineFilePath" : "tmp/out.twine",
|
7
|
+
"projectLocalesPath" : "/path/to/project/locales/directory"
|
8
|
+
}
|
data/lib/babel_bot.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2016, salesforce.com, inc.
|
3
|
+
# All rights reserved.
|
4
|
+
# Licensed under the BSD 3-Clause license.
|
5
|
+
# For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
6
|
+
#
|
7
|
+
|
8
|
+
module BabelBot
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
require "babel_bot/cli"
|
13
|
+
require "babel_bot/csv_loader"
|
14
|
+
require "babel_bot/runner"
|
15
|
+
require "babel_bot/twine_generator"
|
16
|
+
require "babel_bot/version"
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2016, salesforce.com, inc.
|
3
|
+
# All rights reserved.
|
4
|
+
# Licensed under the BSD 3-Clause license.
|
5
|
+
# For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
6
|
+
#
|
7
|
+
|
8
|
+
require "slop"
|
9
|
+
|
10
|
+
module BabelBot
|
11
|
+
class CLI
|
12
|
+
def self.run
|
13
|
+
@opts = Slop.parse(help: true) do
|
14
|
+
on '-v', 'Print the version' do
|
15
|
+
puts "Version #{BabelBot::VERSION}"
|
16
|
+
end
|
17
|
+
|
18
|
+
command "generate-strings" do
|
19
|
+
banner "Usage: babel-bot generate-strings CONFIG_PATH"
|
20
|
+
run do |opts, args|
|
21
|
+
if args[0]
|
22
|
+
config = BabelBot::CLI.load_config(args[0])
|
23
|
+
BabelBot::Runner.new(config).generate_strings
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
puts @opts
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.load_config(config_path)
|
35
|
+
JSON.load(File.open(config_path))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2016, salesforce.com, inc.
|
3
|
+
# All rights reserved.
|
4
|
+
# Licensed under the BSD 3-Clause license.
|
5
|
+
# For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
6
|
+
#
|
7
|
+
|
8
|
+
require "google/api_client"
|
9
|
+
require "google/api_client/client_secrets"
|
10
|
+
require "google/api_client/auth/installed_app"
|
11
|
+
require "google/api_client/auth/file_storage"
|
12
|
+
require "csv"
|
13
|
+
|
14
|
+
module BabelBot
|
15
|
+
class CSVLoader
|
16
|
+
|
17
|
+
API_VERSION = "v2"
|
18
|
+
|
19
|
+
def initialize(config={})
|
20
|
+
@config = config;
|
21
|
+
end
|
22
|
+
|
23
|
+
def load
|
24
|
+
authorize_client
|
25
|
+
load_csv
|
26
|
+
end
|
27
|
+
|
28
|
+
def authorize_client
|
29
|
+
if cached_auth_exists?
|
30
|
+
client.authorization = file_storage.authorization
|
31
|
+
else
|
32
|
+
client.authorization = app_flow.authorize(file_storage)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def drive
|
37
|
+
return @drive if @drive
|
38
|
+
|
39
|
+
api_cache_file_path = @config["apiCachePath"]
|
40
|
+
if File.exists?(api_cache_file_path)
|
41
|
+
File.open(api_cache_file_path) do |file|
|
42
|
+
@drive = Marshal.load(file)
|
43
|
+
end
|
44
|
+
else
|
45
|
+
@drive = client.discovered_api("drive", API_VERSION)
|
46
|
+
File.open(api_cache_file_path, "w") do |file|
|
47
|
+
Marshal.dump(@drive, file)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
@drive
|
52
|
+
end
|
53
|
+
|
54
|
+
def load_csv
|
55
|
+
file_metadata_result = client.execute!(
|
56
|
+
api_method: drive.files.get,
|
57
|
+
parameters: { "fileId" => @config["fileId"] }
|
58
|
+
)
|
59
|
+
|
60
|
+
raise "Error requesting CSV" unless file_metadata_result.status == 200
|
61
|
+
|
62
|
+
csv_raw_data = client.execute!(
|
63
|
+
http_method: :get,
|
64
|
+
uri: file_metadata_result.data.export_links["text/csv"]
|
65
|
+
)
|
66
|
+
CSV.parse(csv_raw_data.body, {headers: true})
|
67
|
+
end
|
68
|
+
|
69
|
+
def client
|
70
|
+
@client ||= Google::APIClient.new(
|
71
|
+
application_name: @config["googleAppName"] || "String File Generator",
|
72
|
+
application_version: BabelBot::VERSION
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
def cached_auth_exists?
|
77
|
+
file_storage.authorization
|
78
|
+
end
|
79
|
+
|
80
|
+
def file_storage
|
81
|
+
@file_storage ||= Google::APIClient::FileStorage.new(@config["credentialsCachePath"])
|
82
|
+
end
|
83
|
+
|
84
|
+
def app_flow
|
85
|
+
@app_flow ||= Google::APIClient::InstalledAppFlow.new(
|
86
|
+
client_id: client_secrets.client_id,
|
87
|
+
client_secret: client_secrets.client_secret,
|
88
|
+
scope: ["https://www.googleapis.com/auth/drive"]
|
89
|
+
)
|
90
|
+
end
|
91
|
+
|
92
|
+
def client_secrets
|
93
|
+
@client_secrets ||= Google::APIClient::ClientSecrets.load
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2016, salesforce.com, inc.
|
3
|
+
# All rights reserved.
|
4
|
+
# Licensed under the BSD 3-Clause license.
|
5
|
+
# For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
6
|
+
#
|
7
|
+
|
8
|
+
module BabelBot
|
9
|
+
class Runner
|
10
|
+
def initialize(config)
|
11
|
+
@config = config
|
12
|
+
end
|
13
|
+
|
14
|
+
def generate_strings
|
15
|
+
twine_file_path = @config['twineFilePath']
|
16
|
+
csv = BabelBot::CSVLoader.new(@config).load
|
17
|
+
BabelBot::TwineGenerator.new(csv, twine_file_path).generate
|
18
|
+
system "twine generate-all-string-files #{twine_file_path} #{@config['projectLocalesPath']}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2016, salesforce.com, inc.
|
3
|
+
# All rights reserved.
|
4
|
+
# Licensed under the BSD 3-Clause license.
|
5
|
+
# For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
6
|
+
#
|
7
|
+
|
8
|
+
require "twine"
|
9
|
+
|
10
|
+
module BabelBot
|
11
|
+
class TwineGenerator
|
12
|
+
|
13
|
+
KEY_ID = "Key"
|
14
|
+
COMMENT_ID = "Comment"
|
15
|
+
EN_LOCALE = "en"
|
16
|
+
|
17
|
+
def initialize(csv, out_path)
|
18
|
+
@csv = csv
|
19
|
+
@out_path = out_path
|
20
|
+
@non_english_locales = @csv.headers - [KEY_ID, COMMENT_ID, EN_LOCALE]
|
21
|
+
end
|
22
|
+
|
23
|
+
def generate
|
24
|
+
section = generate_section
|
25
|
+
strings_file = generate_strings_file(section)
|
26
|
+
strings_file.write(@out_path)
|
27
|
+
end
|
28
|
+
|
29
|
+
def generate_section
|
30
|
+
Twine::StringsSection.new("General").tap do |section|
|
31
|
+
valid_rows = filter_duplicate_rows
|
32
|
+
valid_rows.sort{|a, b| a[KEY_ID] <=> b[KEY_ID] }.each do |row|
|
33
|
+
translation_row = Twine::StringsRow.new(row[KEY_ID])
|
34
|
+
|
35
|
+
translation_row.comment = row[COMMENT_ID]
|
36
|
+
|
37
|
+
translation_row.translations[EN_LOCALE] = row[EN_LOCALE]
|
38
|
+
@non_english_locales.each do |locale|
|
39
|
+
translation_row.translations[locale] = row[locale] if row[locale]
|
40
|
+
end
|
41
|
+
|
42
|
+
section.rows << translation_row
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def filter_duplicate_rows
|
48
|
+
@csv.entries.uniq{|x| x[KEY_ID] }
|
49
|
+
end
|
50
|
+
|
51
|
+
def generate_strings_file(section)
|
52
|
+
Twine::StringsFile.new.tap do |strings_file|
|
53
|
+
strings_file.set_developer_language_code(EN_LOCALE)
|
54
|
+
|
55
|
+
@non_english_locales.each do |locale|
|
56
|
+
strings_file.add_language_code(locale)
|
57
|
+
end
|
58
|
+
|
59
|
+
strings_file.sections << section
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2016, salesforce.com, inc.
|
3
|
+
# All rights reserved.
|
4
|
+
# Licensed under the BSD 3-Clause license.
|
5
|
+
# For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
6
|
+
#
|
7
|
+
|
8
|
+
module BabelBot
|
9
|
+
VERSION = "1.0.0"
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,206 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: babel_bot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Changnon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-13 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: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
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: pry-byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-reporters
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: mocha
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activesupport
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 4.2.4
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 4.2.4
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: google-api-client
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.8.6
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.8.6
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: slop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ~>
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 3.6.0
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ~>
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 3.6.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: twine
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ~>
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.6.0
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ~>
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.6.0
|
153
|
+
description:
|
154
|
+
email:
|
155
|
+
- nchangnon@salesforce.com
|
156
|
+
executables:
|
157
|
+
- babel-bot
|
158
|
+
extensions: []
|
159
|
+
extra_rdoc_files: []
|
160
|
+
files:
|
161
|
+
- .gitignore
|
162
|
+
- .ruby-version
|
163
|
+
- .travis.yml
|
164
|
+
- CODE_OF_CONDUCT.md
|
165
|
+
- Gemfile
|
166
|
+
- LICENSE.txt
|
167
|
+
- README.md
|
168
|
+
- Rakefile
|
169
|
+
- babel_bot.gemspec
|
170
|
+
- bin/babel-bot
|
171
|
+
- bin/console
|
172
|
+
- bin/setup
|
173
|
+
- doc/google-doc-id.png
|
174
|
+
- examples/config.json
|
175
|
+
- lib/babel_bot.rb
|
176
|
+
- lib/babel_bot/cli.rb
|
177
|
+
- lib/babel_bot/csv_loader.rb
|
178
|
+
- lib/babel_bot/runner.rb
|
179
|
+
- lib/babel_bot/twine_generator.rb
|
180
|
+
- lib/babel_bot/version.rb
|
181
|
+
- tmp/.gitkeep
|
182
|
+
homepage: https://github.com/salesforce/BabelBot
|
183
|
+
licenses:
|
184
|
+
- BSD-3-Clause
|
185
|
+
metadata: {}
|
186
|
+
post_install_message:
|
187
|
+
rdoc_options: []
|
188
|
+
require_paths:
|
189
|
+
- lib
|
190
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - '>='
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
196
|
+
requirements:
|
197
|
+
- - '>='
|
198
|
+
- !ruby/object:Gem::Version
|
199
|
+
version: '0'
|
200
|
+
requirements: []
|
201
|
+
rubyforge_project:
|
202
|
+
rubygems_version: 2.6.10
|
203
|
+
signing_key:
|
204
|
+
specification_version: 4
|
205
|
+
summary: gem to generate localization string files from a Google Spreadsheet
|
206
|
+
test_files: []
|