Build Status Coverage Status

Kakimasu

Kakimasu is Ruby gem for easy translation management in Ruby on Rails projects which uses Redis server for translation storage. Kakimasu most valuable function is that it can add translations right from your browser. That's right - create translations without suffering. With Kakimasu you can add translations more faster and more effective, and it has even google translate support. You want to use 'lazy lookup' keys? With this gem you can do that with ease from 'key management' view. Adding translations are not only function for Kakimasu. You can manage all used keys in project. You can even see just those keys which doesn't have translations in all languages (keys with missing translations). You can easily track your translation progress in project. Also for developers this gem has special features - views generating and policy generating for ability to customize views and permissions. One of the features is backup - you can save all your translations in backup file and you can restore backup (these functions can be very useful when you migrate project and want to keep your translations).

Installation

Add this line to your application's Gemfile:

gem 'kakimasu'

I18n should be set up in the project for successful translation

Include Kakimasu in your application controller and for successfull translation process you have to add :set_show_translation_key:

class ApplicationController < ActionController::Base
  include Kakimasu
  before_action :set_show_translation_key
end

Edit default url options in your application controller to pass show_translation_key param between requests.

def default_url_options
  { show_translation_key: Thread.current[:show_tranlsation_key] }
end

If I18n is included in default url options then:

def default_url_options
  { locale: I18n.locale, show_translation_key: Thread.current[:show_translation_key] }.merge(super)
end

Require Kakimasu in your application.coffee

#= require kakimasu

To use stylesheets add this line to your application.scss

@import "kakimasu";

Path to kakimasu panel is translations_path

Link for translator activation should be:

#For activation
= link_to t('activate_translation_mode'), { show_translation_key: true }, id: 'activate_translation_mode_button'
#For deactivation
= link_to t('deactivate_translation_mode'), show_translation_key: false

Usage

Configuring views

If you want to customize kakimasu views, you can easily add them to your app/views by typing in console:

console $ rails generate kakimasu:views

Forms

There is a issue with form default submit buttons because they display span tags as a plain text (thereby javascript can not be executed). So if you want to translate buttons like any other element in project they look like this:

<%= f.button :button do %>
  <% t('translation_key') %>
<% end %> 

Security

Of course security is very important for this gem. By default translation mode is available just for admin. If you want to customize something. For example give translation permissions to moderator you should overwrite show_translation_key method. In moderator case it would look like this:

  def set_show_translation_key
    Thread.current[:show_translation_key] = nil
    return unless current_user.try(:moderator?)
    Thread.current[:show_translation_key] = (params[:show_translation_key] == 'true').presence
  end

If you want to configure policy then you can generate translation policy file by just typing in console:

  $ rails generate kakimasu:policy

Backups

Create backup

You can easily create backup file with command:

console $ rails generate kakimasu:backup

After backup all translations are stored in file called .kakimasu_backup.yml

Restore translations

Command for restoring translations from the backup file:

console $ rails generate kakimasu:restore_backup

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Roberts Groza/kakimasu. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.