Skip to content

Commit

Permalink
Use translations for labels
Browse files Browse the repository at this point in the history
  • Loading branch information
elrayle committed May 4, 2017
1 parent fe8a6b8 commit 5204a81
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 22 deletions.
20 changes: 10 additions & 10 deletions app/views/roles/edit.html.erb
@@ -1,26 +1,26 @@
<h2>Role:</h2>
<h2><%= t('role-management.edit.title') %></h2>
<%= bootstrap_form_for @role, :url=>role_management.role_path(@role) do |f| %>
<%= f.text_field :name, :label=> 'Role name' %>
<%= f.text_field :name, :label=> t('role-management.edit.field_name') %>
<%= f.submit "Update" %>
<%= f.submit t('role-management.edit.update') %>
<% end %>
<% if can? :destroy, Role %>
<%= button_to "Delete", role_management.role_path(@role), :method=>:delete, :class=>'btn btn-danger' %>
<%= button_to t('role-management.edit.delete'), role_management.role_path(@role), :method=>:delete, :class=>'btn btn-danger' %>
<% end %>
<h3>Accounts:</h3>
<h3><%= t('role-management.edit.accounts') %></h3>
<ul>
<% @role.users.each do |user| %>
<li><%= user.user_key %>
<% if can? :remove_user, Role %>
<%= button_to "Remove User", role_management.role_user_path(@role, user), :method=>:delete, :class=>'btn btn-danger' %>
<%= button_to t('role-management.edit.remove'), role_management.role_user_path(@role, user), :method=>:delete, :class=>'btn btn-danger' %>
<% end %>
</li>
<% end %>
</ul>
<h3>Add a new account:</h3>
<h3><%= t('role-management.edit.add_new_account') %></h3>
<%= bootstrap_form_tag :url=> role_management.role_users_path(@role) do |f| %>
<%= f.text_field 'user_key', :label=>'User' %>
<%= f.submit "Add" %>
<%= link_to "Cancel", role_management.roles_path, :class => 'btn btn-default' %>
<%= f.text_field 'user_key', :label=>t('role-management.edit.user') %>
<%= f.submit t('role-management.edit.add') %>
<%= link_to t('role-management.edit.cancel'), role_management.roles_path, :class => 'btn btn-default' %>
<% end %>
4 changes: 2 additions & 2 deletions app/views/roles/index.html.erb
@@ -1,11 +1,11 @@
<h2>Roles</h2>
<h2><%= t('role-management.index.title') %></h2>
<ul>
<% @roles.each do |role| %>
<li><%=link_to role.name, role_management.role_path(role) %></li>
<% end %>
</ul>

<% if can? :create, Role %>
<%= button_to "Create a new role", role_management.new_role_path, method: :get, class: 'btn btn-primary' %>
<%= button_to t('role-management.index.create'), role_management.new_role_path, method: :get, class: 'btn btn-primary' %>
<% end %>

6 changes: 3 additions & 3 deletions app/views/roles/new.html.erb
@@ -1,6 +1,6 @@
<%= bootstrap_form_for @role, :url=>role_management.roles_path do |f| %>
<%= f.text_field :name, :label=> 'Role name' %>
<%= f.submit "Add" %>
<%= link_to "Cancel", role_management.roles_path, :class => 'btn btn-default' %>
<%= f.text_field :name, :label=> t('role-management.new.field_name') %>
<%= f.submit t('role-management.new.add') %>
<%= link_to t('role-management.new.cancel'), role_management.roles_path, :class => 'btn btn-default' %>
<% end %>

