remote_translation_loader 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +136 -0
- data/Rakefile +8 -0
- data/lib/remote_translation_loader/version.rb +5 -0
- data/lib/remote_translation_loader.rb +54 -0
- data/sig/remote_translation_loader.rbs +4 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 43ec77c81cc8eca7e36cd14bae7817a4b6052d21e4207565d05a3d1afb0e2abb
|
4
|
+
data.tar.gz: 10ccc1a5f9e6121ccb4bc2f0402fa482aa10e166cd007b3f1ba84c33c8838934
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 213ea0ccdf50df544041da873bba2d458c7ecf8ea66bc87947aedd42d73a0fcc4d96ec30fe311dcecc67a1d3fbe67d8d5e716291e7f12acc12ea800afa850b46
|
7
|
+
data.tar.gz: d6a6ff5ddea8e87c6709a6eaf453b9880a05d06dc97a0fcdf163200ef465630bb31f74809a712205cd282c4326b932ebfa18387e9fa0734290fd545bd58e2484
|
data/.rspec
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Gokul
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
# Remote Translation Loader
|
2
|
+
|
3
|
+
`remote_translation_loader` is a Ruby gem for fetching YAML translation files from remote sources and dynamically loading them into your Ruby on Rails application’s I18n translations. This gem is useful for applications that need to integrate external translations without writing them to local files.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- Fetch translation files from remote URLs
|
8
|
+
- Merge remote translations with local translations
|
9
|
+
- Directly load translations into Rails I18n without writing to files
|
10
|
+
- Handles YAML parsing errors and HTTP request failures
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'remote_translation_loader'
|
18
|
+
```
|
19
|
+
|
20
|
+
Then execute:
|
21
|
+
|
22
|
+
```bash
|
23
|
+
bundle install
|
24
|
+
```
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
```bash
|
29
|
+
gem install remote_translation_loader
|
30
|
+
```
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
### Basic Setup
|
35
|
+
|
36
|
+
1. **Initialize the Loader**
|
37
|
+
|
38
|
+
Create an instance of the `RemoteTranslationLoader::Loader` class with a list of remote YAML URLs:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
loader = RemoteTranslationLoader::Loader.new([
|
42
|
+
'https://example.com/translations/en.yml',
|
43
|
+
'https://example.com/translations/fr.yml'
|
44
|
+
])
|
45
|
+
```
|
46
|
+
|
47
|
+
2. **Fetch and Load Translations**
|
48
|
+
|
49
|
+
Call the `fetch_and_load` method to fetch and load the translations:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
loader.fetch_and_load
|
53
|
+
```
|
54
|
+
|
55
|
+
This will:
|
56
|
+
- Fetch the YAML files from the specified URLs
|
57
|
+
- Parse the YAML content
|
58
|
+
- Merge the remote translations with your existing local translations
|
59
|
+
- Load the merged translations into Rails I18n
|
60
|
+
|
61
|
+
### Example
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
require 'remote_translation_loader'
|
65
|
+
|
66
|
+
# Initialize the loader with remote YAML URLs
|
67
|
+
loader = RemoteTranslationLoader::Loader.new([
|
68
|
+
'https://example.com/translations/en.yml',
|
69
|
+
'https://example.com/translations/fr.yml'
|
70
|
+
])
|
71
|
+
|
72
|
+
# Fetch and load translations
|
73
|
+
loader.fetch_and_load
|
74
|
+
|
75
|
+
# Now you can use the loaded translations in your application
|
76
|
+
puts I18n.t('greetings.hello') # Output will depend on the remote translation files
|
77
|
+
```
|
78
|
+
|
79
|
+
### Handling Errors
|
80
|
+
|
81
|
+
The gem will raise errors in case of:
|
82
|
+
- **Invalid YAML Content**: If the remote YAML file is invalid, a `RuntimeError` will be raised with a message indicating a YAML parsing error.
|
83
|
+
- **HTTP Request Failures**: If fetching the remote YAML file fails, a `RuntimeError` will be raised with a message indicating the failure.
|
84
|
+
|
85
|
+
### Customizing Error Handling
|
86
|
+
|
87
|
+
You can customize the error handling by rescuing from `RuntimeError` or any other specific exceptions as needed:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
begin
|
91
|
+
loader.fetch_and_load
|
92
|
+
rescue RuntimeError => e
|
93
|
+
puts "An error occurred: #{e.message}"
|
94
|
+
end
|
95
|
+
```
|
96
|
+
|
97
|
+
## Development
|
98
|
+
|
99
|
+
To contribute to the development of `remote_translation_loader`, follow these steps:
|
100
|
+
|
101
|
+
1. **Clone the Repository**
|
102
|
+
|
103
|
+
```bash
|
104
|
+
git clone https://github.com/gklsan/remote_translation_loader.git
|
105
|
+
cd remote_translation_loader
|
106
|
+
```
|
107
|
+
|
108
|
+
2. **Install Dependencies**
|
109
|
+
|
110
|
+
```bash
|
111
|
+
bundle install
|
112
|
+
```
|
113
|
+
|
114
|
+
3. **Run Tests**
|
115
|
+
|
116
|
+
Run the test suite to ensure everything is working correctly:
|
117
|
+
|
118
|
+
```bash
|
119
|
+
bundle exec rspec
|
120
|
+
```
|
121
|
+
|
122
|
+
4. **Make Your Changes**
|
123
|
+
|
124
|
+
Implement your changes or features and ensure they are covered by tests.
|
125
|
+
|
126
|
+
5. **Submit a Pull Request**
|
127
|
+
|
128
|
+
Push your changes to your forked repository and submit a pull request with a clear description of the changes.
|
129
|
+
|
130
|
+
## License
|
131
|
+
|
132
|
+
`remote_translation_loader` is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
|
133
|
+
|
134
|
+
## Contact
|
135
|
+
|
136
|
+
For questions or support, please open an issue on [GitHub](https://github.com/gklsan/remote_translation_loader/issues).
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "remote_translation_loader/version"
|
4
|
+
|
5
|
+
require 'http'
|
6
|
+
require 'yaml'
|
7
|
+
require 'i18n'
|
8
|
+
|
9
|
+
module RemoteTranslationLoader
|
10
|
+
class Loader
|
11
|
+
def initialize(urls)
|
12
|
+
@urls = urls
|
13
|
+
end
|
14
|
+
|
15
|
+
def fetch_and_load
|
16
|
+
@urls.each do |url|
|
17
|
+
yml_content = fetch_yaml(url)
|
18
|
+
merge_into_i18n(yml_content)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def fetch_yaml(url)
|
25
|
+
response = HTTP.get(url)
|
26
|
+
raise "Failed to fetch YAML from #{url}" unless response.status.success?
|
27
|
+
|
28
|
+
begin
|
29
|
+
YAML.safe_load(response.body.to_s)
|
30
|
+
rescue Psych::SyntaxError => e
|
31
|
+
raise "Failed to parse YAML from #{url}: #{e.message}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def merge_into_i18n(yml_content)
|
36
|
+
yml_content.each do |locale, remote_translations|
|
37
|
+
if remote_translations.is_a?(Hash)
|
38
|
+
existing_translations = I18n.backend.send(:translations)[locale.to_sym] || {}
|
39
|
+
merged_translations = deep_merge(existing_translations, remote_translations)
|
40
|
+
|
41
|
+
I18n.backend.store_translations(locale.to_sym, merged_translations)
|
42
|
+
else
|
43
|
+
raise "Invalid data format for locale #{locale}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def deep_merge(existing, incoming)
|
49
|
+
existing.merge(incoming) do |key, oldval, newval|
|
50
|
+
oldval.is_a?(Hash) && newval.is_a?(Hash) ? deep_merge(oldval, newval) : newval
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: remote_translation_loader
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gokul (gklsan)
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-09-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: http
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: yaml
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: i18n
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: The remote_translation_loader gem allows you to fetch YAML translation
|
70
|
+
files from remote sources and dynamically load them into your Rails application’s
|
71
|
+
I18n translations without writing them to local files.
|
72
|
+
email:
|
73
|
+
- pgokulmca@gmail.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".rspec"
|
79
|
+
- CODE_OF_CONDUCT.md
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- lib/remote_translation_loader.rb
|
84
|
+
- lib/remote_translation_loader/version.rb
|
85
|
+
- sig/remote_translation_loader.rbs
|
86
|
+
homepage: https://github.com/gklsan/remote_translation_loader
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 3.0.0
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubygems_version: 3.5.17
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Fetches and loads remote YAML translation files into Rails I18n
|
109
|
+
test_files: []
|