aion-request-translations 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bc7a69b3f2dac822ed694c73ee410102fb58f382667d443fb304d579ce7e9cf0
4
+ data.tar.gz: 8d673d22a0bda29056e56e45c8f961ba62edabdbbc76e1953533718467a4bd93
5
+ SHA512:
6
+ metadata.gz: f4d7f180dcaa1752af1cebb0534ef0c5db9c772478dcfec99dd6d06f8628e20ed5d4d229e975d4c6d178ae7d4b5c20e8a1feccae67f2843ab22109e950f4078c
7
+ data.tar.gz: ebbf5e7462f91a1c2dc0551330e37ddd053bf3f6edbc4fbc5ab7c0d694a024fa7c4360bc1003731097e18fb8a9dfe066961873aeeb76bdddb0eaf4f5fff8f87d
@@ -0,0 +1 @@
1
+ require 'aion_request_translations'
@@ -0,0 +1,7 @@
1
+ # This module provides utilities for loading request specific translations in a thread safe manner.
2
+ module AionRequestTranslations
3
+ end
4
+
5
+ require 'aion_request_translations/version'
6
+ require 'aion_request_translations/backend'
7
+ require 'aion_request_translations/railtie' if defined?(Rails::Railtie)
@@ -0,0 +1,41 @@
1
+ require 'i18n'
2
+
3
+ module AionRequestTranslations
4
+
5
+ REQUEST_STORE_KEY = :request_translations
6
+
7
+ # An i18n backend that stores a list of i18n backends on the request.
8
+ # This makes it possible to load translations in a thread safe manner
9
+ # that cleans up after the request.
10
+ class Backend < I18n::Backend::Chain
11
+
12
+ # Adds a i18n backend to the beginning of the chain of backends.
13
+ # @return [I18n::Backend::Base] an array of i18n backends
14
+ def self.add_backend(backend)
15
+ RequestStore.fetch(REQUEST_STORE_KEY) { [] }.unshift(backend)
16
+ end
17
+
18
+ # Adds a i18n backend with the given translations.
19
+ # Translations should be a hash with locale as key.
20
+ #
21
+ # @param translations [Hash] a hash with locale as keys
22
+ # @return [I18n::Backend::Base] an array of i18n backends
23
+ def self.add_translations(translations)
24
+ backend = I18n::Backend::KeyValue.new({}, true)
25
+ translations.each { |locale, data|
26
+ backend.store_translations(locale, data || {})
27
+ }
28
+ add_backend(backend)
29
+ end
30
+
31
+ def backends
32
+ RequestStore[REQUEST_STORE_KEY] ||= []
33
+ end
34
+
35
+ def backends=(backends)
36
+ RequestStore[REQUEST_STORE_KEY] = backends
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,9 @@
1
+ module AionRequestTranslations
2
+ class Railtie < ::Rails::Railtie
3
+
4
+ initializer "aion_request_translations" do
5
+ I18n.backend = I18n::Backend::Chain.new(AionRequestTranslations::Backend.new, I18n.backend)
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module AionRequestTranslations
2
+ VERSION = '1.0.0'
3
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aion-request-translations
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Andersen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-11-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: request_store
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: i18n
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.17.3
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.17.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 12.3.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 12.3.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 5.11.3
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 5.11.3
83
+ description: A i18n backend for loading per request specific translations for a rails
84
+ app in a thread safe manner
85
+ email: michael@aion.dk
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - lib/aion-request-translations.rb
91
+ - lib/aion_request_translations.rb
92
+ - lib/aion_request_translations/backend.rb
93
+ - lib/aion_request_translations/railtie.rb
94
+ - lib/aion_request_translations/version.rb
95
+ homepage: https://github.com/aion-dk/aion-request-translations
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubygems_version: 3.0.3
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Aion request translations
118
+ test_files: []