internationalize 0.5.1 → 0.7.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: 3b0cf11a752999e4dbbbc5d4052c919e98958a4cfc9a289b4bada123f9138574
4
- data.tar.gz: adc607000e536c7858b0b3ab1d3071995575bc7482f7d7c97692a3b90f4a9997
3
+ metadata.gz: 989275d4cd10812f99f919f7c52ed1c91d6a55c17cc4db7a521c94903389dac7
4
+ data.tar.gz: 0170b99a0a5a8e07fdde7205d0a9643ef1433d0b357669f504da0beffc0d3a0d
5
5
  SHA512:
6
- metadata.gz: 61a9c88a71bf96370975b5c1f0163b668ff45163f8c75cc0e151518c992866b2194846081a2259ac876e6ce9eb4ff1a38d2ad9628069f421b4232c2ca377d835
7
- data.tar.gz: 946c06a56af45762973f109a50c132573fbdef72fa26c900ca1478bdacd4f945dfb58e670683bbd9bbdb68a9bfeda1a732ab3913178875be518eb8bd172f67cd
6
+ metadata.gz: 8034cf07c1acb30f5f73e396da40fa5ac12ce793c76d087e516dc4ac5227ab93c148129428724439d56978c363414089ef5ad497fe449898fa7d88188fffb6a3
7
+ data.tar.gz: 7c04d4651dfa21805efe5b08fe2c8eaa24d76029bcd507b3f6a3d7cf627e23fd676d27e4980ef45e24b64ebcba415ac527edf012c0dc25a528a1221a75eb42f4
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
@@ -45,7 +45,8 @@ module Internationalize
45
45
 
46
46
  # Main getter - returns rich text for current locale with fallback to default locale
47
47
  define_method(name) do
48
- locale_str = I18n.locale.to_s
48
+ # Normalize hyphenated locales (e.g., "zh-TW" -> "zh_TW") for method dispatch
49
+ locale_str = I18n.locale.to_s.tr("-", "_")
49
50
  rich_text = send(:"#{name}_#{locale_str}")
50
51
 
51
52
  if rich_text.blank? && locale_str != default_locale_str
@@ -57,7 +58,9 @@ module Internationalize
57
58
 
58
59
  # Main setter - sets rich text for current locale
59
60
  define_method(:"#{name}=") do |value|
60
- send(:"#{name}_#{I18n.locale}=", value)
61
+ # Normalize hyphenated locales (e.g., "zh-TW" -> "zh_TW") for method dispatch
62
+ locale_str = I18n.locale.to_s.tr("-", "_")
63
+ send(:"#{name}_#{locale_str}=", value)
61
64
  end
62
65
 
63
66
  # Predicate method
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Internationalize
4
- VERSION = "0.5.1"
4
+ VERSION = "0.7.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: internationalize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sampo Kuokkanen