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 +4 -4
- data/README.md +23 -0
- data/lib/active_translate_self/core_ext.rb +5 -2
- data/lib/active_translate_self/missing.rb +11 -0
- data/lib/active_translate_self/version.rb +1 -1
- data/lib/active_translate_self.rb +5 -3
- metadata +13 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea46376b159e99d84a808f6f5397eaa54b8823c1f3b5daeadd47fc5cbbf1d5f7
|
4
|
+
data.tar.gz: af5b7959d06f1277d4b0b723f781d20b083c309e388ab90b8177895b0c9397d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
@@ -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,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
|
5
|
-
|
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.
|
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:
|
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:
|
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:
|
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
|
-
|
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.
|
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.
|
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.
|