14 changes: 7 additions & 7 deletions app/views/roles/show.html.erb
@@ -1,17 +1,17 @@
<h2>Role: <%= @role.name %></h2>
<h3>Accounts:</h3>
<h2><%= t('role-management.show.title') %> <%= @role.name %></h2>
<h3><% t('role-management.show.accounts') %></h3>
<ul>
<% @role.users.each do |user| %>
<li><%= user.user_key %>
<% if can? :remove_user, Role %>
<%= button_to "Remove User", role_management.role_user_path(@role, user), :method=>:delete, :class=>'btn btn-danger' %>
<%= button_to t('role-management.show.remove'), role_management.role_user_path(@role, user), :method=>:delete, :class=>'btn btn-danger' %>
<% end %>
</li>
<% end %>
</ul>
<h3>Add a new account:</h3>
<h3><%= t('role-management.show.add_new_account') %></h3>
<%= bootstrap_form_tag url: role_management.role_users_path(@role) do |f| %>
<%= f.text_field 'user_key', :label=>'User' %>
<%= f.submit "Add" %>
<%= link_to "Cancel", role_management.roles_path, :class => 'btn btn-default' %>
<%= f.text_field 'user_key', :label=>t('role-management.show.user') %>
<%= f.submit t('role-management.show.add') %>
<%= link_to t('role-management.show.cancel'), role_management.roles_path, :class => 'btn btn-default' %>
<% end %>
28 changes: 28 additions & 0 deletions config/locales/role-management.en.yml
@@ -0,0 +1,28 @@
en:
role-management:
index:
title: 'Roles'
create: 'Create a new role'
new:
field_name: 'Role name'
add: 'Add'
cancel: 'Cancel'
show:
title: 'Role:'
accounts: 'Accounts:'
remove: 'Remove User'
add_new_account: 'Add a new account:'
user: 'User'
add: 'Add'
cancel: 'Cancel'
edit:
title: 'Role:'
field_name: 'Role name'
update: 'Update'
accounts: 'Accounts:'
delete: 'Delete'
remove: 'Remove User'
add_new_account: 'Add a new account:'
user: 'User'
add: 'Add'
cancel: 'Cancel'
28 changes: 28 additions & 0 deletions config/locales/role-management.es.yml
@@ -0,0 +1,28 @@
es:
role-management:
index:
title: 'Rols'
create: 'Crear un nuevo rol'
new:
field_name: 'Nombre de rol'
add: 'Añadir'
cancel: 'Cancelar'
show:
title: 'Rol:'
accounts: 'Cuentas:'
remove: 'Eliminar Usuario'
add_new_account: 'Añadir una cuenta nueva:'
user: 'Usuario'
add: 'Añadir'
cancel: 'Cancelar'
edit:
title: 'Rol:'
field_name: 'Nombre de rol'
update: 'Actualizar'
accounts: 'Cuentas:'
delete: 'Borrar'
remove: 'Eliminar Usuario'
add_new_account: 'Añadir una cuenta nueva:'
user: 'Usuario'
add: 'Añadir'
cancel: 'Cancelar'
1 change: 1 addition & 0 deletions hydra-role-management.gemspec
Expand Up @@ -24,4 +24,5 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'rspec-its'
gem.add_development_dependency 'rails-controller-testing', '~> 0'
gem.add_development_dependency 'engine_cart', '~> 1.0'
gem.add_development_dependency 'i18n-tasks'
end
23 changes: 23 additions & 0 deletions spec/i18n/i18n_spec.rb
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require 'i18n/tasks'

RSpec.describe 'I18n' do
let(:cfg) do
fn = File.join(Hydra::RoleManagement::Engine.root, '.internal_test_app', 'config', 'i18n-tasks.yml')
YAML.load(ERB.new(File.read(File.expand_path(fn, __FILE__))).result)
end
let(:i18n) { I18n::Tasks::BaseTask.new(cfg) }
let(:missing_keys) { i18n.missing_keys }
let(:unused_keys) { i18n.unused_keys }

it 'does not have missing keys' do
expect(missing_keys).to be_empty,
"Missing #{missing_keys.leaves.count} i18n keys, run `i18n-tasks missing' to show them"
end

it 'does not have unused keys' do
expect(unused_keys).to be_empty,
"#{unused_keys.leaves.count} unused i18n keys, run `i18n-tasks unused' to show them"
end
end
15 changes: 15 additions & 0 deletions spec/test_app_templates/lib/generators/i18n_generator.rb
@@ -0,0 +1,15 @@
# -*- encoding : utf-8 -*-

require 'rails/generators'

class I18nGenerator < Rails::Generators::Base
desc """
This generator installs the i18n configuration file into the engine_cart test application.
"""

source_root File.expand_path('../templates', __FILE__)

def i18n_config
copy_file 'i18n-tasks.yml', 'config/i18n-tasks.yml'
end
end
122 changes: 122 additions & 0 deletions spec/test_app_templates/lib/generators/templates/i18n-tasks.yml
@@ -0,0 +1,122 @@
# i18n-tasks finds and manages missing and unused translations: https://github.com/glebm/i18n-tasks

# The "main" locale.
base_locale: en
## All available locales are inferred from the data by default. Alternatively, specify them explicitly:
# locales: [es, fr]
## Reporting locale, default: en. Available: en, ru.
# internal_locale: en

