i18n_admin_utils 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +32 -0
- data/app/assets/javascripts/i18n_admin_utils/application.js +13 -0
- data/app/assets/javascripts/i18n_admin_utils/translation_helper.coffee +61 -0
- data/app/assets/stylesheets/i18n_admin_utils/application.css +13 -0
- data/app/controllers/i18n_admin_utils/application_controller.rb +6 -0
- data/app/controllers/i18n_admin_utils/translation_controller.rb +56 -0
- data/app/helpers/i18n_admin_utils/application_helper.rb +4 -0
- data/app/views/i18n_admin_utils/translation/_missing_list.html.erb +29 -0
- data/app/views/i18n_admin_utils/translation/index.html.erb +5 -0
- data/config/routes.rb +6 -0
- data/lib/generators/i18n_admin_utils/install_generator.rb +11 -0
- data/lib/generators/i18n_admin_utils/templates/initializer.rb +11 -0
- data/lib/i18n_admin_utils.rb +13 -0
- data/lib/i18n_admin_utils/config.rb +29 -0
- data/lib/i18n_admin_utils/engine.rb +5 -0
- data/lib/i18n_admin_utils/search_translation.rb +29 -0
- data/lib/i18n_admin_utils/version.rb +3 -0
- data/lib/tasks/i18n_admin_utils_tasks.rake +4 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +29 -0
- data/test/dummy/config/environments/production.rb +80 -0
- data/test/dummy/config/environments/test.rb +36 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +12 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/public/404.html +58 -0
- data/test/dummy/public/422.html +58 -0
- data/test/dummy/public/500.html +57 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/i18n_admin_utils_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- metadata +192 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NjViZGI0YjE0ODFkYWUyNmUyYjRiYWJhY2VkYmI3NmExZTVhZjU1Mg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MTI2ODcwNTEzYTljMGFlN2I1ZjI0ZDJlZDI3ZDJlOGQzZGEyYzg0OA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MGJiNWNlZWI5YWFiM2Y5ZTZlNzJlN2RhODRjY2YwYzVhN2E3MGUyOTkzMDA1
|
10
|
+
YjA2M2JhZTI0NTU4MWE5NWQzZGIyYTQ5Y2UyNzkzM2JiY2E0ZWFiZGQwOWUx
|
11
|
+
Y2I2ZGU4MzE3OGUwNGZhNWY5MzYyYTE5ZjZmMWViODQ2MTViZjk=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
Mzc2MDYyOTEwYmE0MTdlZDU3MDY1ZWJhZDM2YTAyODIwNDFkYjI1YjgxYzNl
|
14
|
+
NmE4MTE4MGE3MzRmZWI3MWRmMTk3NDUzMzU4NjJjMWE5NmI5NjYxMWUwZTE5
|
15
|
+
OWRkYjFhYTk2NDFlNjVjZGE1ZWViYzMxYzE1YTYzNDA2MDk2MjU=
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'I18nAdminUtils'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Bundler::GemHelper.install_tasks
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
|
24
|
+
Rake::TestTask.new(:test) do |t|
|
25
|
+
t.libs << 'lib'
|
26
|
+
t.libs << 'test'
|
27
|
+
t.pattern = 'test/**/*_test.rb'
|
28
|
+
t.verbose = false
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
task default: :test
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#Script that add forms to edit non existing translation
|
2
|
+
|
3
|
+
$(document).ready () ->
|
4
|
+
$('span.translation_missing').each ->
|
5
|
+
span = $(this)
|
6
|
+
content = get_content(span)
|
7
|
+
span.attr('title', '')
|
8
|
+
span.popover({
|
9
|
+
html: true
|
10
|
+
title: 'Translation missing, Input'
|
11
|
+
content: content
|
12
|
+
})
|
13
|
+
|
14
|
+
$('.loadonready').each () ->
|
15
|
+
container = $(this)
|
16
|
+
url = container.data('url')
|
17
|
+
$.get(url).success (data) ->
|
18
|
+
container.html(data)
|
19
|
+
|
20
|
+
$(document).on 'submit', 'form.translation_helper', (e)->
|
21
|
+
e.preventDefault()
|
22
|
+
form = $(this)
|
23
|
+
|
24
|
+
form.find('button').prop('disabled', true);
|
25
|
+
$.ajax({
|
26
|
+
url: form.attr('action'),
|
27
|
+
type: form.attr('method'),
|
28
|
+
dataType: 'json',
|
29
|
+
data: form.serialize()
|
30
|
+
}).success( (data) ->
|
31
|
+
if data.success
|
32
|
+
form.find('button').html('Translation added')
|
33
|
+
form.find('div.alert').hide()
|
34
|
+
else
|
35
|
+
handle_error(form, data)
|
36
|
+
).error (data) ->
|
37
|
+
handle_error(form, data)
|
38
|
+
return false
|
39
|
+
|
40
|
+
get_content = (span)->
|
41
|
+
url = '/translation/edit'
|
42
|
+
key = span.attr('title').match(/translation missing: (.*)/)[1]
|
43
|
+
console.log(key)
|
44
|
+
content = "<form action='" + url + "' method='post' class='translation_helper'>"
|
45
|
+
content += "<div class='alert alert-danger hidden'></div>"
|
46
|
+
content += "<input type='hidden' name='key' value='" + key + "'>"
|
47
|
+
content += "<label>Translate " + key + "</label>"
|
48
|
+
content += "<input type='text' name='value' class='form-control'>"
|
49
|
+
content += "<hr>"
|
50
|
+
content += "<button class='btn btn-primary'>Add translation</button>"
|
51
|
+
content += "</form>"
|
52
|
+
content
|
53
|
+
|
54
|
+
handle_error = (form, data) ->
|
55
|
+
form.find('button').prop('disabled', false);
|
56
|
+
alert = form.find('div.alert')
|
57
|
+
if data.status
|
58
|
+
alert.html('Error: ' + data.status)
|
59
|
+
else if data.error
|
60
|
+
alert.html(data.error)
|
61
|
+
alert.removeClass('hidden')
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module I18nAdminUtils
|
2
|
+
class TranslationController < ApplicationController
|
3
|
+
def index
|
4
|
+
|
5
|
+
end
|
6
|
+
|
7
|
+
def edit
|
8
|
+
if params[:key].nil?
|
9
|
+
i18n_redirect('No key specified')
|
10
|
+
else
|
11
|
+
key = params[:key]
|
12
|
+
locale = params[:locale]
|
13
|
+
value = params[:value]
|
14
|
+
if locale.nil?
|
15
|
+
if key.include? '.'
|
16
|
+
split = key.split('.', 2)
|
17
|
+
locale = split[0]
|
18
|
+
key = split[1]
|
19
|
+
else
|
20
|
+
i18n_redirect('No locale specified')
|
21
|
+
return
|
22
|
+
end
|
23
|
+
end
|
24
|
+
translation = I18nAdminUtils::Config.translation_model.where(:locale => locale, :key => key).first
|
25
|
+
if translation.nil?
|
26
|
+
translation = I18nAdminUtils::Config.translation_model.new
|
27
|
+
translation.locale = locale
|
28
|
+
translation.key = key
|
29
|
+
end
|
30
|
+
translation.value = value
|
31
|
+
translation.save
|
32
|
+
I18n.backend.reload! if I18nAdminUtils::Config.reload_translation_after_update
|
33
|
+
i18n_redirect('Translation edited with success')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
#Return a list of all the missing translation
|
38
|
+
def missing_list
|
39
|
+
translation = I18nAdminUtils::SearchTranslation.search
|
40
|
+
puts translation
|
41
|
+
render :partial => 'missing_list', :layout => false, :locals=> {:translation => translation}
|
42
|
+
end
|
43
|
+
|
44
|
+
def i18n_redirect(message, success = true)
|
45
|
+
if request.xhr?
|
46
|
+
render :json => {:success => success, :message => message}
|
47
|
+
else
|
48
|
+
if success
|
49
|
+
redirect_to :back, :notice => message
|
50
|
+
else
|
51
|
+
redirect_to :back, :alert => message
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<div>
|
2
|
+
<% translation.each do |translation| %>
|
3
|
+
<div class='container'>
|
4
|
+
<%= form_tag translation_edit_path, :class => 'translation_helper form-horizontal' do %>
|
5
|
+
<div class='' data-locale='<%= translation[:locale] %>' data-key='<%= translation[:key ] %>'>
|
6
|
+
<div class='row'>
|
7
|
+
<div class='col-md-1'>
|
8
|
+
<%= translation[:locale] %>
|
9
|
+
</div>
|
10
|
+
<div class='col-md-3'>
|
11
|
+
<%= translation[:key] %>
|
12
|
+
</div>
|
13
|
+
<%= hidden_field_tag :locale, translation[:locale] %>
|
14
|
+
<%= hidden_field_tag :key, translation[:key] %>
|
15
|
+
<div class='col-md-4'>
|
16
|
+
<%= text_area_tag :value, '', :class => 'form-control' %>
|
17
|
+
</div>
|
18
|
+
<div class='col-md-4'>
|
19
|
+
<button class='btn btn-primary'>
|
20
|
+
Add
|
21
|
+
</button>
|
22
|
+
</div>
|
23
|
+
</div>
|
24
|
+
<hr>
|
25
|
+
</div>
|
26
|
+
<% end %>
|
27
|
+
</div>
|
28
|
+
<% end %>
|
29
|
+
</div>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
|
3
|
+
get '/translation' => 'i18n_admin_utils/translation#index', :as => :translation_home
|
4
|
+
get 'translation/missing/list' => 'i18n_admin_utils/translation#missing_list', :as => :translation_missing_list
|
5
|
+
post '/translation/edit' => 'i18n_admin_utils/translation#edit', :as => :translation_edit
|
6
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
module I18nAdminUtils
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
desc 'Creates a InstallGenerator initializer and copy locale files to your application.'
|
6
|
+
def install
|
7
|
+
route("mount I18nAdminUtils::Engine => '/', as: 'i18n_admin_utils'")
|
8
|
+
template 'initializer.rb', 'config/initializers/i18n_admin_utils.rb'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
I18nAdminUtils.config do |config|
|
2
|
+
|
3
|
+
#Model that contains the translation must have locale, key and value columns
|
4
|
+
config.translation_model = Translation
|
5
|
+
|
6
|
+
#Reload the translation after they have been updated
|
7
|
+
config.reload_translation_after_update = true
|
8
|
+
|
9
|
+
#List of locales used in your application
|
10
|
+
config.locales = ['en']
|
11
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'i18n_admin_utils/engine'
|
2
|
+
require 'i18n_admin_utils/config'
|
3
|
+
require 'i18n_admin_utils/search_translation'
|
4
|
+
|
5
|
+
module I18nAdminUtils
|
6
|
+
def self.config(&block)
|
7
|
+
if block_given?
|
8
|
+
block.call(I18nAdminUtils::Config)
|
9
|
+
else
|
10
|
+
I18nAdminUtils::Config
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
2
|
+
|
3
|
+
module I18nAdminUtils
|
4
|
+
module Config
|
5
|
+
class << self
|
6
|
+
attr_accessor :translation_model
|
7
|
+
attr_accessor :reload_translation_after_update
|
8
|
+
attr_accessor :locales
|
9
|
+
|
10
|
+
def reset
|
11
|
+
@translation_model = 'Translation'
|
12
|
+
@reload_translation_after_update = true
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def translation_model
|
17
|
+
if @translation_model.is_a? String
|
18
|
+
@translation_model.constantize
|
19
|
+
else
|
20
|
+
@translation_model
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
#Set the default values
|
26
|
+
end
|
27
|
+
reset
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module I18nAdminUtils
|
2
|
+
class SearchTranslation
|
3
|
+
def self.search
|
4
|
+
results = []
|
5
|
+
dirs = ["#{Rails.root}/app"]
|
6
|
+
dirs.each do |dir|
|
7
|
+
Dir.glob("#{dir}/**/*.*").each do |filename|
|
8
|
+
File.open(filename).read.scan(/t\(("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')\)/).each do |result|
|
9
|
+
results << result[0][1...-1]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
check_results(results)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.check_results(results)
|
17
|
+
missing = []
|
18
|
+
results.each do |result|
|
19
|
+
locale = 'en'
|
20
|
+
I18nAdminUtils::Config.locales.each do |locale|
|
21
|
+
if I18nAdminUtils::Config.translation_model.where(:locale => locale, :key => result).first.nil?
|
22
|
+
missing << {:locale => locale, :key => result}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
missing
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/test/dummy/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|