rodauth-i18n 0.2.1 → 0.3.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 +15 -4
- data/lib/generators/rodauth/translations_generator.rb +37 -0
- data/rodauth-i18n.gemspec +1 -1
- metadata +3 -3
- data/lib/generators/rodauth/i18n/translations_generator.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 017c38a897546999927ec0acb752e2e5315bc895199ec95cdde3f2fd1b5ae85d
|
4
|
+
data.tar.gz: 3173ef8d111825aea4e7f48433e72ad6b3dcfd1cf0453e6cb7f2e7a024903452
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc1047e0a25041e178c839b680070352265d0aaf355b008912fac23f70ec17b4cbf7b8b663d95383cddecfe61f4f9a31818d1ddb6bf861fe72c74423882b487d
|
7
|
+
data.tar.gz: 5a83eb687df9fb3080edea0fbc00079bb5b59b4d7c5c10a6e0507c25222dfa2bf13075be6c7110dcf3233295df817e3c87d9d6240d270978f5f5368694d7ecef
|
data/README.md
CHANGED
@@ -26,7 +26,7 @@ $ gem install rodauth-i18n
|
|
26
26
|
|
27
27
|
## Usage
|
28
28
|
|
29
|
-
Enable the `i18n` feature in your Rodauth configuration
|
29
|
+
Enable the `i18n` feature in your Rodauth configuration, which overrides Rodauth's `#translate` method to use the [I18n] gem.
|
30
30
|
|
31
31
|
```rb
|
32
32
|
plugin :rodauth do
|
@@ -35,7 +35,7 @@ plugin :rodauth do
|
|
35
35
|
end
|
36
36
|
```
|
37
37
|
|
38
|
-
|
38
|
+
Enabling the feature will automatically load built-in translations for locales specified in `I18n.available_locales`. If unset, translations for *all* locales will be loaded.
|
39
39
|
|
40
40
|
### Per configuration translations
|
41
41
|
|
@@ -71,12 +71,15 @@ i18n_cascade? false
|
|
71
71
|
|
72
72
|
### Copying translations
|
73
73
|
|
74
|
-
In a Rails app, you can copy built-in translations into your app via the `rodauth:
|
74
|
+
In a Rails app, you can copy built-in translations into your app via the `rodauth:translations` generator. By default, it will import translations for available locales, but you can also give it a list of locales:
|
75
75
|
|
76
76
|
```sh
|
77
|
-
$ rails generate rodauth:
|
77
|
+
$ rails generate rodauth:translations en hr
|
78
78
|
# create config/locales/rodauth.en.yml
|
79
79
|
# create config/locales/rodauth.hr.yml
|
80
|
+
|
81
|
+
$ rails generate rodauth:translations
|
82
|
+
# imports translations for available locales
|
80
83
|
```
|
81
84
|
|
82
85
|
On other web frameworks, you can copy the translation files directly from the `locales/` directory.
|
@@ -97,6 +100,14 @@ In some cases it can be useful to fall back to untranslated value when the trans
|
|
97
100
|
i18n_fallback_to_untranslated? { Rails.env.production? }
|
98
101
|
```
|
99
102
|
|
103
|
+
### Available locales
|
104
|
+
|
105
|
+
If you want to load translations for a set of locales different than `I18n.available_locales`, you can configure that:
|
106
|
+
|
107
|
+
```rb
|
108
|
+
i18n_available_locales [:en, :pt]
|
109
|
+
```
|
110
|
+
|
100
111
|
### Overriding current locale
|
101
112
|
|
102
113
|
The current locale defaults to `I18n.locale`, but you can override that:
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "rails/generators/base"
|
2
|
+
|
3
|
+
module Rodauth
|
4
|
+
module Rails
|
5
|
+
class TranslationsGenerator < ::Rails::Generators::Base
|
6
|
+
source_root File.expand_path("#{__dir__}/../../../locales")
|
7
|
+
namespace "rodauth:translations"
|
8
|
+
|
9
|
+
argument :selected_locales, type: :array, required: false,
|
10
|
+
desc: "List of locales to copy translation files for"
|
11
|
+
|
12
|
+
def copy_locales
|
13
|
+
locales.each do |locale|
|
14
|
+
copy_file("#{locale}.yml", "config/locales/rodauth.#{locale}.yml")
|
15
|
+
end
|
16
|
+
|
17
|
+
say "No locales specified!", :yellow if locales.empty?
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def locales
|
23
|
+
selected_locales || available_locales
|
24
|
+
end
|
25
|
+
|
26
|
+
def available_locales
|
27
|
+
rodauths.inject([]) do |locales, rodauth|
|
28
|
+
locales |= rodauth.allocate.send(:i18n_available_locales) || []
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def rodauths
|
33
|
+
Rodauth::Rails.app.opts[:rodauths].values
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/rodauth-i18n.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rodauth-i18n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janko Marohnić
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rodauth
|
@@ -117,7 +117,7 @@ extra_rdoc_files: []
|
|
117
117
|
files:
|
118
118
|
- LICENSE.txt
|
119
119
|
- README.md
|
120
|
-
- lib/generators/rodauth/
|
120
|
+
- lib/generators/rodauth/translations_generator.rb
|
121
121
|
- lib/rodauth/features/i18n.rb
|
122
122
|
- lib/rodauth/i18n/login_password_requirements_base.rb
|
123
123
|
- locales/en.yml
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require "rails/generators/base"
|
2
|
-
|
3
|
-
module Rodauth
|
4
|
-
module I18n
|
5
|
-
class TranslationsGenerator < ::Rails::Generators::Base
|
6
|
-
source_root File.expand_path("#{__dir__}/../../../../locales")
|
7
|
-
|
8
|
-
argument :locales, type: :array, desc: "List of locales to copy translation files for"
|
9
|
-
|
10
|
-
def copy_locales
|
11
|
-
locales.each do |locale|
|
12
|
-
copy_file("#{locale}.yml", "config/locales/rodauth.#{locale}.yml")
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|