# Read and write translations.
data:
## Translations are read from the file system. Supported format: YAML, JSON.
## Provide a custom adapter:
# adapter: I18n::Tasks::Data::FileSystem

# Locale files or `File.find` patterns where translations are read from:
read:
## Default:
# - config/locales/%{locale}.yml
## More files:
# - config/locales/**/*.%{locale}.yml
## Another gem (replace %#= with %=):
# - "<%#= %x[bundle show vagrant].chomp %>/templates/locales/%{locale}.yml"
- "<%= %x[bundle show hydra-role-management].chomp %>/config/locales/**/*.%{locale}.yml"

# Locale files to write new keys to, based on a list of key pattern => file rules. Matched from top to bottom:
# `i18n-tasks normalize -p` will force move the keys according to these rules
write:
## For example, write devise and simple form keys to their respective files:
# - ['{devise, simple_form}.*', 'config/locales/\1.%{locale}.yml']
## Catch-all default:
# - config/locales/%{locale}.yml

## Specify the router (see Readme for details). Valid values: conservative_router, pattern_router, or a custom class.
# router: conservative_router

yaml:
write:
# do not wrap lines at 80 characters
line_width: -1

## Pretty-print JSON:
# json:
# write:
# indent: ' '
# space: ' '
# object_nl: "\n"
# array_nl: "\n"

# Find translate calls
search:
## Paths or `File.find` patterns to search in:
# paths:
# - app/

## Root directories for relative keys resolution.
# relative_roots:
# - app/controllers
# - app/helpers
# - app/mailers
# - app/presenters
# - app/views

## Files or `File.fnmatch` patterns to exclude from search. Some files are always excluded regardless of this setting:
## %w(*.jpg *.png *.gif *.svg *.ico *.eot *.otf *.ttf *.woff *.woff2 *.pdf *.css *.sass *.scss *.less *.yml *.json)
exclude:
- app/assets/images
- app/assets/fonts
- app/assets/videos

## Alternatively, the only files or `File.fnmatch patterns` to search in `paths`:
## If specified, this settings takes priority over `exclude`, but `exclude` still applies.
# only: ["*.rb", "*.html.slim"]

## If `strict` is `false`, guess usages such as t("categories.#{category}.title"). The default is `true`.
# strict: true

## Multiple scanners can be used. Their results are merged.
## The options specified above are passed down to each scanner. Per-scanner options can be specified as well.
## See this example of a custom scanner: https://github.com/glebm/i18n-tasks/wiki/A-custom-scanner-example

## Google Translate
# translation:
# # Get an API key and set billing info at https://code.google.com/apis/console to use Google Translate
# api_key: "AbC-dEf5"

## Do not consider these keys missing:
# ignore_missing:
# - 'errors.messages.{accepted,blank,invalid,too_short,too_long}'
# - '{devise,simple_form}.*'

## Consider these keys used:
# ignore_unused:
# - 'activerecord.attributes.*'
# - '{devise,kaminari,will_paginate}.*'
# - 'simple_form.{yes,no}'
# - 'simple_form.{placeholders,hints,labels}.*'
# - 'simple_form.{error_notification,required}.:'

## Exclude these keys from the `i18n-tasks eq-base' report:
# ignore_eq_base:
# all:
# - common.ok
# fr,es:
# - common.brand

## Ignore these keys completely:
# ignore:
# - kaminari.*

## Sometimes, it isn't possible for i18n-tasks to match the key correctly,
## e.g. in case of a relative key defined in a helper method.
## In these cases you can use the built-in PatternMapper to map patterns to keys, e.g.:
#
# <%# I18n::Tasks.add_scanner 'I18n::Tasks::Scanners::PatternMapper',
# only: %w(*.html.haml *.html.slim),
# patterns: [['= title\b', '.page_title']] %>
#
# The PatternMapper can also match key literals via a special %{key} interpolation, e.g.:
#
# <%# I18n::Tasks.add_scanner 'I18n::Tasks::Scanners::PatternMapper',
# patterns: [['\bSpree\.t[( ]\s*%{key}', 'spree.%{key}']] %>
6 changes: 6 additions & 0 deletions spec/test_app_templates/lib/generators/test_app_generator.rb
Expand Up @@ -22,4 +22,10 @@ def run_roles_generator
say_status("warning", "GENERATING ROLES", :yellow)
generate 'roles', '-f'
end

def run_i18n_generator
say_status("warning", "GENERATING I18N CONFIG", :yellow)
generate 'i18n'
end

end

0 comments on commit 5204a81

Please sign in to comment.