internationalize 0.5.1 → 0.6.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 +15 -0
- data/lib/internationalize/model.rb +27 -0
- data/lib/internationalize/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 669e02f74b620a585a47fff36508f25d15a192dd9aaac8f4e2e5ff87a51b1b0e
|
|
4
|
+
data.tar.gz: dd3fb3052577a917627501f88fe192f725c1e9968e437a9e39d0cd2b58cea4d1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 82f5388681b2fb6db3d2d8069eeef062514af9c5f306d102a88514140587fba43355c831938155d4c5b2013b82144b07351b4de936afc8131114c129a3757b91
|
|
7
|
+
data.tar.gz: 59f86594b330f856091a9c415fb153878093dd110fc448539f47c7cd61c6b374b57b3f8799b3c507d7b9abc626e5643030bb38e3a0c55b3ac57913c7d0e53c42
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.6.0] - 2025-02-02
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `i18n_pluck` method for efficient plucking of internationalized attributes
|
|
13
|
+
- Automatically handles JSON extraction for translated attributes
|
|
14
|
+
- Non-international attributes pass through to regular pluck
|
|
15
|
+
- Supports explicit locale parameter: `Article.i18n_pluck(:id, :title, locale: :de)`
|
|
16
|
+
- Example: `Article.limit(100).i18n_pluck(:id, :name, :latitude)` for efficient map data
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- Fixed file permissions issue causing `LoadError: cannot load such file -- internationalize/rich_text` in production environments ([#9](https://github.com/sampokuokkanen/internationalize/issues/9))
|
|
21
|
+
- Gem files now have correct 644 permissions (world-readable)
|
|
22
|
+
|
|
8
23
|
## [0.5.1] - 2025-01-27
|
|
9
24
|
|
|
10
25
|
### Fixed
|
|
@@ -157,6 +157,33 @@ module Internationalize
|
|
|
157
157
|
scope
|
|
158
158
|
end
|
|
159
159
|
|
|
160
|
+
# Pluck attributes with automatic JSON extraction for internationalized attributes
|
|
161
|
+
#
|
|
162
|
+
# @param attributes [Array<Symbol>] attributes to pluck
|
|
163
|
+
# @param locale [Symbol] locale for internationalized attributes (default: current locale)
|
|
164
|
+
# @return [Array] plucked values
|
|
165
|
+
#
|
|
166
|
+
# @example
|
|
167
|
+
# Article.i18n_pluck(:id, :title)
|
|
168
|
+
# Article.i18n_pluck(:id, :title, :description, locale: :de)
|
|
169
|
+
# Article.limit(10).i18n_pluck(:id, :title, :status)
|
|
170
|
+
#
|
|
171
|
+
def i18n_pluck(*attributes, locale: nil)
|
|
172
|
+
locale ||= I18n.locale
|
|
173
|
+
adapter = Adapters.resolve(connection)
|
|
174
|
+
|
|
175
|
+
pluck_args = attributes.map do |attr|
|
|
176
|
+
if international_attributes.include?(attr.to_sym)
|
|
177
|
+
json_col = "#{attr}_translations"
|
|
178
|
+
Arel.sql(adapter.json_extract(json_col, locale))
|
|
179
|
+
else
|
|
180
|
+
attr
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
pluck(*pluck_args)
|
|
185
|
+
end
|
|
186
|
+
|
|
160
187
|
# Exclude records matching translated attribute conditions
|
|
161
188
|
#
|
|
162
189
|
# @param conditions [Hash] attribute => value pairs to exclude
|