lokalise_rails 5.0.1 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile +5 -6
- data/LICENSE +1 -1
- data/README.md +6 -7
- data/Rakefile +27 -4
- data/lib/generators/templates/lokalise_rails_config.rb +40 -38
- data/lib/lokalise_rails/version.rb +2 -4
- data/lib/tasks/lokalise_rails_tasks.rake +2 -0
- data/lokalise_rails.gemspec +2 -3
- metadata +7 -59
- data/spec/dummy/app/controllers/application_controller.rb +0 -4
- data/spec/dummy/app/helpers/application_helper.rb +0 -4
- data/spec/dummy/app/models/application_record.rb +0 -5
- data/spec/dummy/config/application.rb +0 -36
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/environment.rb +0 -7
- data/spec/dummy/config/environments/development.rb +0 -56
- data/spec/dummy/config/environments/production.rb +0 -100
- data/spec/dummy/config/environments/test.rb +0 -38
- data/spec/dummy/config/initializers/assets.rb +0 -14
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -7
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -6
- data/spec/dummy/config/lokalise_rails.rb +0 -5
- data/spec/dummy/config/puma.rb +0 -40
- data/spec/dummy/config/routes.rb +0 -5
- data/spec/dummy/db/seeds.rb +0 -8
- data/spec/lib/generators/lokalise_rails/install_generator_spec.rb +0 -19
- data/spec/lib/lokalise_rails/global_config_spec.rb +0 -117
- data/spec/lib/lokalise_rails/version_spec.rb +0 -7
- data/spec/lib/tasks/export_task_spec.rb +0 -51
- data/spec/lib/tasks/import_task_spec.rb +0 -58
- data/spec/lib/utils_spec.rb +0 -16
- data/spec/spec_helper.rb +0 -35
- data/spec/support/file_manager.rb +0 -86
- data/spec/support/spec_addons.rb +0 -16
- data/spec/support/vcr.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f210fb25454eb844cf639a709f81271aad408589d9b0269e6553fcfc02d112c
|
4
|
+
data.tar.gz: c2063c8f253c577412797aad2e2299cde7c715439fb2ddfc34b27c2c592ba7d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef1fd7e991348827a51f221851a9343ce473b1c1c8b85b77b63feb70ed22d15231d1339c8371e3435fa59543c6a52448470e7800c03e8d54402464251263bfe0
|
7
|
+
data.tar.gz: bcb9c3741313418c3fc35c121071884cdd7083ad8d66fb1d8f41357d7df68cfbfefd65dae677a73ea5e5361d7b914e64751429a89221804bd65b1bf62879b06f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 5.2.0 (26-Jan-2023)
|
4
|
+
|
5
|
+
* The gem can now be added to the `development` group instead of `production` to reduce the bundle size
|
6
|
+
* Update dependences, test with Ruby 3.2
|
7
|
+
|
8
|
+
## 5.1.0 (26-Aug-2022)
|
9
|
+
|
10
|
+
* Fixed an issue with `\n` being improperly imported
|
11
|
+
* Changed default `yaml` format to `ruby_yaml`
|
12
|
+
* Update dependencies
|
13
|
+
|
3
14
|
## 5.0.1 (15-Mar-2022)
|
4
15
|
|
5
16
|
* Fix issue with Zeitwerk and files loading
|
data/Gemfile
CHANGED
@@ -5,16 +5,15 @@ source 'http://rubygems.org'
|
|
5
5
|
gemspec
|
6
6
|
|
7
7
|
group :test do
|
8
|
-
gem 'codecov', '~> 0.2'
|
9
8
|
gem 'dotenv', '~> 2.5'
|
10
|
-
gem 'rails', '~> 7.0'
|
9
|
+
gem 'rails', '~> 7.0.4'
|
11
10
|
gem 'rake', '~> 13.0'
|
12
11
|
gem 'rspec', '~> 3.6'
|
13
12
|
gem 'rubocop', '~> 1.0'
|
14
13
|
gem 'rubocop-performance', '~> 1.5'
|
14
|
+
gem 'rubocop-rake', '~> 0.6'
|
15
15
|
gem 'rubocop-rspec', '~> 2.6'
|
16
|
-
gem 'simplecov', '~> 0.
|
17
|
-
gem '
|
18
|
-
gem '
|
19
|
-
gem 'vcr', '~> 6.1'
|
16
|
+
gem 'simplecov', '~> 0.22'
|
17
|
+
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
|
18
|
+
gem 'webmock', '~> 3.14'
|
20
19
|
end
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
![Gem](https://img.shields.io/gem/v/lokalise_rails)
|
4
4
|
![CI](https://github.com/bodrovis/lokalise_rails/actions/workflows/ci.yml/badge.svg)
|
5
|
-
[![Test Coverage](https://codecov.io/gh/bodrovis/lokalise_rails/graph/badge.svg)](https://codecov.io/gh/bodrovis/lokalise_rails)
|
6
5
|
![Downloads total](https://img.shields.io/gem/dt/lokalise_rails)
|
7
6
|
|
8
7
|
This gem provides [Lokalise](http://lokalise.com) integration for Ruby on Rails and allows to exchange translation files easily. It relies on [lokalise_manager](https://github.com/bodrovis/lokalise_manager) which perform the actual import/export and can be used to run this task in any Ruby script.
|
@@ -13,13 +12,13 @@ This gem provides [Lokalise](http://lokalise.com) integration for Ruby on Rails
|
|
13
12
|
|
14
13
|
### Requirements
|
15
14
|
|
16
|
-
This gem requires Ruby 2.
|
15
|
+
This gem requires Ruby 2.7+ and Rails 5.1+. It might work with older versions of Rails though. You will also need to [setup a Lokalise account](https://app.lokalise.com/signup) and create a [translation project](https://docs.lokalise.com/en/articles/1400460-projects). Finally, you will need to generate a [read/write API token](https://docs.lokalise.com/en/articles/1929556-api-tokens) at your Lokalise profile.
|
17
16
|
|
18
17
|
Alternatively, you can utilize a token obtained via OAuth 2 flow. When using such a token, you'll have to set `:use_oauth2_token` option to `true` (please check [options docs](https://github.com/bodrovis/lokalise_manager#common-config) to learn more).
|
19
18
|
|
20
19
|
### Installation
|
21
20
|
|
22
|
-
Add the gem to your `Gemfile
|
21
|
+
Add the gem to your `Gemfile` (it can be added to the `development` group if you're not planning to import/export translations in production):
|
23
22
|
|
24
23
|
```ruby
|
25
24
|
gem 'lokalise_rails'
|
@@ -131,7 +130,7 @@ LokaliseRails::GlobalConfig.config do |c|
|
|
131
130
|
|
132
131
|
# Import options have the following defaults:
|
133
132
|
# c.import_opts = {
|
134
|
-
# format: '
|
133
|
+
# format: 'ruby_yaml',
|
135
134
|
# placeholder_format: :icu,
|
136
135
|
# yaml_include_root: true,
|
137
136
|
# original_filenames: true,
|
@@ -156,7 +155,7 @@ LokaliseRails::GlobalConfig.config do |c|
|
|
156
155
|
## c.translations_loader = ->(raw_data) { YAML.safe_load raw_data }
|
157
156
|
|
158
157
|
## Convert translations data to a proper format:
|
159
|
-
## c.translations_converter = ->(raw_data) { raw_data.
|
158
|
+
## c.translations_converter = ->(raw_data) { YAML.dump(raw_data).gsub(/\\\\n/, '\n') }
|
160
159
|
|
161
160
|
## Infer language ISO code for the translation file:
|
162
161
|
## c.lang_iso_inferer = ->(data) { YAML.safe_load(data)&.keys&.first }
|
@@ -165,9 +164,9 @@ end
|
|
165
164
|
|
166
165
|
## Running tests
|
167
166
|
|
168
|
-
1. Copypaste `.env.example` file as `.env`. Put your Lokalise API token and project ID inside. The `.env` file is excluded from version control so your data is safe. All in all, we use
|
167
|
+
1. Copypaste `.env.example` file as `.env`. Put your Lokalise API token and project ID inside. The `.env` file is excluded from version control so your data is safe. All in all, we use stubbed requests, so the actual API requests won't be sent. However, providing at least some values is required.
|
169
168
|
2. Run `rspec .`. Observe test results and code coverage.
|
170
169
|
|
171
170
|
## License
|
172
171
|
|
173
|
-
Copyright (c) [Lokalise team](http://lokalise.com), [Ilya
|
172
|
+
Copyright (c) [Lokalise team](http://lokalise.com), [Ilya Krukowski](http://bodrovis.tech). License type is [MIT](https://github.com/bodrovis/lokalise_rails/blob/master/LICENSE).
|
data/Rakefile
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'rake'
|
4
|
+
require 'rake/clean'
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
require 'rubocop/rake_task'
|
4
7
|
|
5
8
|
begin
|
6
9
|
require 'bundler/setup'
|
@@ -9,13 +12,33 @@ rescue LoadError
|
|
9
12
|
puts 'although not required, bundler is recommened for running the tests'
|
10
13
|
end
|
11
14
|
|
12
|
-
task default: :spec
|
13
|
-
|
14
|
-
require 'rspec/core/rake_task'
|
15
15
|
RSpec::Core::RakeTask.new(:spec)
|
16
16
|
|
17
|
-
require 'rubocop/rake_task'
|
18
17
|
RuboCop::RakeTask.new do |task|
|
19
18
|
task.requires << 'rubocop-performance'
|
20
19
|
task.requires << 'rubocop-rspec'
|
20
|
+
task.requires << 'rubocop-rake'
|
21
|
+
end
|
22
|
+
|
23
|
+
CLOBBER.include(FileList['./*.gem'])
|
24
|
+
|
25
|
+
namespace :lokalise do
|
26
|
+
desc 'Updates RubyGems, installs dependencies'
|
27
|
+
task :install do
|
28
|
+
puts 'Running bundle install'
|
29
|
+
sh 'gem update --system'
|
30
|
+
sh 'bundle'
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'Builds the gem'
|
34
|
+
task :build do
|
35
|
+
puts 'Building'
|
36
|
+
sh 'gem build lokalise_rails.gemspec'
|
37
|
+
end
|
21
38
|
end
|
39
|
+
|
40
|
+
task rubospec: %w[rubocop spec]
|
41
|
+
|
42
|
+
task full_build: %w[clobber lokalise:install lokalise:build]
|
43
|
+
|
44
|
+
task default: :full_build
|
@@ -1,54 +1,56 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
LokaliseRails::GlobalConfig
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
if defined?(LokaliseRails) && defined?(LokaliseRails::GlobalConfig)
|
4
|
+
LokaliseRails::GlobalConfig.config do |c|
|
5
|
+
# These are mandatory options that you must set before running rake tasks:
|
6
|
+
# c.api_token = ENV['LOKALISE_API_TOKEN']
|
7
|
+
# c.project_id = ENV['LOKALISE_PROJECT_ID']
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
# Provide a custom path to the directory with your translation files:
|
10
|
+
# c.locales_path = "#{Rails.root}/config/locales"
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
# Provide a Lokalise project branch to use:
|
13
|
+
# c.branch = ''
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
# Provide request timeouts for the Lokalise API client:
|
16
|
+
# c.timeouts = {open_timeout: nil, timeout: nil}
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
# Provide maximum number of retries for file exporting:
|
19
|
+
# c.max_retries_export = 5
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
# Provide maximum number of retries for file importing:
|
22
|
+
# c.max_retries_import = 5
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
# Import options have the following defaults:
|
25
|
+
# c.import_opts = {
|
26
|
+
# format: 'ruby_yaml',
|
27
|
+
# placeholder_format: :icu,
|
28
|
+
# yaml_include_root: true,
|
29
|
+
# original_filenames: true,
|
30
|
+
# directory_prefix: '',
|
31
|
+
# indentation: '2sp'
|
32
|
+
# }
|
32
33
|
|
33
|
-
|
34
|
-
|
34
|
+
# Safe mode for imports is disabled by default:
|
35
|
+
# c.import_safe_mode = false
|
35
36
|
|
36
|
-
|
37
|
-
|
37
|
+
# Additional export options (only filename, contents, and lang_iso params are provided by default)
|
38
|
+
# c.export_opts = {}
|
38
39
|
|
39
|
-
|
40
|
-
|
40
|
+
# Provide additional file exclusion criteria for exports (by default, any file with the proper extension will be exported)
|
41
|
+
# c.skip_file_export = ->(file) { file.split[1].to_s.include?('fr') }
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
# Set the options below if you would like to work with format other than YAML
|
44
|
+
## Regular expression to use when choosing the files to extract from the downloaded archive and upload to Lokalise
|
45
|
+
## c.file_ext_regexp = /\.ya?ml\z/i
|
45
46
|
|
46
|
-
|
47
|
-
|
47
|
+
## Load translations data and make sure they are valid:
|
48
|
+
## c.translations_loader = ->(raw_data) { YAML.safe_load raw_data }
|
48
49
|
|
49
|
-
|
50
|
-
|
50
|
+
## Convert translations data to a proper format:
|
51
|
+
## c.translations_converter = ->(raw_data) { YAML.dump(raw_data).gsub(/\\\\n/, '\n') }
|
51
52
|
|
52
|
-
|
53
|
-
|
53
|
+
## Infer language ISO code for the translation file:
|
54
|
+
## c.lang_iso_inferer = ->(data) { YAML.safe_load(data)&.keys&.first }
|
55
|
+
end
|
54
56
|
end
|
@@ -5,6 +5,7 @@ require 'lokalise_rails'
|
|
5
5
|
require "#{LokaliseRails::Utils.root}/config/lokalise_rails"
|
6
6
|
|
7
7
|
namespace :lokalise_rails do
|
8
|
+
desc 'Imports translation files from Lokalise to the current Rails project'
|
8
9
|
task :import do
|
9
10
|
importer = LokaliseManager.importer({}, LokaliseRails::GlobalConfig)
|
10
11
|
importer.import!
|
@@ -12,6 +13,7 @@ namespace :lokalise_rails do
|
|
12
13
|
abort e.inspect
|
13
14
|
end
|
14
15
|
|
16
|
+
desc 'Exports translation files from the current Rails project to Lokalise'
|
15
17
|
task :export do
|
16
18
|
exporter = LokaliseManager.exporter({}, LokaliseRails::GlobalConfig)
|
17
19
|
exporter.export!
|
data/lokalise_rails.gemspec
CHANGED
@@ -5,7 +5,7 @@ require File.expand_path('lib/lokalise_rails/version', __dir__)
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'lokalise_rails'
|
7
7
|
spec.version = LokaliseRails::VERSION
|
8
|
-
spec.authors = ['Ilya
|
8
|
+
spec.authors = ['Ilya Krukowski']
|
9
9
|
spec.email = ['golosizpru@gmail.com']
|
10
10
|
spec.summary = 'Lokalise integration for Ruby on Rails'
|
11
11
|
spec.description = 'This gem allows to exchange translation files between your Rails app and Lokalise TMS.'
|
@@ -19,11 +19,10 @@ Gem::Specification.new do |spec|
|
|
19
19
|
'lib/**/*.rake',
|
20
20
|
'lokalise_rails.gemspec', '.github/*.md',
|
21
21
|
'Gemfile', 'Rakefile']
|
22
|
-
spec.test_files = Dir['spec/**/*.rb']
|
23
22
|
spec.extra_rdoc_files = ['README.md']
|
24
23
|
spec.require_paths = ['lib']
|
25
24
|
|
26
|
-
spec.add_dependency 'lokalise_manager', '~> 3.
|
25
|
+
spec.add_dependency 'lokalise_manager', '~> 3.2'
|
27
26
|
spec.add_dependency 'zeitwerk', '~> 2.4'
|
28
27
|
|
29
28
|
spec.metadata = {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lokalise_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0
|
4
|
+
version: 5.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Ilya
|
7
|
+
- Ilya Krukowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lokalise_manager
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '3.
|
19
|
+
version: '3.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '3.
|
26
|
+
version: '3.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: zeitwerk
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,32 +64,6 @@ files:
|
|
64
64
|
- lib/lokalise_rails/version.rb
|
65
65
|
- lib/tasks/lokalise_rails_tasks.rake
|
66
66
|
- lokalise_rails.gemspec
|
67
|
-
- spec/dummy/app/controllers/application_controller.rb
|
68
|
-
- spec/dummy/app/helpers/application_helper.rb
|
69
|
-
- spec/dummy/app/models/application_record.rb
|
70
|
-
- spec/dummy/config/application.rb
|
71
|
-
- spec/dummy/config/boot.rb
|
72
|
-
- spec/dummy/config/environment.rb
|
73
|
-
- spec/dummy/config/environments/development.rb
|
74
|
-
- spec/dummy/config/environments/production.rb
|
75
|
-
- spec/dummy/config/environments/test.rb
|
76
|
-
- spec/dummy/config/initializers/assets.rb
|
77
|
-
- spec/dummy/config/initializers/cookies_serializer.rb
|
78
|
-
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
79
|
-
- spec/dummy/config/lokalise_rails.rb
|
80
|
-
- spec/dummy/config/puma.rb
|
81
|
-
- spec/dummy/config/routes.rb
|
82
|
-
- spec/dummy/db/seeds.rb
|
83
|
-
- spec/lib/generators/lokalise_rails/install_generator_spec.rb
|
84
|
-
- spec/lib/lokalise_rails/global_config_spec.rb
|
85
|
-
- spec/lib/lokalise_rails/version_spec.rb
|
86
|
-
- spec/lib/tasks/export_task_spec.rb
|
87
|
-
- spec/lib/tasks/import_task_spec.rb
|
88
|
-
- spec/lib/utils_spec.rb
|
89
|
-
- spec/spec_helper.rb
|
90
|
-
- spec/support/file_manager.rb
|
91
|
-
- spec/support/spec_addons.rb
|
92
|
-
- spec/support/vcr.rb
|
93
67
|
homepage: https://github.com/bodrovis/lokalise_rails
|
94
68
|
licenses:
|
95
69
|
- MIT
|
@@ -110,34 +84,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
84
|
- !ruby/object:Gem::Version
|
111
85
|
version: '0'
|
112
86
|
requirements: []
|
113
|
-
rubygems_version: 3.
|
87
|
+
rubygems_version: 3.4.5
|
114
88
|
signing_key:
|
115
89
|
specification_version: 4
|
116
90
|
summary: Lokalise integration for Ruby on Rails
|
117
|
-
test_files:
|
118
|
-
- spec/dummy/app/controllers/application_controller.rb
|
119
|
-
- spec/dummy/app/helpers/application_helper.rb
|
120
|
-
- spec/dummy/app/models/application_record.rb
|
121
|
-
- spec/dummy/config/application.rb
|
122
|
-
- spec/dummy/config/boot.rb
|
123
|
-
- spec/dummy/config/environment.rb
|
124
|
-
- spec/dummy/config/environments/development.rb
|
125
|
-
- spec/dummy/config/environments/production.rb
|
126
|
-
- spec/dummy/config/environments/test.rb
|
127
|
-
- spec/dummy/config/initializers/assets.rb
|
128
|
-
- spec/dummy/config/initializers/cookies_serializer.rb
|
129
|
-
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
130
|
-
- spec/dummy/config/lokalise_rails.rb
|
131
|
-
- spec/dummy/config/puma.rb
|
132
|
-
- spec/dummy/config/routes.rb
|
133
|
-
- spec/dummy/db/seeds.rb
|
134
|
-
- spec/lib/generators/lokalise_rails/install_generator_spec.rb
|
135
|
-
- spec/lib/lokalise_rails/global_config_spec.rb
|
136
|
-
- spec/lib/lokalise_rails/version_spec.rb
|
137
|
-
- spec/lib/tasks/export_task_spec.rb
|
138
|
-
- spec/lib/tasks/import_task_spec.rb
|
139
|
-
- spec/lib/utils_spec.rb
|
140
|
-
- spec/spec_helper.rb
|
141
|
-
- spec/support/file_manager.rb
|
142
|
-
- spec/support/spec_addons.rb
|
143
|
-
- spec/support/vcr.rb
|
91
|
+
test_files: []
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'boot'
|
4
|
-
|
5
|
-
require 'rails'
|
6
|
-
# Pick the frameworks you want:
|
7
|
-
# require 'active_model/railtie'
|
8
|
-
# require "active_job/railtie"
|
9
|
-
# require 'active_record/railtie'
|
10
|
-
# require "active_storage/engine"
|
11
|
-
require 'action_controller/railtie'
|
12
|
-
# require "action_mailer/railtie"
|
13
|
-
# require "action_mailbox/engine"
|
14
|
-
# require "action_text/engine"
|
15
|
-
require 'action_view/railtie'
|
16
|
-
# require "action_cable/engine"
|
17
|
-
require 'sprockets/railtie'
|
18
|
-
# require "rails/test_unit/railtie"
|
19
|
-
|
20
|
-
# Require the gems listed in Gemfile, including any gems
|
21
|
-
# you've limited to :test, :development, or :production.
|
22
|
-
Bundler.require(*Rails.groups)
|
23
|
-
|
24
|
-
require 'dotenv/load'
|
25
|
-
|
26
|
-
module Dummy
|
27
|
-
class Application < Rails::Application
|
28
|
-
# Settings in config/environments/* take precedence over those specified here.
|
29
|
-
# Application configuration can go into files in config/initializers
|
30
|
-
# -- all .rb files in that directory are automatically loaded after loading
|
31
|
-
# the framework and any gems in your application.
|
32
|
-
|
33
|
-
# Don't generate system test files.
|
34
|
-
config.generators.system_tests = nil
|
35
|
-
end
|
36
|
-
end
|
data/spec/dummy/config/boot.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
Rails.application.configure do
|
4
|
-
# Settings specified here will take precedence over those in config/application.rb.
|
5
|
-
|
6
|
-
# In the development environment your application's code is reloaded on
|
7
|
-
# every request. This slows down response time but is perfect for development
|
8
|
-
# since you don't have to restart the web server when you make code changes.
|
9
|
-
config.cache_classes = false
|
10
|
-
|
11
|
-
# Do not eager load code on boot.
|
12
|
-
config.eager_load = false
|
13
|
-
|
14
|
-
# Show full error reports.
|
15
|
-
config.consider_all_requests_local = true
|
16
|
-
|
17
|
-
# Enable/disable caching. By default caching is disabled.
|
18
|
-
# Run rails dev:cache to toggle caching.
|
19
|
-
if Rails.root.join('tmp', 'caching-dev.txt').exist?
|
20
|
-
config.action_controller.perform_caching = true
|
21
|
-
config.action_controller.enable_fragment_cache_logging = true
|
22
|
-
|
23
|
-
config.cache_store = :memory_store
|
24
|
-
config.public_file_server.headers = {
|
25
|
-
'Cache-Control' => "public, max-age=#{2.days.to_i}"
|
26
|
-
}
|
27
|
-
else
|
28
|
-
config.action_controller.perform_caching = false
|
29
|
-
|
30
|
-
config.cache_store = :null_store
|
31
|
-
end
|
32
|
-
|
33
|
-
# Print deprecation notices to the Rails logger.
|
34
|
-
config.active_support.deprecation = :log
|
35
|
-
|
36
|
-
# Raise an error on page load if there are pending migrations.
|
37
|
-
config.active_record.migration_error = :page_load
|
38
|
-
|
39
|
-
# Highlight code that triggered database queries in logs.
|
40
|
-
config.active_record.verbose_query_logs = true
|
41
|
-
|
42
|
-
# Debug mode disables concatenation and preprocessing of assets.
|
43
|
-
# This option may cause significant delays in view rendering with a large
|
44
|
-
# number of complex assets.
|
45
|
-
config.assets.debug = true
|
46
|
-
|
47
|
-
# Suppress logger output for asset requests.
|
48
|
-
config.assets.quiet = true
|
49
|
-
|
50
|
-
# Raises error for missing translations.
|
51
|
-
# config.action_view.raise_on_missing_translations = true
|
52
|
-
|
53
|
-
# Use an evented file watcher to asynchronously detect changes in source code,
|
54
|
-
# routes, locales, etc. This feature depends on the listen gem.
|
55
|
-
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
|
56
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
Rails.application.configure do
|
4
|
-
# Settings specified here will take precedence over those in config/application.rb.
|
5
|
-
|
6
|
-
# Code is not reloaded between requests.
|
7
|
-
config.cache_classes = true
|
8
|
-
|
9
|
-
# Eager load code on boot. This eager loads most of Rails and
|
10
|
-
# your application in memory, allowing both threaded web servers
|
11
|
-
# and those relying on copy on write to perform better.
|
12
|
-
# Rake tasks automatically ignore this option for performance.
|
13
|
-
config.eager_load = true
|
14
|
-
|
15
|
-
# Full error reports are disabled and caching is turned on.
|
16
|
-
config.consider_all_requests_local = false
|
17
|
-
config.action_controller.perform_caching = true
|
18
|
-
|
19
|
-
# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
|
20
|
-
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
|
21
|
-
# config.require_master_key = true
|
22
|
-
|
23
|
-
# Disable serving static files from the `/public` folder by default since
|
24
|
-
# Apache or NGINX already handles this.
|
25
|
-
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
|
26
|
-
|
27
|
-
# Compress CSS using a preprocessor.
|
28
|
-
# config.assets.css_compressor = :sass
|
29
|
-
|
30
|
-
# Do not fallback to assets pipeline if a precompiled asset is missed.
|
31
|
-
config.assets.compile = false
|
32
|
-
|
33
|
-
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
|
34
|
-
# config.action_controller.asset_host = 'http://assets.example.com'
|
35
|
-
|
36
|
-
# Specifies the header that your server uses for sending files.
|
37
|
-
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
|
38
|
-
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
|
39
|
-
|
40
|
-
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
41
|
-
# config.force_ssl = true
|
42
|
-
|
43
|
-
# Use the lowest log level to ensure availability of diagnostic information
|
44
|
-
# when problems arise.
|
45
|
-
config.log_level = :debug
|
46
|
-
|
47
|
-
# Prepend all log lines with the following tags.
|
48
|
-
config.log_tags = [:request_id]
|
49
|
-
|
50
|
-
# Use a different cache store in production.
|
51
|
-
# config.cache_store = :mem_cache_store
|
52
|
-
|
53
|
-
# Use a real queuing backend for Active Job (and separate queues per environment).
|
54
|
-
# config.active_job.queue_adapter = :resque
|
55
|
-
# config.active_job.queue_name_prefix = "dummy_production"
|
56
|
-
|
57
|
-
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
58
|
-
# the I18n.default_locale when a translation cannot be found).
|
59
|
-
config.i18n.fallbacks = true
|
60
|
-
|
61
|
-
# Send deprecation notices to registered listeners.
|
62
|
-
config.active_support.deprecation = :notify
|
63
|
-
|
64
|
-
# Use default logging formatter so that PID and timestamp are not suppressed.
|
65
|
-
config.log_formatter = ::Logger::Formatter.new
|
66
|
-
|
67
|
-
# Use a different logger for distributed setups.
|
68
|
-
# require 'syslog/logger'
|
69
|
-
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
|
70
|
-
|
71
|
-
if ENV['RAILS_LOG_TO_STDOUT'].present?
|
72
|
-
logger = ActiveSupport::Logger.new($stdout)
|
73
|
-
logger.formatter = config.log_formatter
|
74
|
-
config.logger = ActiveSupport::TaggedLogging.new(logger)
|
75
|
-
end
|
76
|
-
|
77
|
-
# Do not dump schema after migrations.
|
78
|
-
config.active_record.dump_schema_after_migration = false
|
79
|
-
|
80
|
-
# Inserts middleware to perform automatic connection switching.
|
81
|
-
# The `database_selector` hash is used to pass options to the DatabaseSelector
|
82
|
-
# middleware. The `delay` is used to determine how long to wait after a write
|
83
|
-
# to send a subsequent read to the primary.
|
84
|
-
#
|
85
|
-
# The `database_resolver` class is used by the middleware to determine which
|
86
|
-
# database is appropriate to use based on the time delay.
|
87
|
-
#
|
88
|
-
# The `database_resolver_context` class is used by the middleware to set
|
89
|
-
# timestamps for the last write to the primary. The resolver uses the context
|
90
|
-
# class timestamps to determine how long to wait before reading from the
|
91
|
-
# replica.
|
92
|
-
#
|
93
|
-
# By default Rails will store a last write timestamp in the session. The
|
94
|
-
# DatabaseSelector middleware is designed as such you can define your own
|
95
|
-
# strategy for connection switching and pass that into the middleware through
|
96
|
-
# these configuration options.
|
97
|
-
# config.active_record.database_selector = { delay: 2.seconds }
|
98
|
-
# config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
|
99
|
-
# config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
|
100
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# The test environment is used exclusively to run your application's
|
4
|
-
# test suite. You never need to work with it otherwise. Remember that
|
5
|
-
# your test database is "scratch space" for the test suite and is wiped
|
6
|
-
# and recreated between test runs. Don't rely on the data there!
|
7
|
-
|
8
|
-
Rails.application.configure do
|
9
|
-
# Settings specified here will take precedence over those in config/application.rb.
|
10
|
-
|
11
|
-
config.cache_classes = true
|
12
|
-
|
13
|
-
# Do not eager load code on boot. This avoids loading your whole application
|
14
|
-
# just for the purpose of running a single test. If you are using a tool that
|
15
|
-
# preloads Rails for running tests, you may have to set it to true.
|
16
|
-
config.eager_load = false
|
17
|
-
|
18
|
-
# Configure public file server for tests with Cache-Control for performance.
|
19
|
-
config.public_file_server.enabled = true
|
20
|
-
config.public_file_server.headers = {'Cache-Control' => 'public, max-age=3600'}
|
21
|
-
|
22
|
-
# Show full error reports and disable caching.
|
23
|
-
config.consider_all_requests_local = true
|
24
|
-
config.action_controller.perform_caching = false
|
25
|
-
config.cache_store = :null_store
|
26
|
-
|
27
|
-
# Raise exceptions instead of rendering exception templates.
|
28
|
-
config.action_dispatch.show_exceptions = false
|
29
|
-
|
30
|
-
# Disable request forgery protection in test environment.
|
31
|
-
config.action_controller.allow_forgery_protection = false
|
32
|
-
|
33
|
-
# Print deprecation notices to the stderr.
|
34
|
-
config.active_support.deprecation = :stderr
|
35
|
-
|
36
|
-
# Raises error for missing translations.
|
37
|
-
# config.action_view.raise_on_missing_translations = true
|
38
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Be sure to restart your server when you modify this file.
|
4
|
-
|
5
|
-
# Version of your assets, change this if you want to expire all your assets.
|
6
|
-
Rails.application.config.assets.version = '1.0'
|
7
|
-
|
8
|
-
# Add additional assets to the asset load path.
|
9
|
-
# Rails.application.config.assets.paths << Emoji.images_path
|
10
|
-
|
11
|
-
# Precompile additional assets.
|
12
|
-
# application.js, application.css, and all non-JS/CSS in the app/assets
|
13
|
-
# folder are already added.
|
14
|
-
# Rails.application.config.assets.precompile += %w( admin.js admin.css )
|
@@ -1,7 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Be sure to restart your server when you modify this file.
|
4
|
-
|
5
|
-
# Specify a serializer for the signed and encrypted cookie jars.
|
6
|
-
# Valid options are :json, :marshal, and :hybrid.
|
7
|
-
Rails.application.config.action_dispatch.cookies_serializer = :json
|
data/spec/dummy/config/puma.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Puma can serve each request in a thread from an internal thread pool.
|
4
|
-
# The `threads` method setting takes two numbers: a minimum and maximum.
|
5
|
-
# Any libraries that use thread pools should be configured to match
|
6
|
-
# the maximum value specified for Puma. Default is set to 5 threads for minimum
|
7
|
-
# and maximum; this matches the default thread size of Active Record.
|
8
|
-
#
|
9
|
-
max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5)
|
10
|
-
min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count }
|
11
|
-
threads min_threads_count, max_threads_count
|
12
|
-
|
13
|
-
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
|
14
|
-
#
|
15
|
-
port ENV.fetch('PORT', 3000)
|
16
|
-
|
17
|
-
# Specifies the `environment` that Puma will run in.
|
18
|
-
#
|
19
|
-
environment ENV.fetch('RAILS_ENV', 'development')
|
20
|
-
|
21
|
-
# Specifies the `pidfile` that Puma will use.
|
22
|
-
pidfile ENV.fetch('PIDFILE', 'tmp/pids/server.pid')
|
23
|
-
|
24
|
-
# Specifies the number of `workers` to boot in clustered mode.
|
25
|
-
# Workers are forked web server processes. If using threads and workers together
|
26
|
-
# the concurrency of the application would be max `threads` * `workers`.
|
27
|
-
# Workers do not work on JRuby or Windows (both of which do not support
|
28
|
-
# processes).
|
29
|
-
#
|
30
|
-
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
|
31
|
-
|
32
|
-
# Use the `preload_app!` method when specifying a `workers` number.
|
33
|
-
# This directive tells Puma to first boot the application and load code
|
34
|
-
# before forking the application. This takes advantage of Copy On Write
|
35
|
-
# process behavior so workers use less memory.
|
36
|
-
#
|
37
|
-
# preload_app!
|
38
|
-
|
39
|
-
# Allow puma to be restarted by `rails restart` command.
|
40
|
-
plugin :tmp_restart
|
data/spec/dummy/config/routes.rb
DELETED
data/spec/dummy/db/seeds.rb
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# This file should contain all the record creation needed to seed the database with its default values.
|
3
|
-
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
|
4
|
-
#
|
5
|
-
# Examples:
|
6
|
-
#
|
7
|
-
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
|
8
|
-
# Character.create(name: 'Luke', movie: movies.first)
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'generators/lokalise_rails/install_generator'
|
4
|
-
|
5
|
-
describe LokaliseRails::Generators::InstallGenerator do
|
6
|
-
before do
|
7
|
-
remove_config
|
8
|
-
end
|
9
|
-
|
10
|
-
after do
|
11
|
-
remove_config
|
12
|
-
add_config!
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'installs config file properly' do
|
16
|
-
described_class.start
|
17
|
-
expect(File.file?(config_file)).to be true
|
18
|
-
end
|
19
|
-
end
|
@@ -1,117 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
describe LokaliseRails::GlobalConfig do
|
4
|
-
let(:child_config) { Class.new(described_class) }
|
5
|
-
|
6
|
-
it 'is possible to provide config options' do
|
7
|
-
described_class.config do |c|
|
8
|
-
expect(c).to eq(described_class)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'can be redefined' do
|
13
|
-
child_config.config do |c|
|
14
|
-
c.api_token = ENV['LOKALISE_API_TOKEN']
|
15
|
-
c.project_id = ENV['LOKALISE_PROJECT_ID']
|
16
|
-
|
17
|
-
c.branch = 'develop'
|
18
|
-
end
|
19
|
-
|
20
|
-
expect(child_config.branch).to eq('develop')
|
21
|
-
importer = LokaliseManager::TaskDefinitions::Importer.new({}, child_config)
|
22
|
-
expect(importer.config.branch).to eq('develop')
|
23
|
-
expect(importer.config.api_token).to eq(ENV['LOKALISE_API_TOKEN'])
|
24
|
-
end
|
25
|
-
|
26
|
-
describe 'parameters' do
|
27
|
-
let(:fake_class) { class_double(described_class) }
|
28
|
-
|
29
|
-
it 'is possible to set project_id' do
|
30
|
-
allow(fake_class).to receive(:project_id=).with('123.abc')
|
31
|
-
fake_class.project_id = '123.abc'
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'is possible to set file_ext_regexp' do
|
35
|
-
allow(fake_class).to receive(:file_ext_regexp=).with(Regexp.new('.*'))
|
36
|
-
fake_class.file_ext_regexp = Regexp.new('.*')
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'is possible to set import_opts' do
|
40
|
-
allow(fake_class).to receive(:import_opts=).with(duck_type(:each))
|
41
|
-
fake_class.import_opts = {
|
42
|
-
format: 'json',
|
43
|
-
indentation: '8sp'
|
44
|
-
}
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'is possible to set export_opts' do
|
48
|
-
allow(fake_class).to receive(:export_opts=).with(duck_type(:each))
|
49
|
-
fake_class.export_opts = {
|
50
|
-
convert_placeholders: true,
|
51
|
-
detect_icu_plurals: true
|
52
|
-
}
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'is possible to set branch' do
|
56
|
-
allow(fake_class).to receive(:branch=).with('custom')
|
57
|
-
fake_class.branch = 'custom'
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'is possible to set timeouts' do
|
61
|
-
allow(fake_class).to receive(:timeouts=).with(duck_type(:each))
|
62
|
-
fake_class.timeouts = {
|
63
|
-
open_timeout: 100,
|
64
|
-
timeout: 500
|
65
|
-
}
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'is possible to set import_safe_mode' do
|
69
|
-
allow(fake_class).to receive(:import_safe_mode=).with(true)
|
70
|
-
fake_class.import_safe_mode = true
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'is possible to set max_retries_export' do
|
74
|
-
allow(fake_class).to receive(:max_retries_export=).with(10)
|
75
|
-
fake_class.max_retries_export = 10
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'is possible to set max_retries_import' do
|
79
|
-
allow(fake_class).to receive(:max_retries_import=).with(10)
|
80
|
-
fake_class.max_retries_import = 10
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'is possible to set api_token' do
|
84
|
-
allow(fake_class).to receive(:api_token=).with('abc')
|
85
|
-
fake_class.api_token = 'abc'
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'is possible to override locales_path' do
|
89
|
-
allow(fake_class).to receive(:locales_path=).with('/demo/path')
|
90
|
-
fake_class.locales_path = '/demo/path'
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'is possible to set skip_file_export' do
|
94
|
-
cond = ->(f) { f.nil? }
|
95
|
-
allow(fake_class).to receive(:skip_file_export=).with(cond)
|
96
|
-
fake_class.skip_file_export = cond
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'is possible to set translations_loader' do
|
100
|
-
runner = ->(f) { f.to_json }
|
101
|
-
allow(fake_class).to receive(:translations_loader=).with(runner)
|
102
|
-
fake_class.translations_loader = runner
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'is possible to set translations_converter' do
|
106
|
-
runner = ->(f) { f.to_json }
|
107
|
-
allow(fake_class).to receive(:translations_converter=).with(runner)
|
108
|
-
fake_class.translations_converter = runner
|
109
|
-
end
|
110
|
-
|
111
|
-
it 'is possible to set lang_iso_inferer' do
|
112
|
-
runner = ->(f) { f.to_json }
|
113
|
-
allow(fake_class).to receive(:lang_iso_inferer=).with(runner)
|
114
|
-
fake_class.lang_iso_inferer = runner
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe 'Export Rake task' do
|
4
|
-
let(:global_config) { LokaliseRails::GlobalConfig }
|
5
|
-
|
6
|
-
it 'halts when the API key is not set' do
|
7
|
-
allow(global_config).to receive(:api_token).and_return(nil)
|
8
|
-
|
9
|
-
expect { Rake::Task['lokalise_rails:export'].execute }.to raise_error(SystemExit, /API token is not set/i)
|
10
|
-
expect(global_config).to have_received(:api_token)
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'halts when the project ID is not set' do
|
14
|
-
allow(global_config).to receive(:project_id).and_return(nil)
|
15
|
-
|
16
|
-
expect { Rake::Task['lokalise_rails:export'].execute }.to raise_error(SystemExit, /ID is not set/i)
|
17
|
-
|
18
|
-
expect(global_config).to have_received(:project_id)
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'with two translation files' do
|
22
|
-
let(:filename_ru) { 'ru.yml' }
|
23
|
-
let(:path_ru) { "#{Rails.root}/config/locales/#{filename_ru}" }
|
24
|
-
|
25
|
-
before do
|
26
|
-
add_translation_files! with_ru: true
|
27
|
-
end
|
28
|
-
|
29
|
-
after do
|
30
|
-
rm_translation_files
|
31
|
-
end
|
32
|
-
|
33
|
-
describe 'export' do
|
34
|
-
it 'is callable' do
|
35
|
-
allow_project_id global_config, ENV['LOKALISE_PROJECT_ID'] do
|
36
|
-
VCR.use_cassette('upload_files') do
|
37
|
-
expect { Rake::Task['lokalise_rails:export'].execute }.to output(/complete!/).to_stdout
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
it 're-raises export errors' do
|
43
|
-
allow_project_id global_config, '542886116159f798720dc4.94769464' do
|
44
|
-
VCR.use_cassette('upload_files_error') do
|
45
|
-
expect { Rake::Task['lokalise_rails:export'].execute }.to raise_error(SystemExit, /Unknown `lang_iso`/)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe 'Import Rake task' do
|
4
|
-
let(:global_config) { LokaliseRails::GlobalConfig }
|
5
|
-
let(:loc_path) { global_config.locales_path }
|
6
|
-
|
7
|
-
it 'halts when the API key is not set' do
|
8
|
-
allow(global_config).to receive(:api_token).and_return(nil)
|
9
|
-
|
10
|
-
expect { Rake::Task['lokalise_rails:import'].execute }.to raise_error(SystemExit, /API token is not set/i)
|
11
|
-
expect(global_config).to have_received(:api_token)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'halts when the project ID is not set' do
|
15
|
-
allow(global_config).to receive(:project_id).and_return(nil)
|
16
|
-
|
17
|
-
expect { Rake::Task['lokalise_rails:import'].execute }.to raise_error(SystemExit, /ID is not set/i)
|
18
|
-
|
19
|
-
expect(global_config).to have_received(:project_id)
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'when directory is empty' do
|
23
|
-
before do
|
24
|
-
mkdir_locales
|
25
|
-
rm_translation_files
|
26
|
-
end
|
27
|
-
|
28
|
-
after do
|
29
|
-
rm_translation_files
|
30
|
-
end
|
31
|
-
|
32
|
-
describe 'import' do
|
33
|
-
it 'is callable' do
|
34
|
-
allow_project_id global_config, ENV['LOKALISE_PROJECT_ID'] do
|
35
|
-
VCR.use_cassette('download_files') do
|
36
|
-
expect { Rake::Task['lokalise_rails:import'].execute }.to output(/complete!/).to_stdout
|
37
|
-
end
|
38
|
-
|
39
|
-
expect(count_translations).to eq(4)
|
40
|
-
|
41
|
-
expect_file_exist loc_path, 'en.yml'
|
42
|
-
expect_file_exist loc_path, 'ru.yml'
|
43
|
-
expect_file_exist loc_path, 'yo.yml'
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
it 're-raises export errors' do
|
48
|
-
allow_project_id global_config, 'fake' do
|
49
|
-
VCR.use_cassette('download_files_error') do
|
50
|
-
expect do
|
51
|
-
Rake::Task['lokalise_rails:import'].execute
|
52
|
-
end.to raise_error(SystemExit, /Invalid `project_id` parameter/)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
data/spec/lib/utils_spec.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
describe LokaliseRails::Utils do
|
4
|
-
describe '.rails_root' do
|
5
|
-
it 'returns RAILS_ROOT if defined' do
|
6
|
-
allow(::Rails).to receive(:root).and_return(nil)
|
7
|
-
stub_const('RAILS_ROOT', '/stub')
|
8
|
-
expect(described_class.rails_root).to eq('/stub')
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'fallbacks if neither roots are present' do
|
12
|
-
allow(::Rails).to receive(:root).and_return(nil)
|
13
|
-
expect(described_class.rails_root).to be_nil
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'dotenv/load'
|
4
|
-
require 'simplecov'
|
5
|
-
|
6
|
-
SimpleCov.start 'rails' do
|
7
|
-
add_filter 'spec/'
|
8
|
-
add_filter '.github/'
|
9
|
-
add_filter 'lib/generators/templates/'
|
10
|
-
end
|
11
|
-
|
12
|
-
if ENV['CI'] == 'true'
|
13
|
-
require 'codecov'
|
14
|
-
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
15
|
-
end
|
16
|
-
|
17
|
-
# Support files
|
18
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
|
19
|
-
|
20
|
-
# Configure Rails Environment
|
21
|
-
ENV['RAILS_ENV'] = 'test'
|
22
|
-
require_relative '../spec/dummy/config/environment'
|
23
|
-
ENV['RAILS_ROOT'] ||= "#{File.dirname(__FILE__)}../../../spec/dummy"
|
24
|
-
|
25
|
-
RSpec.configure do |config|
|
26
|
-
config.include FileManager
|
27
|
-
config.include SpecAddons
|
28
|
-
end
|
29
|
-
|
30
|
-
# rubocop:disable Style/MixinUsage
|
31
|
-
include FileManager
|
32
|
-
# rubocop:enable Style/MixinUsage
|
33
|
-
|
34
|
-
add_config!
|
35
|
-
Rails.application.load_tasks
|
@@ -1,86 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'fileutils'
|
4
|
-
|
5
|
-
module FileManager
|
6
|
-
def mkdir_locales
|
7
|
-
return if File.directory?(LokaliseRails::GlobalConfig.locales_path)
|
8
|
-
|
9
|
-
FileUtils.mkdir_p(LokaliseRails::GlobalConfig.locales_path)
|
10
|
-
end
|
11
|
-
|
12
|
-
def rm_translation_files
|
13
|
-
FileUtils.rm_rf locales_dir
|
14
|
-
end
|
15
|
-
|
16
|
-
def locales_dir
|
17
|
-
Dir["#{LokaliseRails::GlobalConfig.locales_path}/**/*"]
|
18
|
-
end
|
19
|
-
|
20
|
-
def count_translations
|
21
|
-
locales_dir.count { |file| File.file?(file) }
|
22
|
-
end
|
23
|
-
|
24
|
-
def add_translation_files!(with_ru: false, additional: nil)
|
25
|
-
FileUtils.mkdir_p "#{Rails.root}/config/locales/nested"
|
26
|
-
open_and_write('config/locales/nested/en.yml') { |f| f.write en_data }
|
27
|
-
|
28
|
-
return unless with_ru
|
29
|
-
|
30
|
-
open_and_write('config/locales/ru.yml') { |f| f.write ru_data }
|
31
|
-
|
32
|
-
return unless additional
|
33
|
-
|
34
|
-
additional.times do |i|
|
35
|
-
data = {'en' => {"key_#{i}" => "value #{i}"}}
|
36
|
-
|
37
|
-
open_and_write("config/locales/en_#{i}.yml") { |f| f.write data.to_yaml }
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def add_config!(custom_text = '')
|
42
|
-
data = <<~DATA
|
43
|
-
LokaliseRails::GlobalConfig.config do |c|
|
44
|
-
c.api_token = ENV['LOKALISE_API_TOKEN']
|
45
|
-
c.project_id = ENV['LOKALISE_PROJECT_ID']
|
46
|
-
DATA
|
47
|
-
|
48
|
-
data += custom_text
|
49
|
-
data += "\nend"
|
50
|
-
open_and_write('config/lokalise_rails.rb') { |f| f.write data }
|
51
|
-
end
|
52
|
-
|
53
|
-
def open_and_write(rel_path, &block)
|
54
|
-
return unless block
|
55
|
-
|
56
|
-
File.open("#{Rails.root}/#{rel_path}", 'w+:UTF-8', &block)
|
57
|
-
end
|
58
|
-
|
59
|
-
def remove_config
|
60
|
-
FileUtils.remove_file config_file if File.file?(config_file)
|
61
|
-
end
|
62
|
-
|
63
|
-
def config_file
|
64
|
-
"#{Rails.root}/config/lokalise_rails.rb"
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
def en_data
|
70
|
-
<<~DATA
|
71
|
-
en:
|
72
|
-
my_key: "My value"
|
73
|
-
nested:
|
74
|
-
key: "Value 2"
|
75
|
-
DATA
|
76
|
-
end
|
77
|
-
|
78
|
-
def ru_data
|
79
|
-
<<~DATA
|
80
|
-
ru_RU:
|
81
|
-
my_key: "Моё значение"
|
82
|
-
nested:
|
83
|
-
key: "Значение 2"
|
84
|
-
DATA
|
85
|
-
end
|
86
|
-
end
|
data/spec/support/spec_addons.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module SpecAddons
|
4
|
-
def expect_file_exist(path, file)
|
5
|
-
file_path = File.join path, file
|
6
|
-
expect(File.file?(file_path)).to be true
|
7
|
-
end
|
8
|
-
|
9
|
-
def allow_project_id(obj, value)
|
10
|
-
allow(obj).to receive(:project_id).and_return(value)
|
11
|
-
return unless block_given?
|
12
|
-
|
13
|
-
yield
|
14
|
-
expect(obj).to have_received(:project_id)
|
15
|
-
end
|
16
|
-
end
|
data/spec/support/vcr.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'vcr'
|
4
|
-
|
5
|
-
VCR.configure do |c|
|
6
|
-
c.ignore_hosts 'codeclimate.com'
|
7
|
-
c.hook_into :faraday
|
8
|
-
c.cassette_library_dir = File.join(File.dirname(__FILE__), '..', 'fixtures', 'vcr_cassettes')
|
9
|
-
c.filter_sensitive_data('<LOKALISE_TOKEN>') { ENV.fetch('LOKALISE_API_TOKEN') }
|
10
|
-
c.configure_rspec_metadata!
|
11
|
-
end
|