lokalise_rails 8.0.0 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5acb05fa54c4ff1e243de21c053b5154e307709e1bd569fa3dbb363e147e1443
4
- data.tar.gz: 84714f2c2250a8d81a5671cc6bfaa6735151151bf5c5f6b38ae7f6e13579a3e3
3
+ metadata.gz: a3ff7f8491d3b827f087d10075343078f5bb084b7fb648fac8270b65af1c26f2
4
+ data.tar.gz: d0176a00387aea9c8e4fd3063f214f8a1e3fc5b33b5a026cae685931214ce99b
5
5
  SHA512:
6
- metadata.gz: a457a3fcf4abe0783029f6458a4139b1d24c073b7480f59170f41eaf52fe9989735ffdb4f67ee0a829f29dfa65ca296debb8a32029079816dbfc9621fc8ef662
7
- data.tar.gz: eb21427d268d3ce61d7c87184f07bc2347174d4a9d54f556b64b87a284309b1d6a91324ade166d0abb6fa8db425e788e0add91b29cee3dc05e1f8d4aaf791c33
6
+ metadata.gz: 16ba4b740fb69c45c4de23fc629618fe93a18de23d55b8b7658590c36372d21fe685999f0576fe5055b3f58e331f0493c2f703eb8a0ca5f5bf7613956ddfdd12
7
+ data.tar.gz: 5db3aa39c333e88496a6a48efe13d0792da290cb46676058fd012e9ad3cca8a054c20f171436a3124739ce81ce6a0a566a45f12e57a774ee38c2475fe5415956
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 8.1.0 (17-Apr-2025)
4
+
5
+ * Added `disable_export_task` boolean option. When enabled, the export task is turned off in your project to prevent from accidentally exporting keys to Lokalise and overwriting existing data. Defaults to `false`. Thanks, @aarisr!
6
+
7
+ ## 8.0.1 (19-Feb-2025)
8
+
9
+ * Minor code tweaks, use latest `lokalise_manager` that now enables asynchronous imports
10
+
3
11
  ## 8.0.0 (29-Nov-2024)
4
12
 
5
13
  * **Breaking change**: rename the `timeouts` config option to `additional_client_opts`. It has the same usage but now enables you to set both client timeouts and override the API host to send requests to.
data/Gemfile CHANGED
@@ -6,7 +6,7 @@ gemspec
6
6
 
7
7
  group :test do
8
8
  gem 'dotenv', '~> 3.0'
9
- gem 'rails', '8.0.0'
9
+ gem 'rails', '~> 8.0'
10
10
  gem 'rake', '~> 13.0'
11
11
  gem 'rspec', '~> 3.6'
12
12
  gem 'rubocop', '~> 1.0'
data/README.md CHANGED
@@ -185,6 +185,9 @@ LokaliseRails::GlobalConfig.config do |c|
185
185
 
186
186
  ## Infer language ISO code for the translation file:
187
187
  ## c.lang_iso_inferer = ->(data, _path) { YAML.safe_load(data)&.keys&.first }
188
+
189
+ ## Disable the export rake task:
190
+ ## c.disable_export_task = false
188
191
  end
