rodauth-i18n 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d035217bfe2466bbd5b689d59b3469b15dfd9eb5b5b70ac00a2a6868c22108c2
4
- data.tar.gz: 1844d4468c69fe7e28704ad0bbcfd9c3c79a5b750bff23552a137a6e3f233a8d
3
+ metadata.gz: 017c38a897546999927ec0acb752e2e5315bc895199ec95cdde3f2fd1b5ae85d
4
+ data.tar.gz: 3173ef8d111825aea4e7f48433e72ad6b3dcfd1cf0453e6cb7f2e7a024903452
5
5
  SHA512:
6
- metadata.gz: a3f3b650c95ee21371ac5f3c2e5cc068af598b16430890b5e695feac42ccbacef5523d3f31f4e571f71d8c4219dff1f8d1f754f4c77d2c0ea5692a6a4465642a
7
- data.tar.gz: 39cd36cc115f0e54c905c442b5c70971369245cd95901c6d191ac5221afff13ef34b033dd683fe0c90a03aa3c19656f774e49c16c096eb693a3ce341d06b210b
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
- This will make translations go through the [I18n] gem, and will automatically load translations for locales specified in `I18n.available_locales` (if unset, translations for *all* locales will be loaded).
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:i18n:translations` generator, which receives a list of locales to copy translations for:
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:i18n:translations en hr
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "rodauth-i18n"
5
- spec.version = "0.2.1"
5
+ spec.version = "0.3.0"
6
6
  spec.authors = ["Janko Marohnić"]
7
7
  spec.email = ["janko@hey.com"]
8
8
 
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.2.1
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-23 00:00:00.000000000 Z
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/i18n/translations_generator.rb
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