CouchI18n

<img src=“https://travis-ci.org/bterkuile/couch_i18n.png?branch=master” alt=“Build Status” /> Note this is a Rails >= 3.1 engine

This projects is created to make translations editable. It is created using the simply_stored gem. To use the web frontend please read the README section on this carefully. Important to know is that this system sits *on top* of the standard YAML translation system. To import all yml translations to the CouchDB database type:

CouchI18n::Store.import_from_yaml

Now all translations are ported to the database. If you change then now in the yaml files, they will nolonger be displayed in the website. They should be managed in the database. This gem also provides a translation management system. To place this in your own design, read the layout section. Your Gemfile should look like:

gem 'simply_stored', :git => 'git://github.com/bterkuile/simply_stored.git'
gem 'couch_i18n'
gem 'kaminari'

And in your config routes put:

mount CouchI18n::Engine => '/couch_i18n'

Security!!!

By default there is no security activated for editing the translation. This is a choice since you should be in control over your own security. To help you securing the translations in your application I will describe the steps I did to add declarative_authorization security into the translation. Start with an initializer: config/initializers/couch_I18n_modifications.rb

require 'couch_i18n/application_controller'
module CouchI18n
  class ApplicationController
    def current_user
      Authorization.current_user
    end
    include Authorization::AuthorizationInController
    filter_access_to :all
    def permission_denied
      redirect_to root_path, :alert => I18n.t('authorization.not_authorized')
    end
  end
end

And in config/authorization_rules.rb put your personalized version of:

role :translator do
  has_permission_on :couch_i18n_stores, :to => [:manage, :import, :export, :destroy_offset]
end

Beware that a permission denied message will appear when the server is restarted this way. This is because the current user is set in ApplicationController which is not part of the CouchI18n controller stack.

couch_i18n translations

Ofcourse couch_i18n is working with translations as well. To get them working import the following yamlL

en:
  New: New
  Edit: Edit
  Show: Show
  Back: Back
  Save: Save
  Create: Create
  Are you sure: 'Are you sure?'
  activemodel:
    models:
      couch_i18n:
        translation: Translation
    attributes:
      couch_i18n:
        translation:
          key: Key
          value: Value
  action:
    create:
      successful: %{model} successfully created
    update:
      successful: %{model} successfully updated
    destroy:
      successful: %{model} successfully removed
  couch_i18n: 
    translation:
      index title: Translations
      none found: No translations present
      new title: New translation
      show title: Translation
      edit title: Edit translation
      go to offset: Go to
      go to zero offset: x
      export: 
        execute: Export
        untranslated: Untranslated
      import: Import
      offset deleted: "%{count} translations with offset %{offset} are deleted"
      no proper import extension: Files with extension%{extension} cannot be imported
      no import file given: There is no file to be imported
      cannot parse yaml: The file cannot be read
      file imported: File %{filename} was successfully imported
      # The following tranlation will only work if no are_you_sure helper is present
      are you sure: 'Are you sure?'
      destroy offset link: Delete all translations with current offset
      # The following tranlation will only work if no site_title helper is present
      site_title: Translations

couch_i18n helpers

The following helpers are assumed:

module CouchI18nViewHelpers
  def title(str)
    content_for :title do
      (:h1, str)
    end
  end
  def link_to_new_content(obj)
    t('New')
  end
  def link_to_edit_content(obj = nil)
    t('Edit')
  end
  def link_to_show_content(obj = nil)
    t('Show')
  end
  def link_to_index_content(singular_name)
    t('Back')
  end
  def link_to_destroy_content(obj = nil)
    t('Delete')
  end
  def update_button_text(obj = nil)
    t('Save')
  end
  def create_button_text(obj = nil)
    t('Create')
  end
  def boolean_text(truefalse)
    truefalse ? t('general.boolean true') : t('general.boolean false')
  end
  def are_you_sure(obj = nil)
    t('Are you sure')
  end
end

couch_i18n layout

This gem comes with its own layout file, but you can ofcourse use your own. To do this place a layout at your application with the path: app/views/layouts/couch_i18n/application.html.haml It should yield the following parts:

!!!
%html
  %head
    %title= defined?(site_title) ? site_title : I18n.t('couch_i18n.translation.site_title')
    = csrf_meta_tag
    = stylesheet_link_tag 'couch_i18n/application'
    = javascript_include_tag 'couch_i18n/application'
    = yield :head
  %body
    #page-wrapper
      #page-content
        %h1= yield :title
        = render 'alerts'
        = yield
        #page-links= yield :page_links

TODO

Here my todo list for this project. Makes it insightful for everybody what is on the planning of being made.

  • Check on locale inclusion with are you sure? force creation of new locale. Mostly a stupic mistake omitting these.

  • Add grouped search/replaces to move one group of translations to another section. Same comment as above

  • Search through values. If anyone has a better idea than searching by ruby through all the translations or adding lucene please feel free.

  • A lot of testing

  • Add referencing to other translations (big miss in I18n)

  • Add error_messages partial to manual

  • Only show translations of exact given offset (no children)

  • Show translation matching exact the given offset (beware of caching or automatically adding structures)