lokalise_rails 2.0.0 → 3.0.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 +31 -0
- data/README.md +71 -56
- data/lib/generators/templates/lokalise_rails_config.rb +2 -4
- data/lib/lokalise_rails/global_config.rb +11 -0
- data/lib/lokalise_rails/utils.rb +20 -0
- data/lib/lokalise_rails/version.rb +1 -1
- data/lib/lokalise_rails.rb +4 -87
- data/lib/tasks/lokalise_rails_tasks.rake +6 -3
- data/lokalise_rails.gemspec +3 -4
- data/spec/dummy/config/lokalise_rails.rb +3 -3
- data/spec/lib/lokalise_rails/global_config_spec.rb +117 -0
- data/spec/lib/lokalise_rails_spec.rb +0 -98
- data/spec/lib/tasks/export_task_spec.rb +22 -15
- data/spec/lib/tasks/import_task_spec.rb +32 -95
- data/spec/lib/utils_spec.rb +16 -0
- data/spec/spec_helper.rb +0 -1
- data/spec/support/file_manager.rb +6 -11
- data/spec/support/spec_addons.rb +8 -3
- metadata +16 -34
- data/lib/lokalise_rails/error.rb +0 -10
- data/lib/lokalise_rails/task_definition/base.rb +0 -80
- data/lib/lokalise_rails/task_definition/exporter.rb +0 -79
- data/lib/lokalise_rails/task_definition/importer.rb +0 -109
- data/spec/lib/lokalise_rails/task_definition/base_spec.rb +0 -81
- data/spec/lib/lokalise_rails/task_definition/exporter_spec.rb +0 -200
- data/spec/lib/lokalise_rails/task_definition/importer_spec.rb +0 -72
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dc5e8a5807db8316b7b60606b5e32274d669504f12917022e0fbaba3f0969db
|
4
|
+
data.tar.gz: 2c54267a133e24cef62019185d2063b09b3c57bd26bca4ee28364ab2c05f6c21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21a740e73e2d2bdef702ed8ebf719b60b70474a3503428b05131ddfe0443cc21bf0750203ee9aee9c0b47b1d75ebaa200db7b47a934204d9fe800d3f2c66e1d3
|
7
|
+
data.tar.gz: 44288cec4fc4a95c95780bfe4e00f7efc23d23a07e94dd3c2bc885ef8ee4de309ade9555291aa6a8ae56a8bb99487c2a9982f026f54794e50e08acea3c93e038
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,36 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 3.0.0 (14-Oct-21)
|
4
|
+
|
5
|
+
This is a major re-write of this gem. The actual import/export functionality was extracted to a separate gem called [lokalise_manager](https://github.com/bodrovis/lokalise_manager) that you can use to run your tasks programmatically from *any* Ruby scripts (powered or not powered by Rails). LokaliseRails now has only the Rails-related logic (even though it should probably work with other frameworks as well).
|
6
|
+
|
7
|
+
* **Breaking change:** the global config class is renamed therefore update your `config/lokalise_rails.rb` file to look like this:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
LokaliseRails::GlobalConfig.config do |c|
|
11
|
+
# ...your configuration options provided as before...
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
* **Breaking change**: the `branch` config option now has `""` set as default value (it was `"master"` previously). Therefore, you might need to explicitly state which branch to use now:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
LokaliseRails::GlobalConfig.config do |c|
|
19
|
+
c.branch = "master"
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
* **Breaking change**: to run your task prommatically, use a new approach:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
LokaliseManager.importer(optional_config, global_config_object).import!
|
27
|
+
|
28
|
+
LokaliseManager.exporter(optional_config, global_config_object).export!
|
29
|
+
```
|
30
|
+
|
31
|
+
* Please check [this document section](https://github.com/bodrovis/lokalise_rails#running-tasks-programmatically) to learn more about running tasks programmatically. This change doesn't have any effect on you if you're using only Rake tasks to import/export files.
|
32
|
+
* No need to say `require 'lokalise_rails` in your `lokalise_rails.rb` config file anymore.
|
33
|
+
|
3
34
|
## 2.0.0 (19-Aug-21)
|
4
35
|
|
5
36
|
* Add exponential backoff mechanism for file imports to comply with the upcoming API changes ("rate limiting"), see below for more details.
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
[![Test Coverage](https://codecov.io/gh/bodrovis/lokalise_rails/graph/badge.svg)](https://codecov.io/gh/bodrovis/lokalise_rails)
|
6
6
|
![Downloads total](https://img.shields.io/gem/dt/lokalise_rails)
|
7
7
|
|
8
|
-
This gem provides [Lokalise](http://lokalise.com) integration for Ruby on Rails and allows to exchange translation files easily. It relies on [
|
8
|
+
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.
|
9
9
|
|
10
10
|
*If you would like to know how this gem was built, check out the ["How to create a Ruby gem" series at Lokalise blog](https://lokalise.com/blog/create-a-ruby-gem-basics/).*
|
11
11
|
|
@@ -33,9 +33,7 @@ rails g lokalise_rails:install
|
|
33
33
|
The latter command will generate a new config file `config/lokalise_rails.rb` looking like this:
|
34
34
|
|
35
35
|
```ruby
|
36
|
-
|
37
|
-
|
38
|
-
LokaliseRails.config do |c|
|
36
|
+
LokaliseRails::GlobalConfig.config do |c|
|
39
37
|
c.api_token = ENV['LOKALISE_API_TOKEN']
|
40
38
|
c.project_id = ENV['LOKALISE_PROJECT_ID']
|
41
39
|
|
@@ -45,7 +43,7 @@ end
|
|
45
43
|
|
46
44
|
You have to provide `api_token` and `project_id` to proceed. `project_id` can be found in your Lokalise project settings.
|
47
45
|
|
48
|
-
|
46
|
+
Other options can be customized as well but they have sensible defaults. To learn about all the available options please check [lokalise_manager docs](https://github.com/bodrovis/lokalise_manager#configuration). The generated config file also contains some examples to help you get started.
|
49
47
|
|
50
48
|
## Importing translations from Lokalise
|
51
49
|
|
@@ -55,7 +53,7 @@ To import translations from the specified Lokalise project to your Rails app, ru
|
|
55
53
|
rails lokalise_rails:import
|
56
54
|
```
|
57
55
|
|
58
|
-
Please note that any duplicating files inside the `locales` directory (or any other directory that you've specified in the options) will be overwritten! You
|
56
|
+
Please note that any duplicating files inside the `locales` directory (or any other directory that you've specified in the options) will be overwritten! You can enable [safe mode](https://github.com/bodrovis/lokalise_manager#import-config) to check whether the folder is empty or not.
|
59
57
|
|
60
58
|
## Exporting translations to Lokalise
|
61
59
|
|
@@ -67,84 +65,101 @@ rails lokalise_rails:export
|
|
67
65
|
|
68
66
|
## Running tasks programmatically
|
69
67
|
|
70
|
-
You can also run the import and export tasks from the
|
68
|
+
You can also run the import and export tasks programmatically from your code. To achieve that, please check the [`lokalise_manager`](https://github.com/bodrovis/lokalise_manager) gem which `lokalise_rails` relies on.
|
69
|
+
|
70
|
+
For example, you can use the following approach:
|
71
71
|
|
72
72
|
```ruby
|
73
|
+
# This line is actually not required. Include it if you would like to use your global settings:
|
73
74
|
require "#{Rails.root}/config/lokalise_rails.rb"
|
74
75
|
|
75
|
-
|
76
|
-
|
76
|
+
importer = LokaliseManager.importer({api_token: '1234abc', project_id: '123.abc'}, LokaliseRails::GlobalConfig)
|
77
|
+
|
78
|
+
# OR
|
79
|
+
|
80
|
+
exporter = LokaliseManager.exporter({api_token: '1234abc', project_id: '123.abc'}, LokaliseRails::GlobalConfig)
|
77
81
|
```
|
78
|
-
|
82
|
+
|
83
|
+
The first argument passed to `importer` or `exporter` is the hash containing per-client options. This is an optional argument and you can simply pass an empty hash if you don't want to override any global settings.
|
84
|
+
|
85
|
+
The second argument is the name of your global config which is usually stored inside the `lokalise_rails.rb` file (however, you can subclass this global config and even adjust the defaults [as explained here](https://github.com/bodrovis/lokalise_manager#overriding-defaults)). If you would like to use `LokaliseRails` global defaults, then you must pass this class to the clients. If you don't do this, then `LokaliseManager` defaults will be used instead. The only difference is the location where translation files are stored. For `LokaliseManager` we use `./locales` directory, whereas for `LokaliseRails` the directory is `./config/locales`.
|
86
|
+
|
87
|
+
However, you can also provide the translation files folder on per-client basis, for instance:
|
79
88
|
|
80
89
|
```ruby
|
81
|
-
|
82
|
-
processes = LokaliseRails::TaskDefinition::Exporter.export!
|
90
|
+
importer = LokaliseManager.importer api_token: '1234abc', project_id: '123.abc', locales_path: "#{Rails.root}/config/locales"
|
83
91
|
```
|
84
92
|
|
85
|
-
|
93
|
+
After the client is instantiated, you can run the corresponding task:
|
86
94
|
|
87
|
-
|
95
|
+
```ruby
|
96
|
+
importer.import!
|
88
97
|
|
89
|
-
|
98
|
+
# OR
|
90
99
|
|
91
|
-
|
100
|
+
exporter.export!
|
101
|
+
```
|
92
102
|
|
93
|
-
|
94
|
-
* `project_id` (`string`, required) - Lokalise project ID. You must have import/export permissions in the specified project.
|
95
|
-
* `locales_path` (`string`) - path to the directory with your translation files. Defaults to `"#{Rails.root}/config/locales"`.
|
96
|
-
* `branch` (`string`) - Lokalise project branch to use. Defaults to `"master"`.
|
97
|
-
* `timeouts` (`hash`) - set [request timeouts for the Lokalise API client](https://lokalise.github.io/ruby-lokalise-api/additional_info/customization#setting-timeouts). By default, requests have no timeouts: `{open_timeout: nil, timeout: nil}`. Both values are in seconds.
|
103
|
+
## Configuration
|
98
104
|
|
99
|
-
|
105
|
+
Options are specified in the `config/lokalise_rails.rb` file.
|
100
106
|
|
101
|
-
|
107
|
+
Here's an example:
|
102
108
|
|
103
109
|
```ruby
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
original_filenames: true,
|
109
|
-
directory_prefix: '',
|
110
|
-
indentation: '2sp'
|
111
|
-
}
|
112
|
-
```
|
110
|
+
LokaliseRails::GlobalConfig.config do |c|
|
111
|
+
# These are mandatory options that you must set before running rake tasks:
|
112
|
+
c.api_token = ENV['LOKALISE_API_TOKEN']
|
113
|
+
c.project_id = ENV['LOKALISE_PROJECT_ID']
|
113
114
|
|
114
|
-
|
115
|
-
|
116
|
-
* `max_retries_import` (`integer`) - this option is introduced to properly handle Lokalise API rate limiting. If the HTTP status code 429 (too many requests) has been received, LokaliseRails will apply an exponential backoff mechanism with a very simple formula: `2 ** retries`. If the maximum number of retries has been reached, a `Lokalise::Error::TooManyRequests` exception will be raised and the export operation will be halted.
|
115
|
+
# Provide a custom path to the directory with your translation files:
|
116
|
+
# c.locales_path = "#{Rails.root}/config/locales"
|
117
117
|
|
118
|
-
|
118
|
+
# Provide a Lokalise project branch to use:
|
119
|
+
c.branch = 'develop'
|
119
120
|
|
120
|
-
|
121
|
-
|
122
|
-
+ `filename` (`string`, required) - translation file name. If the file is stored under a subdirectory (for example, `nested/en.yml` inside the `locales/` directory), the whole path acts as a name. Later when importing files with such names, they will be placed into the proper subdirectories.
|
123
|
-
+ `lang_iso` (`string`, required) - language ISO code which is determined using the root key inside your YAML file. For example, in this case the `lang_iso` is `en_US`:
|
121
|
+
# Provide request timeouts for the Lokalise API client:
|
122
|
+
c.timeouts = {open_timeout: 5, timeout: 5}
|
124
123
|
|
125
|
-
|
126
|
-
|
127
|
-
my_key: "my value"
|
128
|
-
```
|
124
|
+
# Provide maximum number of retries for file exporting:
|
125
|
+
c.max_retries_export = 5
|
129
126
|
|
130
|
-
|
127
|
+
# Provide maximum number of retries for file importing:
|
128
|
+
c.max_retries_import = 5
|
131
129
|
|
132
|
-
|
130
|
+
# Import options have the following defaults:
|
131
|
+
# c.import_opts = {
|
132
|
+
# format: 'yaml',
|
133
|
+
# placeholder_format: :icu,
|
134
|
+
# yaml_include_root: true,
|
135
|
+
# original_filenames: true,
|
136
|
+
# directory_prefix: '',
|
137
|
+
# indentation: '2sp'
|
138
|
+
# }
|
133
139
|
|
134
|
-
|
135
|
-
c.
|
136
|
-
|
140
|
+
# Safe mode for imports is disabled by default:
|
141
|
+
# c.import_safe_mode = false
|
142
|
+
|
143
|
+
# Additional export options (only filename, contents, and lang_iso params are provided by default)
|
144
|
+
# c.export_opts = {}
|
145
|
+
|
146
|
+
# Provide additional file exclusion criteria for exports (by default, any file with the proper extension will be exported)
|
147
|
+
# c.skip_file_export = ->(file) { file.split[1].to_s.include?('fr') }
|
137
148
|
|
138
|
-
|
149
|
+
# Set the options below if you would like to work with format other than YAML
|
150
|
+
## Regular expression to use when choosing the files to extract from the downloaded archive and upload to Lokalise
|
151
|
+
## c.file_ext_regexp = /\.ya?ml\z/i
|
139
152
|
|
140
|
-
|
153
|
+
## Load translations data and make sure they are valid:
|
154
|
+
## c.translations_loader = ->(raw_data) { YAML.safe_load raw_data }
|
141
155
|
|
142
|
-
|
156
|
+
## Convert translations data to a proper format:
|
157
|
+
## c.translations_converter = ->(raw_data) { raw_data.to_yaml }
|
143
158
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
159
|
+
## Infer language ISO code for the translation file:
|
160
|
+
## c.lang_iso_inferer = ->(data) { YAML.safe_load(data)&.keys&.first }
|
161
|
+
end
|
162
|
+
```
|
148
163
|
|
149
164
|
## Running tests
|
150
165
|
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
LokaliseRails.config do |c|
|
3
|
+
LokaliseRails::GlobalConfig.config do |c|
|
6
4
|
# These are mandatory options that you must set before running rake tasks:
|
7
5
|
# c.api_token = ENV['LOKALISE_API_TOKEN']
|
8
6
|
# c.project_id = ENV['LOKALISE_PROJECT_ID']
|
@@ -11,7 +9,7 @@ LokaliseRails.config do |c|
|
|
11
9
|
# c.locales_path = "#{Rails.root}/config/locales"
|
12
10
|
|
13
11
|
# Provide a Lokalise project branch to use:
|
14
|
-
# c.branch = '
|
12
|
+
# c.branch = ''
|
15
13
|
|
16
14
|
# Provide request timeouts for the Lokalise API client:
|
17
15
|
# c.timeouts = {open_timeout: nil, timeout: nil}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
module LokaliseRails
|
6
|
+
module Utils
|
7
|
+
class << self
|
8
|
+
def root
|
9
|
+
Pathname.new(rails_root || Dir.getwd)
|
10
|
+
end
|
11
|
+
|
12
|
+
def rails_root
|
13
|
+
return ::Rails.root.to_s if defined?(::Rails.root) && ::Rails.root
|
14
|
+
return RAILS_ROOT.to_s if defined?(RAILS_ROOT)
|
15
|
+
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/lokalise_rails.rb
CHANGED
@@ -1,94 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'lokalise_rails/task_definition/base'
|
5
|
-
require 'lokalise_rails/task_definition/importer'
|
6
|
-
require 'lokalise_rails/task_definition/exporter'
|
3
|
+
require 'lokalise_manager'
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
attr_accessor :api_token, :project_id
|
11
|
-
attr_writer :import_opts, :import_safe_mode, :export_opts, :locales_path,
|
12
|
-
:file_ext_regexp, :skip_file_export, :branch, :timeouts,
|
13
|
-
:translations_loader, :translations_converter, :lang_iso_inferer,
|
14
|
-
:max_retries_export, :max_retries_import
|
15
|
-
|
16
|
-
# Main interface to provide configuration options for rake tasks
|
17
|
-
def config
|
18
|
-
yield self
|
19
|
-
end
|
20
|
-
|
21
|
-
# Full path to directory with translation files
|
22
|
-
def locales_path
|
23
|
-
@locales_path || "#{Rails.root}/config/locales"
|
24
|
-
end
|
25
|
-
|
26
|
-
# Project branch to use
|
27
|
-
def branch
|
28
|
-
@branch || 'master'
|
29
|
-
end
|
30
|
-
|
31
|
-
# Set request timeouts for the Lokalise API client
|
32
|
-
def timeouts
|
33
|
-
@timeouts || {}
|
34
|
-
end
|
35
|
-
|
36
|
-
# Maximum number of retries for file exporting
|
37
|
-
def max_retries_export
|
38
|
-
@max_retries_export || 5
|
39
|
-
end
|
40
|
-
|
41
|
-
# Maximum number of retries for file importing
|
42
|
-
def max_retries_import
|
43
|
-
@max_retries_import || 5
|
44
|
-
end
|
45
|
-
|
46
|
-
# Regular expression used to select translation files with proper extensions
|
47
|
-
def file_ext_regexp
|
48
|
-
@file_ext_regexp || /\.ya?ml\z/i
|
49
|
-
end
|
5
|
+
require 'lokalise_rails/utils'
|
6
|
+
require 'lokalise_rails/global_config'
|
50
7
|
|
51
|
-
|
52
|
-
def import_opts
|
53
|
-
@import_opts || {
|
54
|
-
format: 'yaml',
|
55
|
-
placeholder_format: :icu,
|
56
|
-
yaml_include_root: true,
|
57
|
-
original_filenames: true,
|
58
|
-
directory_prefix: '',
|
59
|
-
indentation: '2sp'
|
60
|
-
}
|
61
|
-
end
|
62
|
-
|
63
|
-
# Options for export rake task
|
64
|
-
def export_opts
|
65
|
-
@export_opts || {}
|
66
|
-
end
|
67
|
-
|
68
|
-
# Enables safe mode for import. When enabled, will check whether the target folder is empty or not
|
69
|
-
def import_safe_mode
|
70
|
-
@import_safe_mode.nil? ? false : @import_safe_mode
|
71
|
-
end
|
72
|
-
|
73
|
-
# Additional file skip criteria to apply when performing export
|
74
|
-
def skip_file_export
|
75
|
-
@skip_file_export || ->(_) { false }
|
76
|
-
end
|
77
|
-
|
78
|
-
def translations_loader
|
79
|
-
@translations_loader || ->(raw_data) { YAML.safe_load raw_data }
|
80
|
-
end
|
81
|
-
|
82
|
-
# Converts translations data to the proper format
|
83
|
-
def translations_converter
|
84
|
-
@translations_converter || ->(raw_data) { raw_data.to_yaml }
|
85
|
-
end
|
86
|
-
|
87
|
-
# Infers lang ISO for the given translation file
|
88
|
-
def lang_iso_inferer
|
89
|
-
@lang_iso_inferer || ->(data) { YAML.safe_load(data)&.keys&.first }
|
90
|
-
end
|
91
|
-
end
|
8
|
+
module LokaliseRails
|
92
9
|
end
|
93
10
|
|
94
11
|
require 'lokalise_rails/railtie' if defined?(Rails)
|
@@ -1,17 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'rake'
|
4
|
-
require
|
4
|
+
require 'lokalise_rails'
|
5
|
+
require "#{LokaliseRails::Utils.root}/config/lokalise_rails"
|
5
6
|
|
6
7
|
namespace :lokalise_rails do
|
7
8
|
task :import do
|
8
|
-
LokaliseRails::
|
9
|
+
importer = LokaliseManager.importer({}, LokaliseRails::GlobalConfig)
|
10
|
+
importer.import!
|
9
11
|
rescue StandardError => e
|
10
12
|
abort e.inspect
|
11
13
|
end
|
12
14
|
|
13
15
|
task :export do
|
14
|
-
LokaliseRails::
|
16
|
+
exporter = LokaliseManager.exporter({}, LokaliseRails::GlobalConfig)
|
17
|
+
exporter.export!
|
15
18
|
rescue StandardError => e
|
16
19
|
abort e.inspect
|
17
20
|
end
|
data/lokalise_rails.gemspec
CHANGED
@@ -23,13 +23,12 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.extra_rdoc_files = ['README.md']
|
24
24
|
spec.require_paths = ['lib']
|
25
25
|
|
26
|
-
spec.add_dependency '
|
27
|
-
spec.add_dependency 'rubyzip', '~> 2.3'
|
26
|
+
spec.add_dependency 'lokalise_manager', '~> 1.0'
|
28
27
|
|
29
28
|
spec.add_development_dependency 'codecov', '~> 0.2'
|
30
29
|
spec.add_development_dependency 'dotenv', '~> 2.5'
|
31
30
|
if ENV['TEST_RAILS_VERSION'].nil?
|
32
|
-
spec.add_development_dependency 'rails', '~> 6.1.
|
31
|
+
spec.add_development_dependency 'rails', '~> 6.1.4'
|
33
32
|
else
|
34
33
|
spec.add_development_dependency 'rails', ENV['TEST_RAILS_VERSION'].to_s
|
35
34
|
end
|
@@ -37,7 +36,7 @@ Gem::Specification.new do |spec|
|
|
37
36
|
spec.add_development_dependency 'rspec', '~> 3.6'
|
38
37
|
spec.add_development_dependency 'rubocop', '~> 1.0'
|
39
38
|
spec.add_development_dependency 'rubocop-performance', '~> 1.5'
|
40
|
-
spec.add_development_dependency 'rubocop-rspec', '~> 2.
|
39
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 2.5.0'
|
41
40
|
spec.add_development_dependency 'simplecov', '~> 0.16'
|
42
41
|
spec.add_development_dependency 'vcr', '~> 6.0'
|
43
42
|
end
|
@@ -0,0 +1,117 @@
|
|
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
|