remote_i18n_extension 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7534fa537c20f856e3ad95d19b8108731289d5966a2fdde6b72d90420e7f1652
4
+ data.tar.gz: 4a974f71c326f864d06d76aa3c00f6b7a06733386081693b0e16a193bad8272f
5
+ SHA512:
6
+ metadata.gz: 42d66376720540baff95b4f1de7556eaa3a920750fc73912f5162db4e6d68a2b89a978a655bd754ffcbc6f0ae8db82c685497b8f4777d6fd29a49cb418c564f9
7
+ data.tar.gz: '08f0700de67562a9a619306c6b10f5f2339d04571698a93ca199de5e18990e3b80d09d5b2f6911abb9b19b4c687b238f3d70f642f868a170e8f06200a39e55e6'
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0 (06-May-23)
4
+
5
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # Remote-I18n-Extension-Hcc
2
+
3
+ This gem provides an extension to the exsiting url(https://github.com/ruby-i18n/i18n)[I18n] gem by providing the ability to fetch locales from remote files
4
+
5
+
6
+ # Getting Started
7
+
8
+ # Requirements
9
+ This gem requires `ruby 3.1.3` and `Rails 7.0.4.3`
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'rake'
2
+ require 'rubocop/rake_task'
3
+
4
+ RuboCop::RakeTask.new do |task|
5
+ task.requires << 'rubocop-performance'
6
+ task.requires << 'rubocop-rspec'
7
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails/generators'
2
+
3
+ module RemoteI18nExtensionHcc
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __dir__)
6
+
7
+ desc 'Creates config file for RemoteI18nExtensionHcc'
8
+
9
+ def copy_config
10
+ template 'remote_i18n_extension_config.rb', "#{Rails.root}/config/remote_i18n_extension.rb"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ require 'remote_i18n_extension'
2
+
3
+ RemoteI18nExtensionHcc.config do |config|
4
+ # All the configurations are mandatory
5
+
6
+ # URL to your remote locales folder housing all the translations
7
+ # Please make sure the file structure inside this folder mirrors your local locales folder
8
+ # for fallback
9
+ # e.g. https://github.com/Gooner91/locales-repo/tree/master/locales
10
+ # config.remote_host = ENV['LOCALES_REMOTE_HOST']
11
+
12
+
13
+ # Below configurations are for the ruby I18n module
14
+
15
+ # List of available locales
16
+ # config.available_locales = [:en, :de]
17
+
18
+
19
+ # config.locale = :en
20
+
21
+ # Paths to the translation files
22
+ # Please make sure the paths to the translation files is same for local and remote locales folder
23
+ # %w[locales/devise.de.yml locales/devise.en.yml ]
24
+ # config.load_path = %w[]
25
+ end
@@ -0,0 +1,43 @@
1
+ require 'open-uri'
2
+
3
+ module RemoteI18nExtensionHcc
4
+ module Backend
5
+ class Remote < I18n::Backend::Simple
6
+ protected
7
+
8
+ # Overrides load_yml method in Simple backend to load translation from
9
+ # the provided remote host otherwise return hash to suppress any error and
10
+ # fallback to Simple backend fetching translations from locale files.
11
+ def load_yml(filename)
12
+ YAML.load(load_remote_locales(filename))
13
+ rescue TypeError, ScriptError, StandardError
14
+ {}
15
+ end
16
+
17
+ # Overrides load_json method in Simple backend to load translation from
18
+ # the provided remote host otherwise return hash to suppress any error and
19
+ # fallback to Simple backend fetching translations from locale files.
20
+ def load_json(filename)
21
+ JSON.parse(load_remote_locales(filename))
22
+ rescue TypeError, StandardError
23
+ {}
24
+ end
25
+
26
+ # Overrides load_rb method in Simple backend to load translation from
27
+ # the provided remote host otherwise return hash to suppress any error and
28
+ # fallback to Simple backend fetching translations from locale files.
29
+ def load_rb(filename)
30
+ eval(load_remote_locales(filename), binding, filename)
31
+ rescue StandardError
32
+ {}
33
+ end
34
+
35
+ private
36
+
37
+ def load_remote_locales(filename)
38
+ remote_host = RemoteI18nExtensionHcc.remote_host
39
+ URI.parse("#{remote_host}/#{filename}").read
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module RemoteI18nExtensionHcc
2
+ VERSION = '1.0.0'.freeze
3
+ end
@@ -0,0 +1,44 @@
1
+ require 'i18n'
2
+ require_relative 'remote_i18n_extension/backend/remote'
3
+
4
+ module RemoteI18nExtensionHcc
5
+ I18n.backend = I18n::Backend::Chain.new(
6
+ RemoteI18nExtensionHcc::Backend::Remote.new,
7
+ I18n::Backend::Simple.new
8
+ )
9
+
10
+ class << self
11
+ attr_reader :load_path, :available_locales, :locale
12
+ attr_accessor :remote_host
13
+
14
+ def config
15
+ yield self
16
+ end
17
+
18
+ def locale=(locale)
19
+ I18n.locale = locale || :en
20
+ end
21
+
22
+ def load_path=(paths_array)
23
+ I18n.load_path += paths_array
24
+ end
25
+
26
+ def available_locales=(locales_array)
27
+ I18n.available_locales = locales_array ? locales_array : [:en]
28
+ end
29
+
30
+ def translate(*args)
31
+ I18n.t(*args)
32
+ end
33
+ alias :t :translate
34
+ end
35
+
36
+ private
37
+
38
+ def init_i18n_backend
39
+ I18n.backend = I18n::Backend::Chain.new(
40
+ RemoteI18nExtensionHcc::Backend::Remote.new,
41
+ I18n::Backend::Simple.new
42
+ )
43
+ end
44
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path('lib/remote_i18n_extension/version', __dir__)
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'remote_i18n_extension'
5
+ spec.version = RemoteI18nExtensionHcc::VERSION
6
+ spec.authors = ['Hassan Ahmed']
7
+ spec.email = ['hassan91ahmed@gmail.com']
8
+ spec.summary = 'Support remote fetching of locales'
9
+ spec.description = 'Support remote fetching of locales'
10
+ spec.homepage = 'https://github.com/Gooner91/remoteI18nExtensionHcc'
11
+ spec.license = 'MIT'
12
+ spec.platform = Gem::Platform::RUBY
13
+ spec.required_ruby_version = '>=3.1.3'
14
+ spec.files = Dir['README.md', 'LICENSE',
15
+ 'CHANGELOG.md', 'lib/**/*.rb',
16
+ 'lib/**/*.rake',
17
+ 'remote_i18n_extension.gemspec', '.github/*.md',
18
+ 'Gemfile', 'Rakefile']
19
+ spec.add_dependency 'i18n', '~> 1.13.0'
20
+ spec.add_dependency 'rubocop-performance', '~> 1.17.1'
21
+ spec.add_dependency 'rubocop-rails', '~> 2.19.1'
22
+ spec.add_dependency 'rubocop-rspec', '~> 2.21.0'
23
+ spec.add_dependency 'rspec-rails', '~> 6.0.2'
24
+ spec.metadata['rubygems_mfa_required'] = 'true'
25
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: remote_i18n_extension
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Hassan Ahmed
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-05-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: i18n
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.13.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.13.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop-performance
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.17.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.17.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.19.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.19.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.21.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.21.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 6.0.2
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 6.0.2
83
+ description: Support remote fetching of locales
84
+ email:
85
+ - hassan91ahmed@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - CHANGELOG.md
91
+ - Gemfile
92
+ - README.md
93
+ - Rakefile
94
+ - lib/generators/remote_i18n_extension/install_generator.rb
95
+ - lib/generators/templates/remote_i18n_extension_config.rb
96
+ - lib/remote_i18n_extension.rb
97
+ - lib/remote_i18n_extension/backend/remote.rb
98
+ - lib/remote_i18n_extension/version.rb
99
+ - remote_i18n_extension.gemspec
100
+ homepage: https://github.com/Gooner91/remoteI18nExtensionHcc
101
+ licenses:
102
+ - MIT
103
+ metadata:
104
+ rubygems_mfa_required: 'true'
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: 3.1.3
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubygems_version: 3.4.12
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Support remote fetching of locales
124
+ test_files: []