lokalise_rails 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09902a3883dec5ff5390383ef2770947547955202c759d794809616c3713bb5e'
4
- data.tar.gz: 1f21ca62432cbdd640286419d2964b87ab4398b91efa505a8e00b284842e39bf
3
+ metadata.gz: 87524123a10425d69c33950f4b2c16366146f5c1ab14c19dbc7185de61fb726a
4
+ data.tar.gz: 39ba0b0a91f443ea162d7804c89906f4523f7c13411fbd541624bafb9197a569
5
5
  SHA512:
6
- metadata.gz: 74105425483dd2371140b27771a050e912173756a65e732289ce991a0c6513f58b4bfdc1a2bbeee4ecef75054226976034edd46447cc0b60857215e689a15d1f
7
- data.tar.gz: 0176b8f37389c4699fdc620c57c17bfa2143f1dd5fc1f3914e953f90a6a4e9434899bab1df53eb6f359928174089a8791cff75e3544bcae0a4b3c8602f844680
6
+ metadata.gz: 4e36f385c123ab80402aaa428973c2c0706b2cbceabade8bcf12689fe0955bdc927a223c27a9114c102d83af6a709b061e1c10d2e189ca832b5b56a0a6b043f8
7
+ data.tar.gz: bbbe1857d99cdc7c3595f611d664c555981fbdf5f1d37c30a52cb179d641902f879b1492996dc7c1c1cb6dacdfbd7c2a3ca226f31a687879fddf59b1e8f9fe7a
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.0 (01-Oct-20)
4
+
5
+ * Added export feature
6
+ * More convenient configuration and additional options
7
+ * Other major enhancements
8
+
9
+ ## 0.2.0 (26-Sep-20)
10
+
11
+ * Allow to override options properly
12
+
3
13
  ## 0.1.0 (26-Sep-20)
4
14
 
5
15
  * Initial (proper) release
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # LokaliseRails
2
2
 
