Giter Site home page Giter Site logo

hellehata / rails_i18n_manager Goto Github PK

View Code? Open in Web Editor NEW

This project forked from westonganger/rails_i18n_manager

0.0 0.0 0.0 1.27 MB

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: MIT License

JavaScript 0.97% Ruby 74.77% CSS 2.49% HTML 8.59% Slim 13.18%

rails_i18n_manager's Introduction

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

rails_i18n_manager's People

Contributors

westonganger avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.