internationalize 0.2.0 → 0.2.1

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: 520c17d4993a0145c00081a95a30f21c9a3b56b0879589fc87f4731564be7f1e
4
- data.tar.gz: 24478d271a6500c4104c8e26db4238ed1857b533b25e5c351e30cfc45fe7c13a
3
+ metadata.gz: 25678f8238179260f1496807a1a68a20d86e09e72e7d7c4097c4b14f41b060ec
4
+ data.tar.gz: b713e70a91f521041975b86e6e22be2239ebfddbd3c9867691c55ecf8fbfb380
5
5
  SHA512:
6
- metadata.gz: a15ca8db8848c85feec7d912c47905a0cbd665aed43721642b97e039f607699edbeb207666d3af98e92e412d6c6ac0c89298b4ac4aba5c9643bf2554c2f59a08
7
- data.tar.gz: b380cf31e89bd26994935e733c89df8b23771e83a73606f39dd6092f833aec11f0a4e471ec8c8c8ff914cd3079a15b0d05a4d016962936adc707302acaec5683
6
+ metadata.gz: 433cc8be47c2df3d5e48abf8eaa6cd0550cbe4ceaaf3fde9700ad08c82be24488eb5b7a52d8ec4b6555880119d8c961a451841ddeed9a52d2a455792ae5eb69d
7
+ data.tar.gz: e6656a5c811920e9e4b4b2184ee5b981496296f3588182d3ce2f53e6bcb9328b0051c210830c01d2eb23a9fea5fe3151181a5adb7d08c5222eac08a67c2661ac
data/CHANGELOG.md CHANGED
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
14
14
  - ActionText support via `international_rich_text` (optional, requires ActionText)
15
15
  - Generates `has_rich_text` for each locale with unified accessor
16
16
  - Full attachment support per locale
17
+ - Validation for `title_translations=` setter - rejects non-Hash values and invalid locales
17
18
 
18
19
  ### Removed
19
20
 
@@ -86,6 +86,7 @@ Article.international_order(:title, :desc)
86
86
  - No JOINs - data lives in the same table
87
87
  - Automatic fallback to default locale
88
88
  - Works with SQLite, PostgreSQL, and MySQL
89
+ - ActionText support via `international_rich_text` (see Model API)
89
90
 
90
91
  ## Important: Column Defaults
91
92
 
data/context/model-api.md CHANGED
@@ -21,7 +21,7 @@ For each `international :title` declaration:
21
21
  | `title=` | Set translation for current `I18n.locale` |
22
22
  | `title?` | Check if translation exists |
23
23
  | `title_translations` | Get raw hash of all translations |
24
- | `title_translations=` | Set all translations at once |
24
+ | `title_translations=` | Set all translations at once (validates locale keys) |
25
25
 
26
26
  ### Locale-Specific Accessors
27
27
 
@@ -79,3 +79,39 @@ article.title_en = "Hello"
79
79
  I18n.locale = :de
80
80
  article.title # => "Hello" (falls back to default locale)
81
81
  ```
82
+
83
+ ## ActionText Support
84
+
85
+ For rich text with attachments, use `international_rich_text` (requires ActionText):
86
+
87
+ ```ruby
88
+ require "internationalize/rich_text"
89
+
90
+ class Article < ApplicationRecord
91
+ include Internationalize::Model
92
+ include Internationalize::RichText
93
+
94
+ international_rich_text :content
95
+ end
96
+ ```
97
+
98
+ This generates `has_rich_text :content_en`, `has_rich_text :content_de`, etc. for each locale.
99
+
100
+ ### Generated Methods
101
+
102
+ | Method | Description |
103
+ |--------|-------------|
104
+ | `content` | Get rich text for current locale (with fallback) |
105
+ | `content=` | Set rich text for current locale |
106
+ | `content?` | Check if rich text exists |
107
+ | `content_en` | Direct access to English rich text |
108
+ | `content_de` | Direct access to German rich text |
109
+ | `content_translated?(:de)` | Check if translation exists |
110
+ | `content_translated_locales` | Array of locales with content |
111
+
112
+ ```ruby
113
+ article.content = "<p>Hello</p>" # Sets for current locale
114
+ article.content # Gets for current locale (with fallback)
115
+ article.content.body # ActionText::Content object
116
+ article.content.embeds # Attachments work per-locale
117
+ ```
@@ -324,7 +324,21 @@ module Internationalize
324
324
 
325
325
  # Set all translations at once
326
326
  define_method("#{attr}_translations=") do |hash|
327
- write_attribute(translations_column, hash&.stringify_keys || {})
327
+ return write_attribute(translations_column, {}) if hash.nil?
328
+
329
+ unless hash.is_a?(Hash)
330
+ raise ArgumentError, "#{attr}_translations must be a Hash, got #{hash.class}"
331
+ end
332
+
333
+ allowed_locales = Internationalize.locales.map(&:to_s)
334
+ hash.each_key do |key|
335
+ unless allowed_locales.include?(key.to_s)
336
+ raise ArgumentError, "Invalid locale '#{key}' for #{attr}_translations. " \
337
+ "Allowed locales: #{allowed_locales.join(', ')}"
338
+ end
339
+ end
340
+
341
+ write_attribute(translations_column, hash.stringify_keys)
328
342
  end
329
343
  end
330
344
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Internationalize
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sampo Kuokkanen