189
192
  ```
190
193
 
@@ -4,21 +4,15 @@ require 'rails/generators'
4
4
 
5
5
  module LokaliseRails
6
6
  module Generators
7
- # Generator that sets up the LokaliseRails configuration in a Rails application.
8
- # It copies a predefined configuration template into the appropriate directory within the Rails application,
9
- # making it easier for users to configure and use LokaliseRails.
7
+ # Installs the LokaliseRails configuration file in a Rails application.
10
8
  class InstallGenerator < Rails::Generators::Base
11
- # Sets the directory containing the template files relative to this file's location.
12
9
  source_root File.expand_path('../templates', __dir__)
13
10
 
14
- # Description of the generator's purpose, which is displayed in the Rails generators list.
15
- desc 'Creates a LokaliseRails config file in your Rails application.'
11
+ # Adds a configuration file for LokaliseRails to the Rails application.
12
+ desc 'Creates a config/lokalise_rails.rb file for LokaliseRails.'
16
13
 
17
- # The primary method of this generator, responsible for copying the LokaliseRails configuration template
18
- # from the gem to the Rails application's config directory. This is where users can customize
19
- # their Lokalise settings.
14
+ # Copies the configuration template to the application's config directory.
20
15
  def copy_config
21
- # Copies the configuration template to the Rails application's config directory.
22
16
  template 'lokalise_rails_config.rb', "#{Rails.root}/config/lokalise_rails.rb"
23
17
  end
24
18
  end
@@ -34,6 +34,9 @@ if defined?(LokaliseRails::GlobalConfig)
34
34
  # Safe mode for imports is disabled by default:
35
35
  # c.import_safe_mode = false
36
36
 
37
+ # Run imports asynchronously
38
+ # c.import_async = false
39
+
37
40
  # Additional export options (only filename, contents, and lang_iso params are provided by default)
38
41
  # c.export_opts = {}
39
42
 
@@ -52,5 +55,8 @@ if defined?(LokaliseRails::GlobalConfig)
52
55
 
53
56
  ## Infer language ISO code for the translation file:
54
57
  ## c.lang_iso_inferer = ->(data, _path) { YAML.safe_load(data)&.keys&.first }
58
+
59
+ ## Disable the export rake task:
60
+ ## c.disable_export_task = false
55
61
  end
56
62
  end
@@ -1,17 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LokaliseRails
4
- # Inherits from LokaliseManager::GlobalConfig to provide a global configuration specific to the LokaliseRails gem.
5
- # This class is primarily used to manage configuration settings that affect how the LokaliseRails gem operates
6
- # within a Ruby on Rails application, particularly in managing locale paths.
4
+ # Extends `LokaliseManager::GlobalConfig` to provide a global configuration
5
+ # specific to the LokaliseRails gem in a Rails application.
7
6
  class GlobalConfig < LokaliseManager::GlobalConfig
8
7
  class << self
9
- # Provides the path to the locales directory where translation files are stored. If not set explicitly,
10
- # it defaults to the `config/locales` directory within the root of the application using this gem.
8
+ attr_writer :disable_export_task
9
+
10
+ # Returns whether the export task should be disabled.
11
+ #
12
+ # Defaults to `false` if not explicitly set.
13
+ #
14
+ # @return [Boolean] `true` if the export task is disabled, otherwise `false`.
15
+ def disable_export_task
16
+ @disable_export_task.nil? ? false : @disable_export_task
17
+ end
18
+
19
+ # Returns the path to the directory where translation files are stored.
20
+ #
21
+ # Defaults to `config/locales` under the Rails application root if not explicitly set.
11
22
  #
12
- # @return [String] the path to the locales directory
23
+ # @return [String] Absolute path to the locales directory.
13
24
  def locales_path
14
- # If @locales_path is not set, it defaults to a path under the application's root directory.
15
25
  @locales_path || "#{LokaliseRails::Utils.root}/config/locales"
16
26
  end
17
27
  end
@@ -1,18 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LokaliseRails
4
- # The Railtie class in Rails is used to extend Rails' functionality within an application, or in this case,
5
- # a gem. This Railtie is specifically used to add custom Rake tasks from the
6
- # LokaliseRails gem into the Rails application.
4
+ # Extends Rails via Railtie to integrate LokaliseRails functionalities.
7
5
  #
8
- # It leverages Rails' Railtie architecture to ensure the Rake
9
- # tasks are loaded when the application boots up and Rake is invoked.
6
+ # This Railtie ensures that custom Rake tasks from the LokaliseRails gem
7
+ # are automatically available within a Rails application.
10
8
  class Railtie < Rails::Railtie
11
- # Register Rake tasks that are defined within this gem. This block is called by Rails during the initialization
12
- # process and ensures that all Rake tasks specific to LokaliseRails are available to the application.
9
+ # Registers custom Rake tasks for LokaliseRails.
10
+ #
11
+ # This ensures that the tasks are loaded when the Rails application boots
12
+ # and Rake is invoked.
13
13
  rake_tasks do
14
- # Loads the Rake tasks from a file located relative to this file. Ensure this file exists and contains
15
- # valid Rake task definitions specifically tailored for Lokalise integration.
16
14
  load 'tasks/lokalise_rails_tasks.rake'
17
15
  end
18
16
  end
@@ -3,31 +3,30 @@
3
3
  require 'pathname'
4
4
 
5
5
  module LokaliseRails
6
- # Util methods
6
+ # Utility methods for LokaliseRails
7
7
  module Utils
8
8
  class << self
9
9
  # Retrieves the root directory of the current project.
10
- # It attempts to find the Rails root directory if Rails is loaded.
11
- # If Rails is not present, it defaults to the current working directory of the process.
12
10
  #
13
- # @return [Pathname] A Pathname object pointing to the root directory of the project.
11
+ # If Rails is available, it returns `Rails.root`. Otherwise, it defaults
12
+ # to the current working directory.
13
+ #
14
+ # @return [Pathname] Pathname object pointing to the project root.
14
15
  def root
15
- # Uses Pathname to create a robust path object from the rails_root or the current working directory.
16
16
  Pathname.new(rails_root || Dir.getwd)
17
17
  end
18
18
 
19
- # Attempts to determine the root directory of a Rails
20
- # project by checking the presence of Rails and its root method.
21
- # If Rails is older and does not have the root method, it falls back to the RAILS_ROOT constant if defined.
19
+ # Determines the root directory of a Rails project.
20
+ #
21
+ # - Uses `Rails.root` if available.
22
+ # - Falls back to `RAILS_ROOT` for older Rails versions.
23
+ # - Returns `nil` if Rails is not present.
22
24
  #
23
- # @return [String, nil] the path to the root directory if Rails is defined, or nil if it cannot be determined.
25
+ # @return [String, nil] Path to the root directory or `nil` if not found.
24
26
  def rails_root
25
- # First, check if Rails.root is defined and return its path if available.
26
27
  return ::Rails.root.to_s if defined?(::Rails.root) && ::Rails.root
27
- # Fallback to the RAILS_ROOT constant from older Rails versions.
28
28
  return RAILS_ROOT.to_s if defined?(RAILS_ROOT)
29
29
 
30
- # Returns nil if none of the above are defined, indicating Rails is not present.
31
30
  nil
32
31
  end
33
32
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LokaliseRails
4
- VERSION = '8.0.0'
4
+ VERSION = '8.1.0'
5
5
  end
@@ -3,19 +3,22 @@
3
3
  require 'zeitwerk'
4
4
  require 'lokalise_manager'
5
5
 
6
- # Configure Zeitwerk loader specific for gem environments. This loader is set up to ignore certain files
7
- # that should not be autoloaded, such as Rails-specific files or templates which are not part of the main load path.
6
+ # Configure Zeitwerk for managing gem autoloading.
8
7
  loader = Zeitwerk::Loader.for_gem
9
- loader.ignore "#{__dir__}/lokalise_rails/railtie.rb" # Ignore the Railtie in non-Rails environments
10
- loader.ignore "#{__dir__}/generators/templates/lokalise_rails_config.rb" # Ignore the generator templates
11
- loader.ignore "#{__dir__}/generators/lokalise_rails/install_generator.rb" # Ignore installation generator scripts
8
+
9
+ # Ignore files that should not be autoloaded.
10
+ loader.ignore "#{__dir__}/lokalise_rails/railtie.rb" # Exclude Railtie when not in a Rails app
11
+ loader.ignore "#{__dir__}/generators/templates/lokalise_rails_config.rb" # Ignore generator templates
12
+ loader.ignore "#{__dir__}/generators/lokalise_rails/install_generator.rb" # Ignore installation generator
13
+
12
14
  loader.setup
13
15
 
14
- # Main module for the LokaliseRails gem. This module serves as the namespace for all components
15
- # related to the LokaliseRails integration. It provides a structured way to manage translations
16
- # through the Lokalise platform within Ruby on Rails applications.
16
+ # Main module for LokaliseRails.
17
+ #
18
+ # Serves as the namespace for all components of the LokaliseRails gem,
19
+ # providing tools for managing translations in Ruby on Rails applications.
17
20
  module LokaliseRails
18
21
  end
19
22
 
20
- # Require the Railtie only if Rails is defined to integrate with Rails without manual configuration.
23
+ # Load Railtie if running within a Rails application.
21
24
  require_relative 'lokalise_rails/railtie' if defined?(Rails)
@@ -2,33 +2,34 @@
2
2
 
3
3
  require 'rake'
4
4
  require 'lokalise_rails'
5
- # Loads the configuration settings from the lokalise_rails configuration file within the Rails project.
6
- require "#{LokaliseRails::Utils.root}/config/lokalise_rails"
5
+ require File.join(LokaliseRails::Utils.root, 'config', 'lokalise_rails')
7
6
 
8
- # Namespace for Rake tasks related to the LokaliseRails gem.
9
- # These tasks facilitate the synchronization of localization files between the Rails project and the Lokalise platform.
7
+ # Rake tasks for syncing translation files between a Rails project and Lokalise.
10
8
  namespace :lokalise_rails do
11
- # Imports translation files from Lokalise and integrates them into the current Rails project.
12
- # This task utilizes the LokaliseManager to handle the import process according to the configuration specified
13
- # in the GlobalConfig class.
14
- desc 'Imports translation files from Lokalise to the current Rails project'
9
+ ##########################################################################
10
+ # IMPORT
11
+ ##########################################################################
12
+ desc 'Import translations from Lokalise into the Rails project'
15
13
  task :import do
16
14
  importer = LokaliseManager.importer({}, LokaliseRails::GlobalConfig)
17
15
  importer.import!
18
16
  rescue StandardError => e
19
- # Aborts the task and prints the error message.
20
- # Ensures that any exceptions raised during import are handled gracefully.
21
17
  abort "Import failed: #{e.message}"
22
18
  end
23
19
 
24
- # Exports translation files from the current Rails project to Lokalise.
25
- # Similar to the import task, it leverages the LokaliseManager and uses the GlobalConfig for configuration settings.
26
- desc 'Exports translation files from the current Rails project to Lokalise'
20
+ ##########################################################################
21
+ # EXPORT
22
+ ##########################################################################
23
+ desc 'Export translations from the Rails project to Lokalise'
27
24
  task :export do
25
+ if LokaliseRails::GlobalConfig.disable_export_task
26
+ $stdout.puts 'Export task is disabled.'
27
+ exit 0
28
+ end
29
+
28
30
  exporter = LokaliseManager.exporter({}, LokaliseRails::GlobalConfig)
29
31
  exporter.export!
30
32
  rescue StandardError => e
31
- # Aborts the task and prints the error message. Provides clear feedback on why the export failed.
32
33
  abort "Export failed: #{e.message}"
33
34
  end
34
35
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lokalise_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.0.0
4
+ version: 8.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Krukowski
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-11-29 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: lokalise_manager
@@ -69,7 +68,6 @@ licenses:
69
68
  - MIT
70
69
  metadata:
71
70
  rubygems_mfa_required: 'true'
72
- post_install_message:
73
71
  rdoc_options: []
74
72
  require_paths:
75
73
  - lib
@@ -84,8 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
82
  - !ruby/object:Gem::Version
85
83
  version: '0'
86
84
  requirements: []
87
- rubygems_version: 3.5.23
88
- signing_key:
85
+ rubygems_version: 3.6.8
89
86
  specification_version: 4
90
87
  summary: Lokalise integration for Ruby on Rails
91
88
  test_files: []