Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
L

lit

> 编程语言
Open source

rails i18n web interface

300 stars0 likes2 views
WebsiteGitHub

About

rails i18n web interface

Lost in translation

Rails i18n web interface

Translate your apps with pleasure (sort of...) and for free. It's simple i18n web interface, build on top of twitter bootstrap, that one may find helpful in translating app by non-technicals.

Highly inspired by Copycopter by thoughtbot.

Features

  1. Runs with your app - no need for external services
  2. Support for array types, (ie. date.abbr_day_names)
  3. Versioning translations - you can always check, how value did look like in past
  4. Possibility to synchronize translations between environments or apps
  5. Easy to install - works as an engine, comes with simple generator
  6. You can always export all translations to plain old YAML file which can then be imported elsewhere. Translations can also be exported to (and then imported from) a CSV file so that e.g. a third party can easily edit translations for you using any spreadsheet editor, without access to your website's Lit panel.
  7. Has build in wysiwyg editor (jQuery TE)
  8. Translating apps directly in frontend (see bellow)
  9. (On request) stores paths where translation keys were called
  10. (On request) is able to show all translation keys used to render current page

Screenshots

Feature overview on YouTube

Check wiki for more: Screenshots

Installation

  1. Add lit gem to your Gemfile
ruby
gem 'lit'

For Ruby 1.2.4'

...we also support V2 of Google Cloud Translate gem, should you need it:

gem 'google-cloud-translate', '~> 2.1.2'


To use translation via Google, you need to obtain a [service account key](https://cloud.google.com/iam/docs/creating-managing-service-account-keys) containing all the credentials required by the API.

These credentials can be given in three ways:
* via a `.json` keyfile, the path to which should be stored in the `GOOGLE_TRANSLATE_API_KEYFILE` environment variable,
* programmatically, in the initializer - be sure to use secrets in all the sensitive fields so you don't expose private credentials in the code:

Lit::CloudTranslation.configure do |config| config.keyfile_hash = { 'type' => 'service_account', 'project_id' => 'foo', 'private_key_id' => 'keyid', ... # see Google docs link above for reference } end

For example, for Rails 6, from encrypted credentials file (HashWithIndifferentAccess is used, because the keys in

the credentials.config could be strings or, as well, symbols):

Lit::CloudTranslation.configure do |config| config.keyfile_hash = HashWithIndifferentAccess.new(Rails.application.credentials.config[:google_translate_api]) end

* directly via `GOOGLE_TRANSLATE_API_` environment variables, where e.g. the `GOOGLE_TRANSLATE_API_PROJECT_ID` variable corresponds to the `project_id` element of a JSON keyfile. Typically, only the following variables are mandatory:
* `GOOGLE_TRANSLATE_API_PROJECT_ID`
* `GOOGLE_TRANSLATE_API_PRIVATE_KEY` (make sure that it contains correct line breaks and markers of the private key's begin and end)
* `GOOGLE_TRANSLATE_API_CLIENT_EMAIL`

#### Yandex.Translate API

Insert this into your Lit initializer:

require 'lit/cloud_translation/providers/yandex'

Lit::CloudTranslation.provider = Lit::CloudTranslation::Providers::Yandex


To use Yandex translation, an [API key must be obtained](https://translate.yandex.com/developers/keys). Then, you can pass it to your application via the `YANDEX_TRANSLATE_API_KEY` environment variable.

The API key can also be set programmatically in your Lit initializer (again, be sure to use secrets if you choose to do so):

Lit::CloudTranslation.configure do |config| config.api_key = 'the_api_key' end

…

Lit::Localization.group(:locale_id, :localization_key_id).having('count(*) > 1').count


### 0.2 -> 0.3 upgrade guide

1. Specify exact lit version in your Gemfile: `gem 'lit', '~> 0.3.0'`
2. Run `bundle update lit`
3. Add `config.i18n.available_locales` to your `application.rb` (see 3rd point from Installation info)
4. Add `config.i18n.enforce_available_locales = true` config to your `application.rb`
5. Compare your current `lit.rb` initializer with [template](https://github.com/prograils/lit/blob/master/lib/generators/lit/install/templates/initializer.rb).

### On-site live translations

1. Add `Lit::FrontendHelper` to your `ApplicationController`

```ruby
helper Lit::FrontendHelper
  1. In you layout file include lit assets
erb

  

…

ruby
include Lit::RequestInfoStore
  1. In lit initializer (lit.rb) set store_request_info config to true
ruby
Lit.store_request_info = true
  1. Lit authorized user must be signed in for this feature to work!

Showing called translations in frontend

  1. Add Lit::FrontendHelper in your ApplicationController
ruby
helper Lit::FrontendHelper
  1. Include Lit::RequestKeysStore concern in your ApplicationController
ruby
include Lit::RequestKeysStore
  1. Enable storing of request keys in lit initializer config/initializers/lit.rb
ruby
Lit.store_request_keys = true
  1. On the bottom of you layout file call lit_translations_info helper function
erb
  1. From now on you'll be able to see all translation keys that were used to render current page. This feature works great with on-site live translations!

  2. Lit authorized user must be signed in for this feature to work! This feature requires jQuery!

ToDo

  • Versioning
  • API
  • Synchronization between environments
  • Rewrite initializer
  • Rewrite exporter (which is now code from copycopter)
  • Support for array types (ie. date.abbr_day_names)
  • Generator
  • Support for wysiwyg
  • Better cache
  • Support for other key value providers (ie. Redis does not support Array types in easy way) (not applicable, as array storage works now with redis).
  • Integration with ActiveAdmin
  • Support for Proc defaults (like in I18n.t('not_exising_keys', default: lambda{|_, options| 'text'}) )

Testing

  1. gem install bundler && bundle install - ensure Bundler and all required gems are installed
  2. bundle exec appraisal install - install gems from appraisal's gemfiles
  3. cp test/dummy/config/database.yml.sample test/dummy/config/database.yml - move a database.yml in place (remember to fill your DB credentials in it)
  4. RAILS_ENV=test bundle exec appraisal rails-7.0 rake db:setup - setup lit DB (see test/config/database.yml); do it only once, it does not matter which Rails version you use for appraisal
  5. bundle exec appraisal rake - run the tests!

License

Lit is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.

Issues· 24 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言