active_translate_self 0.3.0 → 1.0.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: 8be859b957fdf07c519a5c1afb68e870bfdee5854a81d329cf76029133a5efb6
4
- data.tar.gz: 91231060b8ebb7a55dab987c6382d795b10b928c23e853e72637adfa76965571
3
+ metadata.gz: ea46376b159e99d84a808f6f5397eaa54b8823c1f3b5daeadd47fc5cbbf1d5f7
4
+ data.tar.gz: af5b7959d06f1277d4b0b723f781d20b083c309e388ab90b8177895b0c9397d3
5
5
  SHA512:
6
- metadata.gz: 5501a76025408a66aed069b2b535316943a19d7c08e9d0d2ae7400619e4bd8e95c814b6b70e08ab31375b491ae818fd6ce53de06d0065765a9951863d7adc0a1
7
- data.tar.gz: bf8dd0cbae15e93188a2e6ffd21c0fe6710b919be289771fb9ea3f1d5ef0d24e8a8f8f6aacfb3a109654f45c61ff3e9946a5caaa0a2e43aa0063da6600b57951
6
+ metadata.gz: 0fc4ed47074d2525fd2d31a7ba874c907ef4d2bc819e1e03941fa13ee8158564c4becef2132ef6309b02b07ba331fbbbfb02e3a34fdd42430fe52430ef77a96e
7
+ data.tar.gz: b220f68b81a08c1af6878e73f194141262fd344b09f08de6f647212e7125fe50841c6f98cd17a74ef31e7ef31bb23b4f2e04f89778e227469132106d885ec0ed
data/README.md CHANGED
@@ -14,6 +14,29 @@ Any and all languages supported, as long as they're also supported by DeepL. If
14
14
 
15
15
  supported languages are: Bulgarian, Chinese, Czech, Danish, Dutch, English, Estonian, Finnish, French, German, Greek, Hungarian, Italian, Japanese, Latvian, Lithuanian, Polish, Portuguese, Romanian, Russian, Slovak, Slovenian, Spanish, and Swedish.
16
16
 
17
+ ## Automatic translations with I18n ActiveRecord backend
18
+
19
+ So first, install the ActiveRecord backend for I18n from the link below:
20
+ [svenfuchs/i18n-active_record: I18n ActiveRecord backend](https://github.com/svenfuchs/i18n-active_record)
21
+
22
+ Then, include the following in your `config/initializers/i18n_active_record.rb`:
23
+
24
+ ```ruby
25
+ if I18n::Backend::ActiveRecord::Translation.table_exists?
26
+ I18n.backend = I18n::Backend::ActiveRecord.new
27
+ I18n::Backend::ActiveRecord.include I18n::Backend::Memoize
28
+ I18n::Backend::Simple.include I18n::Backend::Memoize
29
+ I18n::Backend::Simple.include I18n::Backend::Pluralization
30
+ # This is the monkeypatch!
31
+ I18n::Backend::ActiveRecord::Missing.prepend ActiveTranslateSelf::Missing
32
+ I18n::Backend::Simple.include I18n::Backend::ActiveRecord::Missing
33
+
34
+ I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Simple.new, I18n.backend)
35
+ end
36
+ ```
37
+
38
+ Now just add a new translation language to your app, and it will be automatically translated using the default language's translation.
39
+
17
40
  ## Usage
18
41
  Easy to use!
19
42
 
@@ -2,6 +2,9 @@
2
2
 
3
3
  require 'translate_self/translation'
4
4
 
5
- class String
6
- include Translation
5
+ module ActiveTranslateSelf
6
+ module CoreExt
7
+ include Translation
8
+ end
7
9
  end
10
+ String.include ActiveTranslateSelf::CoreExt
@@ -0,0 +1,11 @@
1
+ module ActiveTranslateSelf
2
+ module Missing
3
+ def store_default_translation(locale, key, interpolations)
4
+ translation = I18n::Backend::ActiveRecord::Translation.new locale: locale.to_s, key: key
5
+ default = I18n.t(key, locale: I18n.default_locale)
6
+ translation.value = default.public_send "to_#{locale}" if default.respond_to?("to_#{locale}")
7
+ translation.interpolations = interpolations
8
+ translation.save
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveTranslateSelf
4
- VERSION = '0.3.0'
4
+ VERSION = '1.0.0'
5
5
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_translate_self/version'
4
- require 'active_translate_self/engine'
5
- require 'active_translate_self/core_ext'
3
+ require 'zeitwerk'
4
+ loader = Zeitwerk::Loader.for_gem
5
+ loader.setup # ready!
6
6
 
7
7
  # A Rails engine that connects TranslateSelf to Rails
8
8
  module ActiveTranslateSelf
@@ -16,3 +16,5 @@ module ActiveTranslateSelf
16
16
  end
17
17
  end
18
18
  end
19
+
20
+ loader.eager_load # optionally
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_translate_self
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sampo Kuokkanen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-13 00:00:00.000000000 Z
11
+ date: 2022-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: translate_self
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.3.0
33
+ version: '1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.3.0
40
+ version: '1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: byebug
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -75,6 +75,7 @@ files:
75
75
  - lib/active_translate_self.rb
76
76
  - lib/active_translate_self/core_ext.rb
77
77
  - lib/active_translate_self/engine.rb
78
+ - lib/active_translate_self/missing.rb
78
79
  - lib/active_translate_self/version.rb
79
80
  - lib/tasks/active_translate_self_tasks.rake
80
81
  homepage: https://github.com/sampokuokkanen/ActiveTranslateSelf
@@ -84,7 +85,8 @@ metadata:
84
85
  homepage_uri: https://github.com/sampokuokkanen/ActiveTranslateSelf
85
86
  source_code_uri: https://github.com/sampokuokkanen/ActiveTranslateSelf
86
87
  changelog_uri: https://github.com/sampokuokkanen/ActiveTranslateSelf/blob/main/CHANGELOG.md
87
- post_install_message:
88
+ rubygems_mfa_required: 'true'
89
+ post_install_message:
88
90
  rdoc_options: []
89
91
  require_paths:
90
92
  - lib
@@ -92,15 +94,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
94
  requirements:
93
95
  - - ">="
94
96
  - !ruby/object:Gem::Version
95
- version: 2.5.0
97
+ version: 2.7.0
96
98
  required_rubygems_version: !ruby/object:Gem::Requirement
97
99
  requirements:
98
100
  - - ">="
99
101
  - !ruby/object:Gem::Version
100
102
  version: '0'
101
103
  requirements: []
102
- rubygems_version: 3.2.15
103
- signing_key:
104
+ rubygems_version: 3.3.3
105
+ signing_key:
104
106
  specification_version: 4
105
107
  summary: ActiveTranslateSelf provides the strings in Rails an ability to translate
106
108
  themselves.