instant18n 0.2.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +6 -1
- data/README.md +3 -3
- data/lib/i18n_extensions.rb +7 -4
- data/lib/instant18n/version.rb +1 -1
- metadata +2 -3
- data/instant18n-0.1.0.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70e940c3b52cf480efc667a894684b4fd197089dcde79e39d8ba9fece75ae30c
|
4
|
+
data.tar.gz: 6cf59ff1278a201388cd78aa7cc58949adaea889164336ece8adc54a8c68fcfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7a485365e333fc26d2ff1f02f4c10d35d33e32469367f25e46640c723cec8dbc80d6f60905eec11c7ddafd1d1278fd162ce15ef131ded90fa0ac186ee37ea8b
|
7
|
+
data.tar.gz: eaef6b047abc7c7690709d8e858460f8e49666ec70ced91e5beaaf4297b01c07bb4c20f9ae27a60f739f45bba9bc1c8c7f8d4260d68c667e948f92d8a242d52c
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
instant18n (0.
|
4
|
+
instant18n (0.3.0)
|
5
5
|
actionview
|
6
6
|
activesupport
|
7
7
|
railties
|
@@ -30,6 +30,7 @@ GEM
|
|
30
30
|
tzinfo (~> 2.0)
|
31
31
|
ast (2.4.2)
|
32
32
|
builder (3.2.4)
|
33
|
+
coderay (1.1.3)
|
33
34
|
concurrent-ruby (1.2.2)
|
34
35
|
crass (1.0.6)
|
35
36
|
diff-lcs (1.5.0)
|
@@ -55,6 +56,9 @@ GEM
|
|
55
56
|
parallel (1.23.0)
|
56
57
|
parser (3.2.2.1)
|
57
58
|
ast (~> 2.4.1)
|
59
|
+
pry (0.14.2)
|
60
|
+
coderay (~> 1.1)
|
61
|
+
method_source (~> 1.0)
|
58
62
|
racc (1.6.2)
|
59
63
|
rack (2.2.6.4)
|
60
64
|
rack-test (2.1.0)
|
@@ -117,6 +121,7 @@ PLATFORMS
|
|
117
121
|
DEPENDENCIES
|
118
122
|
dotenv
|
119
123
|
instant18n!
|
124
|
+
pry
|
120
125
|
rake (~> 13.0)
|
121
126
|
rspec (~> 3.0)
|
122
127
|
rubocop (~> 1.21)
|
data/README.md
CHANGED
@@ -52,11 +52,11 @@ Full description of these options is available [here](https://platform.openai.co
|
|
52
52
|
|
53
53
|
### View Helper
|
54
54
|
|
55
|
-
This gem mixes in an `it` helper method into `ActionView::Base`. For convenience, the helper method assumes the presence of a `current_user` object with a `preferred_language` attribute. If `current_user` is nil, it will use the value of `I18n.
|
55
|
+
This gem mixes in an `it` helper method into `ActionView::Base`. For convenience, the helper method assumes the presence of a `current_user` object with a `preferred_language` attribute. If `current_user` is nil, it will use the value of `I18n.locale` instead.
|
56
56
|
|
57
57
|
### Default Language
|
58
58
|
|
59
|
-
|
59
|
+
We use `I18n.default_locale` as the default language. For performance and practical reasons, if you pass in the default language, GPT is not invoked. Change the default language in an initializer or at runtime by changing the value of the `default_language` property on the `I18n` module.
|
60
60
|
|
61
61
|
```
|
62
62
|
I18n.default_language = "Spanish"
|
@@ -64,7 +64,7 @@ I18n.default_language = "Spanish"
|
|
64
64
|
|
65
65
|
### Anything Goes
|
66
66
|
|
67
|
-
Because GPT is smart and can translate into almost anything that resembles a language, all of the following options are known to work:
|
67
|
+
Because GPT is smart and can translate into almost anything that resembles a language, in addition to standard locale country codes, all of the following options are known to work:
|
68
68
|
* Español
|
69
69
|
* Baby Talk
|
70
70
|
* Baseldeutsch
|
data/lib/i18n_extensions.rb
CHANGED
@@ -11,7 +11,9 @@ module I18n
|
|
11
11
|
attr_accessor :default_language
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
##
|
15
|
+
# Override in case of wanting to leave the locale "as is" but using a different language
|
16
|
+
self.default_language = nil
|
15
17
|
|
16
18
|
##
|
17
19
|
# This method, `it`, instantly translates a given text based on the provided language code.
|
@@ -40,16 +42,17 @@ module I18n
|
|
40
42
|
#
|
41
43
|
# @return [String] the translated text.
|
42
44
|
##
|
43
|
-
def self.it(key, lang, **opts)
|
45
|
+
def self.it(key, lang=nil, **opts)
|
46
|
+
lang = (lang || default_language || I18n.default_locale || "en").to_s
|
44
47
|
opts && opts.symbolize_keys!
|
45
48
|
Rails.cache.fetch(cache_key(key, lang, opts), expires_in: (opts[:expires_in] || 1.year) , force: (opts[:force] || false)) do
|
46
|
-
if lang.casecmp(default_language).zero?
|
49
|
+
if lang.casecmp(default_language.to_s || I18n.default_locale.to_s || "en").zero?
|
47
50
|
key
|
48
51
|
else
|
49
52
|
chat(prompt % { key: key, lang: lang }, directive: DIRECTIVE, **opts)
|
50
53
|
end
|
51
54
|
end.then do |text|
|
52
|
-
text = text.gsub(/^"+|"+$/, '') # remove wrapper double quotes
|
55
|
+
text = text.to_s.gsub(/^"+|"+$/, '') # remove wrapper double quotes
|
53
56
|
if opts[:class].present?
|
54
57
|
tag.div(text, class: "instant18n #{lang.parameterize} #{opts[:class]}")
|
55
58
|
else
|
data/lib/instant18n/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: instant18n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Obie Fernandez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -83,7 +83,6 @@ files:
|
|
83
83
|
- LICENSE.txt
|
84
84
|
- README.md
|
85
85
|
- Rakefile
|
86
|
-
- instant18n-0.1.0.gem
|
87
86
|
- instant18n.gemspec
|
88
87
|
- lib/i18n_extensions.rb
|
89
88
|
- lib/instant18n.rb
|
data/instant18n-0.1.0.gem
DELETED
Binary file
|