RemoteTranslationLoader is a Ruby gem designed to dynamically fetch and load translation files (YAML format) into your Ruby or Ruby on Rails application. It supports multiple sources such as HTTP URLs, local files, and AWS S3, allowing you to seamlessly integrate external translations.
- Fetch translations from multiple sources:
- HTTP URLs
- Local files
- AWS S3 buckets
- Supports deep merging of translations with existing
I18n
backend. - Namespace support for isolating translations.
- Dry-run mode to simulate translation loading.
- Rake tasks for easy integration with Rails applications.
- CLI tool for manual loading.
Add this line to your application's Gemfile:
gem 'remote_translation_loader'
And then execute:
bundle install
Or install it directly:
gem install remote_translation_loader
require 'remote_translation_loader'
urls = ['https://example.com/en.yml', 'https://example.com/fr.yml']
loader = RemoteTranslationLoader::Loader.new(urls)
loader.fetch_and_load
require 'remote_translation_loader'
files = ['/path/to/local/en.yml', '/path/to/local/fr.yml']
loader = RemoteTranslationLoader::Loader.new(files, fetcher: RemoteTranslationLoader::Fetchers::FileFetcher.new)
loader.fetch_and_load
require 'remote_translation_loader'
bucket = 'your-s3-bucket'
s3_fetcher = RemoteTranslationLoader::Fetchers::S3Fetcher.new(bucket, region: 'us-east-1')
keys = ['translations/en.yml', 'translations/fr.yml']
loader = RemoteTranslationLoader::Loader.new(keys, fetcher: s3_fetcher)
loader.fetch_and_load
Add a namespace to group translations under a specific key:
loader.fetch_and_load(namespace: 'remote')
# Translations will be grouped under the `remote` key, e.g., `remote.en.some_key`
Simulate the loading process without modifying the I18n
backend:
loader.fetch_and_load(dry_run: true)
# Outputs fetched translations to the console without loading them
Install the gem globally and use the CLI tool:
remote_translation_loader https://example.com/en.yml /path/to/local/fr.yml
- The CLI fetches and loads the specified translations.
- Add the executable to your
$PATH
for easier access.
Use the provided Rake task to fetch translations in a Rails application:
require 'remote_translation_loader'
load 'remote_translation_loader/tasks/remote_translation_loader.rake'
rake translations:load[https://example.com/en.yml,/path/to/local/fr.yml]
Add an initializer to load translations on application startup:
require 'remote_translation_loader'
urls = ['https://example.com/en.yml', '/path/to/local/fr.yml']
loader = RemoteTranslationLoader::Loader.new(urls)
loader.fetch_and_load(namespace: 'remote')
We welcome contributions! Follow these steps:
- Fork the repository.
- Create your feature branch:
git checkout -b feature/my-new-feature
- Commit your changes:
git commit -m 'Add some feature'
- Push the branch:
git push origin feature/my-new-feature
- Create a pull request.
To work on the gem locally:
- Clone the repository:
git clone https://github.com/gklsan/remote_translation_loader.git cd remote_translation_loader
- Install dependencies:
bundle install
- Run tests:
rspec
This gem is released under the MIT License. See the LICENSE file for details.
A big thanks to the open-source community for the inspiration and support. Special mention to contributors who helped shape this gem!
For questions, bug reports, or feature requests, feel free to open an issue. 🚀