3
- <!-- [![Gem Version](https://badge.fury.io/rb/ruby-lokalise-api.svg)](https://badge.fury.io/rb/ruby-lokalise-api) -->
3
+ [![Gem Version](https://badge.fury.io/rb/lokalise_rails.svg)](https://badge.fury.io/rb/lokalise_rails)
4
4
  [![Build Status](https://travis-ci.org/bodrovis/lokalise_rails.svg?branch=master)](https://travis-ci.org/bodrovis/lokalise_rails)
5
5
  [![Test Coverage](https://codecov.io/gh/bodrovis/lokalise_rails/graph/badge.svg)](https://codecov.io/gh/bodrovis/lokalise_rails)
6
6
 
@@ -10,17 +10,17 @@ This gem provides [Lokalise](http://lokalise.com) integration for Ruby on Rails
10
10
 
11
11
  ### Requirements
12
12
 
13
- This gem requires Ruby 2.5+ and Rails 5.1+. It might work with older versions of Rails though. You will also need to setup a Lokalise account and a translation project. Finally, you will need to generate a read/write API token at your Lokalise profile.
13
+ This gem requires Ruby 2.5+ 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.
14
14
 
15
15
  ### Installation
16
16
 
17
- Add the gem to your `Gemfile`
17
+ Add the gem to your `Gemfile`:
18
18
 
19
19
  ```ruby
20
20
  gem 'lokalise_rails'
21
21
  ```
22
22
 
23
- and run
23
+ and run:
24
24
 
25
25
  ```
26
26
  bundle install
@@ -32,12 +32,17 @@ The latter command will generate a new config file `config/lokalise_rails.rb` lo
32
32
  ```ruby
33
33
  require 'lokalise_rails'
34
34
 
35
- LokaliseRails.api_token = ENV['LOKALISE_API_TOKEN']
36
- LokaliseRails.project_id = ENV['LOKALISE_PROJECT_ID']
37
- # ...
35
+ LokaliseRails.config do |c|
36
+ c.api_token = ENV['LOKALISE_API_TOKEN']
37
+ c.project_id = ENV['LOKALISE_PROJECT_ID']
38
+
39
+ # ...other options
40
+ end
38
41
  ```
39
42
 
40
- You have to provide `api_token` and `project_id` to proceed. [Other options can be customized as well (see below)](https://github.com/bodrovis/lokalise_rails#import-settings) but they have sensible defaults.
43
+ You have to provide `api_token` and `project_id` to proceed. `project_id` can be found in your Lokalise project settings.
44
+
45
+ [Other options can be customized as well (see below)](https://github.com/bodrovis/lokalise_rails#import-settings) but they have sensible defaults.
41
46
 
42
47
  ## Importing translations from Lokalise
43
48
 
@@ -47,7 +52,15 @@ To import translations from the specified Lokalise project to your Rails app, ru
47
52
  rails lokalise_rails:import
48
53
  ```
49
54
 
50
- Please note that any existing files inside the `locales` directory will be overwritten! You may enable [safe mode](https://github.com/bodrovis/lokalise_rails#import-settings) to check whether the folder is empty or not.
55
+ 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 may enable [safe mode](https://github.com/bodrovis/lokalise_rails#import-settings) to check whether the folder is empty or not.
56
+
57
+ ## Exporting translations to Lokalise
58
+
59
+ To export translations from your Rails app to the specified Lokalise project, run the following command:
60
+
61
+ ```
62
+ rails lokalise_rails:export
63
+ ```
51
64
 
52
65
  ## Configuration
53
66
 
@@ -55,23 +68,14 @@ Options are specified in the `config/lokalise_rails.rb` file.
55
68
 
56
69
  ### Global settings
57
70
 
58
- * `LokaliseRails.api_token` (`string`, required) - Lokalise API token with read/write permissions.
59
- * `LokaliseRails.project_id` (`string`, required) - Lokalise project ID. You must have import/export permissions in the specified project.
60
- * `locales_path` - method returning a string with the path to your translation files. Defaults to `"#{Rails.root}/config/locales"`. To provide a custom path, override the method inside the initializer (make sure that the path exists!):
61
-
62
- ```ruby
63
- class LokaliseRails
64
- class << self
65
- def locales_path
66
- "#{Rails.root}/config/locales_custom"
67
- end
68
- end
69
- end
70
- ```
71
+ * `api_token` (`string`, required) - Lokalise API token with read/write permissions.
72
+ * `project_id` (`string`, required) - Lokalise project ID. You must have import/export permissions in the specified project.
73
+ * `locales_path` (`string`) - path to the directory with your translation files. Defaults to `"#{Rails.root}/config/locales"`.
74
+ * `file_ext_regexp` (`regexp`) - regular expression applied to file extensions to determine which files should be imported and exported. Defaults to `/\.ya?ml\z/i` (YAML files).
71
75
 
72
76
  ### Import settings
73
77
 
74
- * `LokaliseRails.import_opts` (`hash`) - options that will be passed to Lokalise API when downloading translations to your app. Here are the default options:
78
+ * `import_opts` (`hash`) - options that will be passed to Lokalise API when downloading translations to your app. Here are the default options:
75
79
 
76
80
  ```ruby
77
81
  {
@@ -84,8 +88,28 @@ end
84
88
  }
85
89
  ```
86
90
 
87
- Full list of available options [can be found at the official API documentation](https://app.lokalise.com/api2docs/curl/#transition-download-files-post).
88
- * `LokaliseRails.import_safe_mode` (`boolean`) - default to `false`. When this option is enabled, the import task will check whether the `locales` directory is empty or not. If it is not empty, you will be prompted to continue.
91
+ Full list of available import options [can be found in the official API documentation](https://app.lokalise.com/api2docs/curl/#transition-download-files-post).
92
+ * `import_safe_mode` (`boolean`) - default to `false`. When this option is enabled, the import task will check whether the directory set with `locales_path` is empty or not. If it is not empty, you will be prompted to continue.
93
+
94
+ ### Export settings
95
+
96
+ * `export_opts` (`hash`) - options that will be passed to Lokalise API when uploading translations. Full list of available export options [can be found in the official documentation](https://app.lokalise.com/api2docs/curl/#transition-download-files-post). By default, the following options are provided:
97
+ + `data` (`string`, required) - base64-encoded contents of the translation file.
98
+ + `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.
99
+ + `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`:
100
+
101
+ ```yaml
102
+ en_US:
103
+ my_key: "my value"
104
+ ```
105
+
106
+ **Please note** that if your Lokalise project does not have a language with the specified `lang_iso` code, the export will fail.
107
+
108
+ * `skip_file_export` (`lambda` or `proc`) - specify additional exclusion criteria for the exported files. By default, the rake task will ignore all non-file entries and all files with improper extensions (the latter is controlled by the `file_ext_regexp`). Lambda passed to this option should accept a single argument which is full path to the file (instance of the [`Pathname` class](https://ruby-doc.org/stdlib-2.7.1/libdoc/pathname/rdoc/Pathname.html)). For example, to exclude all files that have `fr` part in their names, add the following config:
109
+
110
+ ```ruby
111
+ c.skip_file_export = ->(file) { f.split[1].to_s.include?('fr') }
112
+ ```
89
113
 
90
114
  ## License
91
115
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'rails/generators'
4
4
 
5
- class LokaliseRails
5
+ module LokaliseRails
6
6
  module Generators
7
7
  class InstallGenerator < Rails::Generators::Base
8
8
  source_root File.expand_path('../templates', __dir__)
@@ -2,28 +2,33 @@
2
2
 
3
3
  require 'lokalise_rails'
4
4
 
5
- # These are mandatory options that you must set before running rake tasks:
6
- LokaliseRails.api_token = ENV['LOKALISE_API_TOKEN']
7
- LokaliseRails.project_id = ENV['LOKALISE_PROJECT_ID']
8
-
9
- # Import options have the following defaults:
10
- # LokaliseRails.import_opts = {
11
- # format: 'yaml',
12
- # placeholder_format: :icu,
13
- # yaml_include_root: true,
14
- # original_filenames: true,
15
- # directory_prefix: '',
16
- # indentation: '2sp'
17
- # }
18
-
19
- # Safe mode is disabled by default:
20
- # LokaliseRails.import_safe_mode = false
21
-
22
- # Provide a custom path to the directory with your translation files:
23
- # class LokaliseRails
24
- # class << self
25
- # def locales_path
26
- # "#{Rails.root}/config/locales"
27
- # end
28
- # end
29
- # end
5
+ LokaliseRails.config do |c|
6
+ # These are mandatory options that you must set before running rake tasks:
7
+ # c.api_token = ENV['LOKALISE_API_TOKEN']
8
+ # c.project_id = ENV['LOKALISE_PROJECT_ID']
9
+
10
+ # Provide a custom path to the directory with your translation files:
11
+ # c.locales_path = "#{Rails.root}/config/locales"
12
+
13
+ # Import options have the following defaults:
14
+ # c.import_opts = {
15
+ # format: 'yaml',
16
+ # placeholder_format: :icu,
17
+ # yaml_include_root: true,
18
+ # original_filenames: true,
19
+ # directory_prefix: '',
20
+ # indentation: '2sp'
21
+ # }
22
+
23
+ # Safe mode for imports is disabled by default:
24
+ # c.import_safe_mode = false
25
+
26
+ # Additional export options (only filename, contents, and lang_iso params are provided by default)
27
+ # c.export_opts = {}
28
+
29
+ # Provide additional file exclusion criteria for exports (by default, any file with the proper extension will be exported)
30
+ # c.skip_file_export = ->(file) { file.split[1].to_s.include?('fr') }
31
+
32
+ # Regular expression to use when choosing the files to extract from the downloaded archive and upload to Lokalise
33
+ # c.file_ext_regexp = /\.ya?ml\z/i
34
+ end
@@ -2,29 +2,54 @@
2
2
 
3
3
  require 'lokalise_rails/task_definition/base'
4
4
  require 'lokalise_rails/task_definition/importer'
5
+ require 'lokalise_rails/task_definition/exporter'
5
6
 
6
- class LokaliseRails
7
- @project_id = nil
8
- @import_opts = {
9
- format: 'yaml',
10
- placeholder_format: :icu,
11
- yaml_include_root: true,
12
- original_filenames: true,
13
- directory_prefix: '',
14
- indentation: '2sp'
15
- }
16
- # @export_opts = {
17
- #
18
- # }
19
- @import_safe_mode = false
20
- @api_token = nil
21
-
7
+ module LokaliseRails
22
8
  class << self
23
- attr_accessor :import_opts, :import_safe_mode, :api_token, :export_opts,
24
- :project_id
9
+ attr_accessor :api_token, :project_id
10
+ attr_writer :import_opts, :import_safe_mode, :export_opts, :locales_path,
11
+ :file_ext_regexp, :skip_file_export
12
+
13
+ # Main interface to provide configuration options for rake tasks
14
+ def config
15
+ yield self
16
+ end
25
17
 
18
+ # Full path to directory with translation files
26
19
  def locales_path
27
- "#{Rails.root}/config/locales"
20
+ @locales_path || "#{Rails.root}/config/locales"
21
+ end
22
+
23
+ # Regular expression used to select translation files with proper extensions
24
+ def file_ext_regexp
25
+ @file_ext_regexp || /\.ya?ml\z/i
26
+ end
27
+
28
+ # Options for import rake task
29
+ def import_opts
30
+ @import_opts || {
31
+ format: 'yaml',
32
+ placeholder_format: :icu,
33
+ yaml_include_root: true,
34
+ original_filenames: true,
35
+ directory_prefix: '',
36
+ indentation: '2sp'
37
+ }
38
+ end
39
+
40
+ # Options for export rake task
41
+ def export_opts
42
+ @export_opts || {}
43
+ end
44
+
45
+ # Enables safe mode for import. When enabled, will check whether the target folder is empty or not
46
+ def import_safe_mode
47
+ @import_safe_mode.nil? ? false : @import_safe_mode
48
+ end
49
+
50
+ # Additional file skip criteria to apply when performing export
51
+ def skip_file_export
52
+ @skip_file_export || ->(_) { false }
28
53
  end
29
54
  end
30
55
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'rake'
4
4
 
5
- class LokaliseRails
5
+ module LokaliseRails
6
6
  class Railtie < Rails::Railtie
7
7
  rake_tasks do
8
8
  load 'tasks/lokalise_rails_tasks.rake'
@@ -1,21 +1,48 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'ruby-lokalise-api'
4
- require 'open-uri'
4
+ require 'pathname'
5
5
 
6
- class LokaliseRails
6
+ module LokaliseRails
7
7
  module TaskDefinition
8
8
  class Base
9
9
  class << self
10
- def check_required_opts
11
- return [
12
- false, 'Project ID is not set! Aborting...'
13
- ] if LokaliseRails.project_id.nil? || LokaliseRails.project_id.empty?
14
- return [
15
- false, 'Lokalise API token is not set! Aborting...'
16
- ] if LokaliseRails.api_token.nil? || LokaliseRails.api_token.empty?
10
+ attr_writer :api_client
17
11
 
18
- [true, '']
12
+ # Creates a Lokalise API client
13
+ #
14
+ # @return [Lokalise::Client]
15
+ def api_client
16
+ @api_client ||= ::Lokalise.client LokaliseRails.api_token
17
+ end
18
+
19
+ # Checks task options
20
+ #
21
+ # @return Array
22
+ def opt_errors
23
+ errors = []
24
+ errors << 'Project ID is not set! Aborting...' if LokaliseRails.project_id.nil? || LokaliseRails.project_id.empty?
25
+ errors << 'Lokalise API token is not set! Aborting...' if LokaliseRails.api_token.nil? || LokaliseRails.api_token.empty?
26
+ errors
27
+ end
28
+
29
+ private
30
+
31
+ # Checks whether the provided file has a proper extension as dictated by the `file_ext_regexp` option
32
+ #
33
+ # @return Boolean
34
+ # @param raw_path [String, Pathname]
35
+ def proper_ext?(raw_path)
36
+ path = raw_path.is_a?(Pathname) ? raw_path : Pathname.new(raw_path)
37
+ LokaliseRails.file_ext_regexp.match? path.extname
38
+ end
39
+
40
+ # Returns directory and filename for the given entry
41
+ #
42
+ # @return Array
43
+ # @param entry [String]
44
+ def subdir_and_filename_for(entry)
45
+ Pathname.new(entry).split
19
46
  end
20
47
  end
21
48
  end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'base64'
4
+
5
+ module LokaliseRails
6
+ module TaskDefinition
7
+ class Exporter < Base
8
+ class << self
9
+ # Performs translation file export from Rails to Lokalise and returns an array of queued processes
10
+ #
11
+ # @return [Array]
12
+ def export!
13
+ errors = opt_errors
14
+
15
+ if errors.any?
16
+ errors.each { |e| $stdout.puts e }
17
+ return false
18
+ end
19
+
20
+ queued_processes = []
21
+ each_file do |full_path, relative_path|
22
+ queued_processes << api_client.upload_file(
23
+ LokaliseRails.project_id, opts(full_path, relative_path)
24
+ )
25
+ rescue StandardError => e
26
+ $stdout.puts "Error while trying to upload #{full_path}: #{e.inspect}"
27
+ end
28
+
29
+ $stdout.print 'Task complete!'
30
+
31
+ queued_processes
32
+ end
33
+
34
+ # Processes each translation file in the specified directory
35
+ def each_file
36
+ return unless block_given?
37
+
38
+ loc_path = LokaliseRails.locales_path
39
+ Dir["#{loc_path}/**/*"].sort.each do |f|
40
+ full_path = Pathname.new f
41
+
42
+ next unless file_matches_criteria? full_path
43
+
44
+ relative_path = full_path.relative_path_from Pathname.new(loc_path)
45
+
46
+ yield full_path, relative_path
47
+ end
48
+ end
49
+
50
+ # Generates export options
51
+ #
52
+ # @return [Hash]
53
+ # @param full_p [Pathname]
54
+ # @param relative_p [Pathname]
55
+ def opts(full_p, relative_p)
56
+ content = File.read full_p
57
+
58
+ lang_iso = YAML.safe_load(content)&.keys&.first
59
+
60
+ initial_opts = {
61
+ data: Base64.strict_encode64(content.strip),
62
+ filename: relative_p,
63
+ lang_iso: lang_iso
64
+ }
65
+
66
+ initial_opts.merge LokaliseRails.export_opts
67
+ end
68
+
69
+ # Checks whether the specified file has to be processed or not
70
+ #
71
+ # @return [Boolean]
72
+ # @param full_path [Pathname]
73
+ def file_matches_criteria?(full_path)
74
+ full_path.file? && proper_ext?(full_path) &&
75
+ !LokaliseRails.skip_file_export.call(full_path)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -1,42 +1,84 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class LokaliseRails
3
+ require 'zip'
4
+ require 'yaml'
5
+ require 'open-uri'
6
+ require 'fileutils'
7
+
8
+ module LokaliseRails
4
9
  module TaskDefinition
5
10
  class Importer < Base
6
11
  class << self
12
+ # Performs translation files import from Lokalise to Rails app
13
+ #
14
+ # @return [Boolean]
7
15
  def import!
8
- status_ok, msg = check_required_opts
9
- return msg unless status_ok
10
- return 'Task cancelled!' unless proceed_when_safe_mode?
16
+ errors = opt_errors
17
+
18
+ if errors.any?
19
+ errors.each { |e| $stdout.puts e }
20
+ return false
21
+ end
22
+
23
+ unless proceed_when_safe_mode?
24
+ $stdout.print 'Task cancelled!'
25
+ return false
26
+ end
11
27
 
12
28
  open_and_process_zip download_files['bundle_url']
13
29
 
14
- 'Task complete!'
30
+ $stdout.print 'Task complete!'
31
+ true
15
32
  end
16
33
 
34
+ # Downloads files from Lokalise using the specified options
35
+ #
36
+ # @return [Hash]
17
37
  def download_files
18
- client = ::Lokalise.client LokaliseRails.api_token
19
38
  opts = LokaliseRails.import_opts
20
39
 
21
- client.download_files LokaliseRails.project_id, opts
40
+ api_client.download_files LokaliseRails.project_id, opts
41
+ rescue StandardError => e
42
+ $stdout.puts "There was an error when trying to download files: #{e.inspect}"
22
43
  end
23
44
 
45
+ # Opens ZIP archive (local or remote) with translations and processes its entries
46
+ #
47
+ # @param path [String]
24
48
  def open_and_process_zip(path)
25
- Zip::File.open_buffer(URI.open(path)) { |zip| process_zip zip }
49
+ Zip::File.open_buffer(URI.open(path)) do |zip|
50
+ fetch_zip_entries(zip) { |entry| process!(entry) }
51
+ end
26
52
  end
27
53
 
28
- def process_zip(zip)
54
+ # Iterates over ZIP entries. Each entry may be a file or folder.
55
+ def fetch_zip_entries(zip)
56
+ return unless block_given?
57
+
29
58
  zip.each do |entry|
30
- next unless /\.ya?ml/.match?(entry.name)
59
+ next unless proper_ext? entry.name
60
+
61
+ yield entry
62
+ end
63
+ end
64
+
65
+ # Processes ZIP entry by reading its contents and creating the corresponding translation file
66
+ def process!(zip_entry)
67
+ data = YAML.safe_load zip_entry.get_input_stream.read
68
+ subdir, filename = subdir_and_filename_for zip_entry.name
69
+ full_path = "#{LokaliseRails.locales_path}/#{subdir}"
70
+ FileUtils.mkdir_p full_path
31
71
 
32
- filename = entry.name.include?('/') ? entry.name.split('/')[1] : entry.name
33
- data = YAML.safe_load entry.get_input_stream.read
34
- File.open("#{LokaliseRails.locales_path}/#{filename}", 'w+:UTF-8') do |f|
35
- f.write(data.to_yaml)
36
- end
72
+ File.open(File.join(full_path, filename), 'w+:UTF-8') do |f|
73
+ f.write data.to_yaml
37
74
  end
75
+ rescue StandardError => e
76
+ $stdout.puts "Error when trying to process #{zip_entry&.name}: #{e.inspect}"
38
77
  end
39
78
 
79
+ # Checks whether the user wishes to proceed when safe mode is enabled and the target directory is not empty
80
+ #
81
+ # @return [Boolean]
40
82
  def proceed_when_safe_mode?
41
83
  return true unless LokaliseRails.import_safe_mode && !Dir.empty?(LokaliseRails.locales_path.to_s)
42
84
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class LokaliseRails
4
- VERSION = '0.2.0'
3
+ module LokaliseRails
4
+ VERSION = '1.0.0'
5
5
  end
@@ -1,15 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rake'
4
- require 'ruby-lokalise-api'
5
- require 'zip'
6
- require 'open-uri'
7
- require 'yaml'
8
4
  require "#{Rails.root}/config/lokalise_rails"
9
5
 
10
6
  namespace :lokalise_rails do
11
7
  task :import do
12
- msg = LokaliseRails::TaskDefinition::Importer.import!
13
- $stdout.print msg
8
+ LokaliseRails::TaskDefinition::Importer.import!
9
+ end
10
+
11
+ task :export do
12
+ LokaliseRails::TaskDefinition::Exporter.export!
14
13
  end
15
14
  end
@@ -40,6 +40,5 @@ Gem::Specification.new do |spec|
40
40
  spec.add_development_dependency 'rubocop-performance', '~> 1.5'
41
41
  spec.add_development_dependency 'rubocop-rspec', '~> 1.37'
42
42
  spec.add_development_dependency 'simplecov', '~> 0.16'
43
- spec.add_development_dependency 'sqlite3', '~> 1.4'
44
43
  spec.add_development_dependency 'vcr', '~> 6.0'
45
44
  end
@@ -4,9 +4,9 @@ require_relative 'boot'
4
4
 
5
5
  require 'rails'
6
6
  # Pick the frameworks you want:
7
- require 'active_model/railtie'
7
+ # require 'active_model/railtie'
8
8
  # require "active_job/railtie"
9
- require 'active_record/railtie'
9
+ # require 'active_record/railtie'
10
10
  # require "active_storage/engine"
11
11
  require 'action_controller/railtie'
12
12
  # require "action_mailer/railtie"
@@ -1,29 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
1
  require 'lokalise_rails'
4
-
5
- # These are mandatory options that you must set before running rake tasks:
6
- LokaliseRails.api_token = ENV['LOKALISE_API_TOKEN']
7
- LokaliseRails.project_id = ENV['LOKALISE_PROJECT_ID']
8
-
9
- # Import options have the following defaults:
10
- # LokaliseRails.import_opts = {
11
- # format: 'yaml',
12
- # placeholder_format: :icu,
13
- # yaml_include_root: true,
14
- # original_filenames: true,
15
- # directory_prefix: '',
16
- # indentation: '2sp'
17
- # }
18
-
19
- # Safe mode is disabled by default:
20
- # LokaliseRails.import_safe_mode = false
21
-
22
- # Provide a custom path to the directory with your translation files:
23
- # class LokaliseRails
24
- # class << self
25
- # def locales_path
26
- # "#{Rails.root}/config/locales"
27
- # end
28
- # end
29
- # end
2
+ LokaliseRails.config do |c|
3
+ c.api_token = ENV['LOKALISE_API_TOKEN']
4
+ c.project_id = ENV['LOKALISE_PROJECT_ID']
5
+ end
@@ -9,7 +9,7 @@ describe LokaliseRails::Generators::InstallGenerator do
9
9
 
10
10
  after :all do
11
11
  remove_config
12
- described_class.start
12
+ add_config!
13
13
  end
14
14
 
15
15
  it 'installs config file properly' do
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'base64'
4
+
5
+ describe LokaliseRails::TaskDefinition::Exporter do
6
+ let(:filename) { 'en.yml' }
7
+ let(:path) { "#{Rails.root}/config/locales/nested/#{filename}" }
8
+ let(:relative_name) { "nested/#{filename}" }
9
+
10
+ context 'with one translation file' do
11
+ before :all do
12
+ add_translation_files!
13
+ end
14
+
15
+ after :all do
16
+ rm_translation_files
17
+ end
18
+
19
+ describe '.export!' do
20
+ it 'sends a proper API request' do
21
+ process = VCR.use_cassette('upload_files') do
22
+ described_class.export!
23
+ end.first
24
+
25
+ expect(process.project_id).to eq(LokaliseRails.project_id)
26
+ expect(process.status).to eq('queued')
27
+ end
28
+
29
+ it 'halts when the API key is not set' do
30
+ expect(LokaliseRails).to receive(:api_token).and_return(nil)
31
+ expect(described_class).not_to receive(:each_file)
32
+ expect(-> { described_class.export! }).to output(/API token is not set/).to_stdout
33
+ end
34
+
35
+ it 'halts when the project_id is not set' do
36
+ expect(LokaliseRails).to receive(:project_id).and_return(nil)
37
+ expect(described_class).not_to receive(:each_file)
38
+ expect(-> { described_class.export! }).to output(/Project ID is not set/).to_stdout
39
+ end
40
+ end
41
+
42
+ describe '.each_file' do
43
+ it 'yield proper arguments' do
44
+ expect { |b| described_class.each_file(&b) }.to yield_with_args(
45
+ Pathname.new(path),
46
+ Pathname.new(relative_name)
47
+ )
48
+ end
49
+ end
50
+
51
+ describe '.opts' do
52
+ let(:base64content) { Base64.strict_encode64(File.read(path).strip) }
53
+
54
+ it 'generates proper options' do
55
+ resulting_opts = described_class.opts(path, relative_name)
56
+
57
+ expect(resulting_opts[:data]).to eq(base64content)
58
+ expect(resulting_opts[:filename]).to eq(relative_name)
59
+ expect(resulting_opts[:lang_iso]).to eq('en')
60
+ end
61
+
62
+ it 'allows to redefine options' do
63
+ expect(LokaliseRails).to receive(:export_opts).and_return({
64
+ detect_icu_plurals: true,
65
+ convert_placeholders: true
66
+ })
67
+
68
+ resulting_opts = described_class.opts(path, relative_name)
69
+
70
+ expect(resulting_opts[:data]).to eq(base64content)
71
+ expect(resulting_opts[:filename]).to eq(relative_name)
72
+ expect(resulting_opts[:lang_iso]).to eq('en')
73
+ expect(resulting_opts[:detect_icu_plurals]).to be true
74
+ expect(resulting_opts[:convert_placeholders]).to be true
75
+ end
76
+ end
77
+ end
78
+
79
+ context 'with two translation files' do
80
+ let(:filename_ru) { 'ru.yml' }
81
+ let(:path_ru) { "#{Rails.root}/config/locales/#{filename_ru}" }
82
+ let(:relative_name_ru) { filename_ru }
83
+
84
+ before :all do
85
+ add_translation_files! with_ru: true
86
+ end
87
+
88
+ after :all do
89
+ rm_translation_files
90
+ end
91
+
92
+ describe '.export!' do
93
+ it 'rescues from export errors' do
94
+ processes = VCR.use_cassette('upload_files_error') do
95
+ described_class.export!
96
+ end
97
+
98
+ expect(processes.length).to eq(1)
99
+ process = processes.first
100
+ expect(process.project_id).to eq(LokaliseRails.project_id)
101
+ expect(process.status).to eq('queued')
102
+ end
103
+ end
104
+
105
+ describe '.opts' do
106
+ let(:base64content_ru) { Base64.strict_encode64(File.read(path_ru).strip) }
107
+
108
+ it 'generates proper options' do
109
+ resulting_opts = described_class.opts(path_ru, relative_name_ru)
110
+
111
+ expect(resulting_opts[:data]).to eq(base64content_ru)
112
+ expect(resulting_opts[:filename]).to eq(relative_name_ru)
113
+ expect(resulting_opts[:lang_iso]).to eq('ru_RU')
114
+ end
115
+ end
116
+
117
+ describe '.each_file' do
118
+ it 'yields every translation file' do
119
+ expect { |b| described_class.each_file(&b) }.to yield_successive_args(
120
+ [
121
+ Pathname.new(path),
122
+ Pathname.new(relative_name)
123
+ ],
124
+ [
125
+ Pathname.new(path_ru),
126
+ Pathname.new(relative_name_ru)
127
+ ]
128
+ )
129
+ end
130
+
131
+ it 'does not yield files that have to be skipped' do
132
+ expect(LokaliseRails).to receive(:skip_file_export).twice.and_return(
133
+ ->(f) { f.split[1].to_s.include?('ru') }
134
+ )
135
+ expect { |b| described_class.each_file(&b) }.to yield_successive_args(
136
+ [
137
+ Pathname.new(path),
138
+ Pathname.new(relative_name)
139
+ ]
140
+ )
141
+ end
142
+ end
143
+ end
144
+ end
@@ -1,6 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  describe LokaliseRails::TaskDefinition::Importer do
4
+ describe '.open_and_process_zip' do
5
+ let(:faulty_trans) { "#{Rails.root}/public/faulty_trans.zip" }
6
+
7
+ it 'rescues from errors during file processing' do
8
+ expect(-> { described_class.open_and_process_zip(faulty_trans) }).
9
+ to output(/Psych::DisallowedClass/).to_stdout
10
+ end
11
+ end
12
+
4
13
  describe '.download_files' do
5
14
  it 'returns a proper download URL' do
6
15
  expect(LokaliseRails).to receive(:project_id).and_return('189934715f57a162257d74.88352370')
@@ -11,20 +20,27 @@ describe LokaliseRails::TaskDefinition::Importer do
11
20
  expect(response['project_id']).to eq('189934715f57a162257d74.88352370')
12
21
  expect(response['bundle_url']).to include('s3-eu-west-1.amazonaws.com')
13
22
  end
23
+
24
+ it 'rescues from errors during file download' do
25
+ allow(LokaliseRails).to receive(:api_token).and_return('incorrect')
26
+
27
+ VCR.use_cassette('download_files_error') do
28
+ expect(-> { described_class.download_files }).
29
+ to output(/Lokalise::Error::BadRequest/).to_stdout
30
+ end
31
+ end
14
32
  end
15
33
 
16
34
  describe '.import!' do
17
35
  it 'halts when the API key is not set' do
18
36
  expect(LokaliseRails).to receive(:api_token).and_return(nil)
19
- result = described_class.import!
20
- expect(result).to include('API token is not set')
37
+ expect(-> {described_class.import!}).to output(/API token is not set/).to_stdout
21
38
  expect(count_translations).to eq(0)
22
39
  end
23
40
 
24
41
  it 'halts when the project_id is not set' do
25
42
  expect(LokaliseRails).to receive(:project_id).and_return(nil)
26
- result = described_class.import!
27
- expect(result).to include('Project ID is not set')
43
+ expect(-> {described_class.import!}).to output(/Project ID is not set/).to_stdout
28
44
  expect(count_translations).to eq(0)
29
45
  end
30
46
  end
@@ -1,10 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  describe LokaliseRails do
4
- it 'should return a proper version' do
4
+ it 'returns a proper version' do
5
5
  expect(LokaliseRails::VERSION).to be_a(String)
6
6
  end
7
7
 
8
+ it 'is possible to provide config options' do
9
+ described_class.config do |c|
10
+ expect(c).to eq(described_class)
11
+ end
12
+ end
13
+
8
14
  describe 'parameters' do
9
15
  let(:fake_class) { class_double('LokaliseRails') }
10
16
 
@@ -13,6 +19,11 @@ describe LokaliseRails do
13
19
  fake_class.project_id = '123.abc'
14
20
  end
15
21
 
22
+ it 'is possible to set file_ext_regexp' do
23
+ expect(fake_class).to receive(:file_ext_regexp=).with(Regexp.new('.*'))
24
+ fake_class.file_ext_regexp = Regexp.new('.*')
25
+ end
26
+
16
27
  it 'is possible to set import_opts' do
17
28
  expect(fake_class).to receive(:import_opts=).with(duck_type(:each))
18
29
  fake_class.import_opts = {
@@ -21,6 +32,14 @@ describe LokaliseRails do
21
32
  }
22
33
  end
23
34
 
35
+ it 'is possible to set export_opts' do
36
+ expect(fake_class).to receive(:export_opts=).with(duck_type(:each))
37
+ fake_class.export_opts = {
38
+ convert_placeholders: true,
39
+ detect_icu_plurals: true
40
+ }
41
+ end
42
+
24
43
  it 'is possible to set import_safe_mode' do
25
44
  expect(fake_class).to receive(:import_safe_mode=).with(true)
26
45
  fake_class.import_safe_mode = true
@@ -32,9 +51,14 @@ describe LokaliseRails do
32
51
  end
33
52
 
34
53
  it 'is possible to override locales_path' do
35
- expect(fake_class).to receive(:locales_path).and_return('/demo/path')
54
+ expect(fake_class).to receive(:locales_path=).with('/demo/path')
55
+ fake_class.locales_path = '/demo/path'
56
+ end
36
57
 
37
- expect(fake_class.locales_path).to eq('/demo/path')
58
+ it 'is possible to set skip_file_export' do
59
+ cond = ->(f) { f.nil? }
60
+ expect(fake_class).to receive(:skip_file_export=).with(cond)
61
+ fake_class.skip_file_export = cond
38
62
  end
39
63
  end
40
64
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe LokaliseRails do
4
+ it 'runs export rake task properly' do
5
+ expect(export_executor).to output(/complete!/).to_stdout
6
+ end
7
+ end
@@ -3,6 +3,10 @@
3
3
  require 'fileutils'
4
4
 
5
5
  RSpec.describe LokaliseRails do
6
+ let(:loc_path) { described_class.locales_path }
7
+ let(:local_trans) { "#{Rails.root}/public/trans.zip" }
8
+ let(:remote_trans) { 'https://github.com/bodrovis/lokalise_rails/blob/master/spec/dummy/public/trans.zip?raw=true' }
9
+
6
10
  context 'when directory is empty' do
7
11
  before do
8
12
  mkdir_locales
@@ -13,13 +17,13 @@ RSpec.describe LokaliseRails do
13
17
  rm_translation_files
14
18
  end
15
19
 
16
- it 'is callable' do
20
+ it 'import rake task is callable' do
17
21
  expect(LokaliseRails::TaskDefinition::Importer).to receive(
18
22
  :download_files
19
23
  ).and_return(
20
24
  {
21
25
  'project_id' => '123.abc',
22
- 'bundle_url' => "#{Rails.root}/public/translations.zip"
26
+ 'bundle_url' => local_trans
23
27
  }
24
28
  )
25
29
 
@@ -27,17 +31,18 @@ RSpec.describe LokaliseRails do
27
31
 
28
32
  expect(count_translations).to eq(4)
29
33
 
30
- main_en = File.join described_class.locales_path, 'main_en.yml'
31
- expect(File.file?(main_en)).to be true
34
+ expect_file_exist loc_path, 'en/nested/main_en.yml'
35
+ expect_file_exist loc_path, 'en/nested/deep/secondary_en.yml'
36
+ expect_file_exist loc_path, 'ru/main_ru.yml'
32
37
  end
33
38
 
34
- it 'downloads ZIP archive properly' do
39
+ it 'import rake task downloads ZIP archive properly' do
35
40
  expect(LokaliseRails::TaskDefinition::Importer).to receive(
36
41
  :download_files
37
42
  ).and_return(
38
43
  {
39
44
  'project_id' => '123.abc',
40
- 'bundle_url' => 'https://github.com/bodrovis/lokalise_rails/blob/master/spec/dummy/public/translations.zip?raw=true'
45
+ 'bundle_url' => remote_trans
41
46
  }
42
47
  )
43
48
 
@@ -45,38 +50,53 @@ RSpec.describe LokaliseRails do
45
50
 
46
51
  expect(count_translations).to eq(4)
47
52
 
48
- main_en = File.join described_class.locales_path, 'main_en.yml'
49
- expect(File.file?(main_en)).to be true
53
+ expect_file_exist loc_path, 'en/nested/main_en.yml'
54
+ expect_file_exist loc_path, 'en/nested/deep/secondary_en.yml'
55
+ expect_file_exist loc_path, 'ru/main_ru.yml'
50
56
  end
51
57
  end
52
58
 
53
- context 'when directory is not empty' do
59
+ context 'when directory is not empty and safe mode enabled' do
54
60
  before :all do
55
61
  mkdir_locales
56
- rm_translation_files
57
- temp_file = File.join described_class.locales_path, 'kill.me'
58
- File.open(temp_file, 'w+') { |file| file.write('temp') }
59
62
  described_class.import_safe_mode = true
60
63
  end
61
64
 
65
+ before do
66
+ rm_translation_files
67
+ add_translation_files!
68
+ end
69
+
62
70
  after :all do
63
71
  rm_translation_files
64
72
  described_class.import_safe_mode = false
65
73
  end
66
74
 
67
- it 'returns a success message with default settings' do
75
+ it 'import proceeds when the user agrees' do
68
76
  expect(LokaliseRails::TaskDefinition::Importer).to receive(
69
77
  :download_files
70
78
  ).and_return(
71
79
  {
72
80
  'project_id' => '123.abc',
73
- 'bundle_url' => "#{Rails.root}/public/translations.zip"
81
+ 'bundle_url' => local_trans
74
82
  }
75
83
  )
76
84
  expect($stdin).to receive(:gets).and_return('Y')
77
85
  expect(import_executor).to output(/is not empty/).to_stdout
78
86
 
79
87
  expect(count_translations).to eq(5)
88
+
89
+ expect_file_exist loc_path, 'en/nested/main_en.yml'
90
+ expect_file_exist loc_path, 'en/nested/deep/secondary_en.yml'
91
+ expect_file_exist loc_path, 'ru/main_ru.yml'
92
+ end
93
+
94
+ it 'import halts when a user chooses not to proceed' do
95
+ expect(LokaliseRails::TaskDefinition::Importer).not_to receive(:download_files)
96
+ expect($stdin).to receive(:gets).and_return('N')
97
+ expect(import_executor).to output(/is not empty/).to_stdout
98
+
99
+ expect(count_translations).to eq(1)
80
100
  end
81
101
  end
82
102
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'dotenv/load'
4
4
  require 'simplecov'
5
+
5
6
  SimpleCov.start 'rails' do
6
7
  add_filter 'spec/'
7
8
  add_filter '.github/'
@@ -21,14 +22,19 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
21
22
  ENV['RAILS_ENV'] = 'test'
22
23
 
23
24
  require_relative '../spec/dummy/config/environment'
24
- ActiveRecord::Migrator.migrations_paths = [File.expand_path('../spec/dummy/db/migrate', __dir__)]
25
+ # ActiveRecord::Migrator.migrations_paths = [File.expand_path('../spec/dummy/db/migrate', __dir__)]
25
26
  ENV['RAILS_ROOT'] ||= "#{File.dirname(__FILE__)}../../../spec/dummy"
26
27
 
27
28
  require 'rspec/rails'
28
29
 
29
30
  RSpec.configure do |config|
30
- config.include FileUtils
31
+ config.include FileManager
31
32
  config.include RakeUtils
32
33
  end
33
34
 
35
+ # rubocop:disable Style/MixinUsage
36
+ include FileManager
37
+ # rubocop:enable Style/MixinUsage
38
+
39
+ add_config!
34
40
  Rails.application.load_tasks
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+
5
+ module FileManager
6
+ def expect_file_exist(path, file)
7
+ file_path = File.join path, file
8
+ expect(File.file?(file_path)).to be true
9
+ end
10
+
11
+ def mkdir_locales
12
+ FileUtils.mkdir_p(LokaliseRails.locales_path) unless File.directory?(LokaliseRails.locales_path)
13
+ end
14
+
15
+ def rm_translation_files
16
+ FileUtils.rm_rf locales_dir
17
+ end
18
+
19
+ def locales_dir
20
+ Dir["#{LokaliseRails.locales_path}/**/*"]
21
+ end
22
+
23
+ def count_translations
24
+ locales_dir.count { |file| File.file?(file) }
25
+ end
26
+
27
+ def add_translation_files!(with_ru: false)
28
+ FileUtils.mkdir_p "#{Rails.root}/config/locales/nested"
29
+ File.open("#{Rails.root}/config/locales/nested/en.yml", 'w+:UTF-8') do |f|
30
+ f.write en_data
31
+ end
32
+
33
+ return unless with_ru
34
+
35
+ File.open("#{Rails.root}/config/locales/ru.yml", 'w+:UTF-8') do |f|
36
+ f.write ru_data
37
+ end
38
+ end
39
+
40
+ def add_config!
41
+ data = <<~DATA
42
+ require 'lokalise_rails'
43
+ LokaliseRails.config do |c|
44
+ c.api_token = ENV['LOKALISE_API_TOKEN']
45
+ c.project_id = ENV['LOKALISE_PROJECT_ID']
46
+ end
47
+ DATA
48
+
49
+ File.open("#{Rails.root}/config/lokalise_rails.rb", 'w+:UTF-8') do |f|
50
+ f.write data
51
+ end
52
+ end
53
+
54
+ def remove_config
55
+ FileUtils.remove_file config_file if File.file?(config_file)
56
+ end
57
+
58
+ def config_file
59
+ "#{Rails.root}/config/lokalise_rails.rb"
60
+ end
61
+
62
+ private
63
+
64
+ def en_data
65
+ <<~DATA
66
+ en:
67
+ my_key: "My value"
68
+ nested:
69
+ key: "Value 2"
70
+ DATA
71
+ end
72
+
73
+ def ru_data
74
+ <<~DATA
75
+ ru_RU:
76
+ my_key: "Моё значение"
77
+ nested:
78
+ key: "Значение 2"
79
+ DATA
80
+ end
81
+ end
@@ -5,6 +5,10 @@ module RakeUtils
5
5
  -> { Rake::Task['lokalise_rails:import'].execute }
6
6
  end
7
7
 
8
+ def export_executor
9
+ -> { Rake::Task['lokalise_rails:export'].execute }
10
+ end
11
+
8
12
  def install_invoker
9
13
  Rails::Generators.invoke 'lokalise_rails:install'
10
14
  end
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: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Bodrov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-26 00:00:00.000000000 Z
11
+ date: 2020-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-lokalise-api
@@ -178,20 +178,6 @@ dependencies:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0.16'
181
- - !ruby/object:Gem::Dependency
182
- name: sqlite3
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - "~>"
186
- - !ruby/object:Gem::Version
187
- version: '1.4'
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - "~>"
193
- - !ruby/object:Gem::Version
194
- version: '1.4'
195
181
  - !ruby/object:Gem::Dependency
196
182
  name: vcr
197
183
  requirement: !ruby/object:Gem::Requirement
@@ -228,6 +214,7 @@ files:
228
214
  - lib/lokalise_rails.rb
229
215
  - lib/lokalise_rails/railtie.rb
230
216
  - lib/lokalise_rails/task_definition/base.rb
217
+ - lib/lokalise_rails/task_definition/exporter.rb
231
218
  - lib/lokalise_rails/task_definition/importer.rb
232
219
  - lib/lokalise_rails/version.rb
233
220
  - lib/tasks/lokalise_rails_tasks.rake
@@ -255,11 +242,13 @@ files:
255
242
  - spec/dummy/config/routes.rb
256
243
  - spec/dummy/db/seeds.rb
257
244
  - spec/lib/generators/lokalise_rails/install_generator_spec.rb
245
+ - spec/lib/lokalise_rails/exporter_spec.rb
258
246
  - spec/lib/lokalise_rails/importer_spec.rb
259
247
  - spec/lib/lokalise_rails_spec.rb
248
+ - spec/lib/tasks/export_task_spec.rb
260
249
  - spec/lib/tasks/import_task_spec.rb
261
250
  - spec/spec_helper.rb
262
- - spec/support/file_utils.rb
251
+ - spec/support/file_manager.rb
263
252
  - spec/support/rake_utils.rb
264
253
  - spec/support/vcr.rb
265
254
  homepage: https://github.com/bodrovis/lokalise_rails
@@ -309,10 +298,12 @@ test_files:
309
298
  - spec/dummy/config/routes.rb
310
299
  - spec/dummy/db/seeds.rb
311
300
  - spec/lib/generators/lokalise_rails/install_generator_spec.rb
301
+ - spec/lib/lokalise_rails/exporter_spec.rb
312
302
  - spec/lib/lokalise_rails/importer_spec.rb
313
303
  - spec/lib/lokalise_rails_spec.rb
304
+ - spec/lib/tasks/export_task_spec.rb
314
305
  - spec/lib/tasks/import_task_spec.rb
315
306
  - spec/spec_helper.rb
316
- - spec/support/file_utils.rb
307
+ - spec/support/file_manager.rb
317
308
  - spec/support/rake_utils.rb
318
309
  - spec/support/vcr.rb
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module FileUtils
4
- def mkdir_locales
5
- FileUtils.mkdir_p(LokaliseRails.locales_path) unless File.directory?(LokaliseRails.locales_path)
6
- end
7
-
8
- def rm_translation_files
9
- FileUtils.rm_rf locales_dir
10
- end
11
-
12
- def locales_dir
13
- Dir["#{LokaliseRails.locales_path}/*"]
14
- end
15
-
16
- def count_translations
17
- locales_dir.count { |file| File.file?(file) }
18
- end
19
-
20
- def remove_config
21
- FileUtils.remove_file config_file if File.file?(config_file)
22
- end
23
-
24
- def config_file
25
- "#{Rails.root}/config/lokalise_rails.rb"
26
- end
27
- end