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 +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile +1 -1
- data/README.md +3 -0
- data/lib/generators/lokalise_rails/install_generator.rb +4 -10
- data/lib/generators/templates/lokalise_rails_config.rb +6 -0
- data/lib/lokalise_rails/global_config.rb +17 -7
- data/lib/lokalise_rails/railtie.rb +7 -9
- data/lib/lokalise_rails/utils.rb +11 -12
- data/lib/lokalise_rails/version.rb +1 -1
- data/lib/lokalise_rails.rb +12 -9
- data/lib/tasks/lokalise_rails_tasks.rake +15 -14
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3ff7f8491d3b827f087d10075343078f5bb084b7fb648fac8270b65af1c26f2
|
4
|
+
data.tar.gz: d0176a00387aea9c8e4fd3063f214f8a1e3fc5b33b5a026cae685931214ce99b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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
|
-
#
|
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
|
-
#
|
15
|
-
desc 'Creates a
|
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
|
-
#
|
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
|
-
#
|
5
|
-
#
|
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
|
-
|
10
|
-
|
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]
|
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
|
-
#
|
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
|
-
#
|
9
|
-
#
|
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
|
-
#
|
12
|
-
#
|
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
|
data/lib/lokalise_rails/utils.rb
CHANGED
@@ -3,31 +3,30 @@
|
|
3
3
|
require 'pathname'
|
4
4
|
|
5
5
|
module LokaliseRails
|
6
|
-
#
|
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
|
-
#
|
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
|
-
#
|
20
|
-
#
|
21
|
-
#
|
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]
|
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
|
data/lib/lokalise_rails.rb
CHANGED
@@ -3,19 +3,22 @@
|
|
3
3
|
require 'zeitwerk'
|
4
4
|
require 'lokalise_manager'
|
5
5
|
|
6
|
-
# Configure Zeitwerk
|
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
|
-
|
10
|
-
|
11
|
-
loader.ignore "#{__dir__}/
|
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
|
15
|
-
#
|
16
|
-
#
|
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
|
-
#
|
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
|
-
|
6
|
-
require "#{LokaliseRails::Utils.root}/config/lokalise_rails"
|
5
|
+
require File.join(LokaliseRails::Utils.root, 'config', 'lokalise_rails')
|
7
6
|
|
8
|
-
#
|
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
|
-
|
12
|
-
#
|
13
|
-
|
14
|
-
desc '
|
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
|
-
|
25
|
-
#
|
26
|
-
|
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.
|
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:
|
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.
|
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: []
|