lokalise_rails 6.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 +16 -0
- data/Gemfile +3 -2
- data/LICENSE +1 -1
- data/README.md +4 -2
- data/lib/generators/lokalise_rails/install_generator.rb +10 -3
- data/lib/generators/templates/lokalise_rails_config.rb +1 -1
- 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
- data/lokalise_rails.gemspec +2 -2
- metadata +6 -6
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,21 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 7.0.1
|
4
|
+
|
5
|
+
* Update documentation, minor code tweaks
|
6
|
+
|
7
|
+
## 7.0.0 (09-Nov-2023)
|
8
|
+
|
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.
|
10
|
+
* **Potential breaking change**: lambda returned by the `lang_iso_inferer` method has been slightly enhanced. It now accepts not only the file data but also the full path to the file. Therefore, if you redefine the `lang_iso_inferer` option please make sure that the returned lambda accepts two params, not one. This way, you can be more flexible when inferring the locale. For example:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
lang_iso_inferer: ->(_data, path) { path.basename('.yml').to_s }
|
14
|
+
```
|
15
|
+
|
16
|
+
* Use newer lokalise_manager and ruby-lokalise-api.
|
17
|
+
* Test with Ruby 3.3, do not test with Rails 6.0 (EOL)
|
18
|
+
|
3
19
|
## 6.0.0 (27-Jul-2023)
|
4
20
|
|
5
21
|
* Use lokalise-manager v4 and ruby-lokalise-api v8. The latter is a major rewrite of the original SDK and has some breaking changes (however 95% of the methods have similar signatures). Therefore please make sure that your tests pass.
|
data/Gemfile
CHANGED
@@ -5,8 +5,8 @@ source 'http://rubygems.org'
|
|
5
5
|
gemspec
|
6
6
|
|
7
7
|
group :test do
|
8
|
-
gem 'dotenv', '~>
|
9
|
-
gem 'rails', '~> 7.
|
8
|
+
gem 'dotenv', '~> 3.0'
|
9
|
+
gem 'rails', '~> 7.1'
|
10
10
|
gem 'rake', '~> 13.0'
|
11
11
|
gem 'rspec', '~> 3.6'
|
12
12
|
gem 'rubocop', '~> 1.0'
|
@@ -14,6 +14,7 @@ group :test do
|
|
14
14
|
gem 'rubocop-rake', '~> 0.6'
|
15
15
|
gem 'rubocop-rspec', '~> 2.6'
|
16
16
|
gem 'simplecov', '~> 0.22'
|
17
|
+
gem 'simplecov-lcov', '~> 0.8'
|
17
18
|
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
|
18
19
|
gem 'webmock', '~> 3.14'
|
19
20
|
end
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
![Gem](https://img.shields.io/gem/v/lokalise_rails)
|
4
4
|
![CI](https://github.com/bodrovis/lokalise_rails/actions/workflows/ci.yml/badge.svg)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/github/bodrovis/lokalise_rails/badge.svg?branch=master)](https://coveralls.io/github/bodrovis/lokalise_rails?branch=master)
|
6
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/6e5c98f76227de00b0f2/maintainability)](https://codeclimate.com/github/bodrovis/lokalise_rails/maintainability)
|
5
7
|
![Downloads total](https://img.shields.io/gem/dt/lokalise_rails)
|
6
8
|
|
7
9
|
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.
|
@@ -12,7 +14,7 @@ This gem provides [Lokalise](http://lokalise.com) integration for Ruby on Rails
|
|
12
14
|
|
13
15
|
### Requirements
|
14
16
|
|
15
|
-
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.
|
16
18
|
|
17
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).
|
18
20
|
|
@@ -182,7 +184,7 @@ LokaliseRails::GlobalConfig.config do |c|
|
|
182
184
|
## c.translations_converter = ->(raw_data) { YAML.dump(raw_data).gsub(/\\\\n/, '\n') }
|
183
185
|
|
184
186
|
## Infer language ISO code for the translation file:
|
185
|
-
## c.lang_iso_inferer = ->(data) { YAML.safe_load(data)&.keys&.first }
|
187
|
+
## c.lang_iso_inferer = ->(data, _path) { YAML.safe_load(data)&.keys&.first }
|
186
188
|
end
|
187
189
|
```
|
188
190
|
|
@@ -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
|
@@ -51,6 +51,6 @@ if defined?(LokaliseRails) && defined?(LokaliseRails::GlobalConfig)
|
|
51
51
|
## c.translations_converter = ->(raw_data) { YAML.dump(raw_data).gsub(/\\\\n/, '\n') }
|
52
52
|
|
53
53
|
## Infer language ISO code for the translation file:
|
54
|
-
## c.lang_iso_inferer = ->(data) { YAML.safe_load(data)&.keys&.first }
|
54
|
+
## c.lang_iso_inferer = ->(data, _path) { YAML.safe_load(data)&.keys&.first }
|
55
55
|
end
|
56
56
|
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
|
data/lokalise_rails.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.homepage = 'https://github.com/bodrovis/lokalise_rails'
|
13
13
|
spec.license = 'MIT'
|
14
14
|
spec.platform = Gem::Platform::RUBY
|
15
|
-
spec.required_ruby_version = '>=
|
15
|
+
spec.required_ruby_version = '>= 3.0'
|
16
16
|
|
17
17
|
spec.files = Dir['README.md', 'LICENSE',
|
18
18
|
'CHANGELOG.md', 'lib/**/*.rb',
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.extra_rdoc_files = ['README.md']
|
23
23
|
spec.require_paths = ['lib']
|
24
24
|
|
25
|
-
spec.add_dependency 'lokalise_manager', '~>
|
25
|
+
spec.add_dependency 'lokalise_manager', '~> 5.0'
|
26
26
|
spec.add_dependency 'zeitwerk', '~> 2.4'
|
27
27
|
|
28
28
|
spec.metadata = {
|
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:
|
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
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '5.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: zeitwerk
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,14 +77,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
77
|
requirements:
|
78
78
|
- - ">="
|
79
79
|
- !ruby/object:Gem::Version
|
80
|
-
version:
|
80
|
+
version: '3.0'
|
81
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
82
|
requirements:
|
83
83
|
- - ">="
|
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
|