Skip to content

Web interface to manage i18n translations helping to facilitate the editors of your translations. Provides a low-tech and complete workflow for importing, translating, and exporting your I18n translation files. Designed to allow you to keep the translation files inside your projects git repository where they should be.

License

Notifications You must be signed in to change notification settings

westonganger/rails_i18n_manager

Repository files navigation

Rails I18n Manager

A complete translation editor and workflow

Gem Version CI Status

Web interface to manage i18n translations helping to facilitate the editors of your translations. Provides a low-tech and complete workflow for importing, translating, and exporting your I18n translation files. Designed to allow you to keep the translation files inside your projects git repository where they should be.

Features:

  • Import & export translations using standard i18n YAML/JSON files
  • Allows managing translations for any number of apps
  • Built in support for Google Translation for missing translations
  • Provides an API end point to perform automated downloads of your translations

Screenshots

Screenshot

Screenshot

Screenshot

Setup

Developed as a Rails engine. So you can add to any existing app or create a brand new app with the functionality.

First add the gem to your Gemfile

### Gemfile
gem "rails_i18n_manager"

Then install and run the database migrations

bundle install
bundle exec rake rails_i18n_manager:install:migrations
bundle exec rake db:migrate

Routes

Option A: Mount to a path

### config/routes.rb

### As sub-path
mount RailsI18nManager::Engine, at: "/rails_i18n_manager", as: "rails_i18n_manager"

### OR as root-path
mount RailsI18nManager::Engine, at: "/", as: "rails_i18n_manager"

Option B: Mount to a subdomain

### config/routes.rb

translations_engine_subdomain = "translations"

mount RailsI18nManager::Engine,
  at: "/", as: "translations_engine",
  constraints: Proc.new{|request| request.subdomain == translations_engine_subdomain }

not_engine = Proc.new{|request| request.subdomain != translations_engine_subdomain }

constraints not_engine do
  # your app routes here...
end

Configuration

### config/initializers/rails_i18n_manager.rb

RailsI18nManager.config do |config|
  config.google_translate_api_key = ENV.fetch("GOOGLE_TRANSLATE_API_KEY", nil)

  ### You can use our built-in list of all locales Google Translate supports
  ### OR make your own list. These need to be supported by Google Translate
  # config.valid_locales = ["en", "es", "fr"]
end

Customizing Authentication

### config/routes.rb

### Using Devise
authenticated :user do
  mount RailsI18nManager::Engine, at: "/rails_i18n_manager", as: "rails_i18n_manager"
end

### Custom devise-like
constraints ->(req){ req.session[:user_id].present? && User.find_by(id: req.session[:user_id]) } do
  mount RailsI18nManager::Engine, at: "/rails_i18n_manager", as: "rails_i18n_manager"
end

### HTTP Basic Auth
with_http_basic_auth = ->(engine){
  Rack::Builder.new do
    use Rack::Auth::Basic do |username, password|
      ActiveSupport::SecurityUtils.secure_compare(::Digest::SHA256.hexdigest(username), ::Digest::SHA256.hexdigest(ENV.fetch("RAILS_I18N_MANAGER_USERNAME"))) &&
        ActiveSupport::SecurityUtils.secure_compare(::Digest::SHA256.hexdigest(password), ::Digest::SHA256.hexdigest(ENV.fetch("RAILS_I18N_MANAGER_PASSWORD")))
    end
    run(engine)
  end
}
mount with_http_basic_auth.call(RailsI18nManager::Engine), at: "/rails_i18n_manager", as: "rails_i18n_manager"

API Endpoint

We provide an endpoint to retrieve your translation files at /translations.

You will likely want to add your own custom authentication strategy and can do so using a routing constraint on the mount RailsI18nManager call.

From that point you can implement an automated mechanism to update your apps translations using the provided API end point. Some examples

An example in Ruby:

require 'open-uri'

zip_stream = URI.open('https://translations-manager.example.com/translations.zip?export_format=yaml')
IO.copy_stream(zip_stream, '/tmp/my-app-locales.zip')
`unzip /tmp/my-app-locales.zip /tmp/my-app-locales/`
`rsync --delete-after /tmp/my-app-locales/my-app/ /path/to/my-app/config/locales/`
puts "Locales are now updated, app restart not-required"

A command line example using curl:

curl https://translations-manager.example.com/translations.zip?export_format=json -o /tmp/my-app-locales.zip \
  && unzip /tmp/my-app-locales.zip /tmp/my-app-locales/ \
  && rsync --delete-after /tmp/my-app-locales/my-app/ \
  && echo "Locales are now updated, app restart not-required"

Development

Run migrations using: rails db:migrate

Run server using: bin/dev or cd test/dummy/; rails s

Testing

bundle exec rspec

We can locally test different versions of Rails using ENV['RAILS_VERSION']

export RAILS_VERSION=7.0
bundle install
bundle exec rspec

Other Translation Managers & Web Interfaces

For comparison, some other projects for managing Rails translations.

Credits

Created & Maintained by Weston Ganger - @westonganger

About

Web interface to manage i18n translations helping to facilitate the editors of your translations. Provides a low-tech and complete workflow for importing, translating, and exporting your I18n translation files. Designed to allow you to keep the translation files inside your projects git repository where they should be.

Resources

License

Stars

Watchers

Forks

Packages

No packages published