lokalise_rails 7.0.0 → 7.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/lib/generators/lokalise_rails/install_generator.rb +10 -3
- data/lib/lokalise_rails/global_config.rb +8 -1
- data/lib/lokalise_rails/railtie.rb +10 -1
- data/lib/lokalise_rails/utils.rb +14 -2
- data/lib/lokalise_rails/version.rb +1 -1
- data/lib/lokalise_rails.rb +9 -4
- data/lib/tasks/lokalise_rails_tasks.rake +13 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d0c8f216f82d224538b9d7e0931f99dff27067c21209a4652f210fc3e4a6dd8
|
4
|
+
data.tar.gz: bcf43f559a4b2a81b307498641af169ee916e634fe6f0b44ae2e1816df7ba86d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe926df4a57c93bb325802a7767dfb978e7bddcdd652bff24be9e889e42bff478031d0561bf84cb0f3c2541aa3da87ad8c5d5ad95593761c3bb647ae66eb5670
|
7
|
+
data.tar.gz: 7e11ac6f31780fc01a1109101ab70fe8a42e6377270198e58050e11af6c98a6e285c4ce79f3c53bb2d1edfd3264ea64d26281e86fda5b4a07fc3b6963f8b0925
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 7.0.1
|
4
|
+
|
5
|
+
* Update documentation, minor code tweaks
|
6
|
+
|
3
7
|
## 7.0.0 (09-Nov-2023)
|
4
8
|
|
5
9
|
* **Breaking change**: require Ruby 3+. Version 2.7 has reached end-of-life and thus we are not planning to support it anymore. If you need support for Ruby 2.7, please stay on 6.0.0.
|
data/Gemfile
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -14,7 +14,7 @@ This gem provides [Lokalise](http://lokalise.com) integration for Ruby on Rails
|
|
14
14
|
|
15
15
|
### Requirements
|
16
16
|
|
17
|
-
This gem requires Ruby
|
17
|
+
This gem requires Ruby 3.0+ 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.
|
18
18
|
|
19
19
|
Alternatively, you can utilize a token obtained via OAuth 2 flow. When using such a token, you'll have to set `:use_oauth2_token` option to `true` (please check [options docs](https://github.com/bodrovis/lokalise_manager#common-config) to learn more).
|
20
20
|
|
@@ -3,15 +3,22 @@
|
|
3
3
|
require 'rails/generators'
|
4
4
|
|
5
5
|
module LokaliseRails
|
6
|
-
# Generators for LokaliseRails
|
7
6
|
module Generators
|
8
|
-
#
|
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.
|
9
10
|
class InstallGenerator < Rails::Generators::Base
|
11
|
+
# Sets the directory containing the template files relative to this file's location.
|
10
12
|
source_root File.expand_path('../templates', __dir__)
|
11
13
|
|
12
|
-
|
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.'
|
13
16
|
|
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
20
|
def copy_config
|
21
|
+
# Copies the configuration template to the Rails application's config directory.
|
15
22
|
template 'lokalise_rails_config.rb', "#{Rails.root}/config/lokalise_rails.rb"
|
16
23
|
end
|
17
24
|
end
|
@@ -1,10 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module LokaliseRails
|
4
|
-
#
|
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.
|
5
7
|
class GlobalConfig < LokaliseManager::GlobalConfig
|
6
8
|
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.
|
11
|
+
#
|
12
|
+
# @return [String] the path to the locales directory
|
7
13
|
def locales_path
|
14
|
+
# If @locales_path is not set, it defaults to a path under the application's root directory.
|
8
15
|
@locales_path || "#{LokaliseRails::Utils.root}/config/locales"
|
9
16
|
end
|
10
17
|
end
|
@@ -1,9 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module LokaliseRails
|
4
|
-
#
|
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.
|
7
|
+
#
|
8
|
+
# It leverages Rails' Railtie architecture to ensure the Rake
|
9
|
+
# tasks are loaded when the application boots up and Rake is invoked.
|
5
10
|
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.
|
6
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.
|
7
16
|
load 'tasks/lokalise_rails_tasks.rake'
|
8
17
|
end
|
9
18
|
end
|
data/lib/lokalise_rails/utils.rb
CHANGED
@@ -6,16 +6,28 @@ module LokaliseRails
|
|
6
6
|
# Util methods
|
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
|
+
#
|
13
|
+
# @return [Pathname] A Pathname object pointing to the root directory of the project.
|
10
14
|
def root
|
15
|
+
# Uses Pathname to create a robust path object from the rails_root or the current working directory.
|
11
16
|
Pathname.new(rails_root || Dir.getwd)
|
12
17
|
end
|
13
18
|
|
14
|
-
#
|
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.
|
22
|
+
#
|
23
|
+
# @return [String, nil] the path to the root directory if Rails is defined, or nil if it cannot be determined.
|
15
24
|
def rails_root
|
25
|
+
# First, check if Rails.root is defined and return its path if available.
|
16
26
|
return ::Rails.root.to_s if defined?(::Rails.root) && ::Rails.root
|
27
|
+
# Fallback to the RAILS_ROOT constant from older Rails versions.
|
17
28
|
return RAILS_ROOT.to_s if defined?(RAILS_ROOT)
|
18
29
|
|
30
|
+
# Returns nil if none of the above are defined, indicating Rails is not present.
|
19
31
|
nil
|
20
32
|
end
|
21
33
|
end
|
data/lib/lokalise_rails.rb
CHANGED
@@ -3,14 +3,19 @@
|
|
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
8
|
loader = Zeitwerk::Loader.for_gem
|
7
|
-
loader.ignore "#{__dir__}/lokalise_rails/railtie.rb"
|
8
|
-
loader.ignore "#{__dir__}/generators/templates/lokalise_rails_config.rb"
|
9
|
-
loader.ignore "#{__dir__}/generators/lokalise_rails/install_generator.rb"
|
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
|
10
12
|
loader.setup
|
11
13
|
|
12
|
-
# Main LokaliseRails module
|
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.
|
13
17
|
module LokaliseRails
|
14
18
|
end
|
15
19
|
|
20
|
+
# Require the Railtie only if Rails is defined to integrate with Rails without manual configuration.
|
16
21
|
require_relative 'lokalise_rails/railtie' if defined?(Rails)
|
@@ -2,22 +2,33 @@
|
|
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.
|
5
6
|
require "#{LokaliseRails::Utils.root}/config/lokalise_rails"
|
6
7
|
|
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
10
|
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.
|
8
14
|
desc 'Imports translation files from Lokalise to the current Rails project'
|
9
15
|
task :import do
|
10
16
|
importer = LokaliseManager.importer({}, LokaliseRails::GlobalConfig)
|
11
17
|
importer.import!
|
12
18
|
rescue StandardError => e
|
13
|
-
|
19
|
+
# Aborts the task and prints the error message.
|
20
|
+
# Ensures that any exceptions raised during import are handled gracefully.
|
21
|
+
abort "Import failed: #{e.message}"
|
14
22
|
end
|
15
23
|
|
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.
|
16
26
|
desc 'Exports translation files from the current Rails project to Lokalise'
|
17
27
|
task :export do
|
18
28
|
exporter = LokaliseManager.exporter({}, LokaliseRails::GlobalConfig)
|
19
29
|
exporter.export!
|
20
30
|
rescue StandardError => e
|
21
|
-
|
31
|
+
# Aborts the task and prints the error message. Provides clear feedback on why the export failed.
|
32
|
+
abort "Export failed: #{e.message}"
|
22
33
|
end
|
23
34
|
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: 7.0.
|
4
|
+
version: 7.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya Krukowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lokalise_manager
|
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: '0'
|
86
86
|
requirements: []
|
87
|
-
rubygems_version: 3.
|
87
|
+
rubygems_version: 3.5.10
|
88
88
|
signing_key:
|
89
89
|
specification_version: 4
|
90
90
|
summary: Lokalise integration for Ruby on Rails
|