mongo_translatable 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +26 -0
- data/.gitmodules +3 -0
- data/LICENSE +295 -0
- data/README.rdoc +131 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/app/controllers/translations_controller.rb +150 -0
- data/app/helpers/translations_helper.rb +71 -0
- data/app/views/layouts/translations.html.erb +18 -0
- data/app/views/translations/_form.html.erb +50 -0
- data/app/views/translations/_translatable_value.html.erb +17 -0
- data/app/views/translations/_translation_field.html.erb +34 -0
- data/app/views/translations/_translation_field_input.html.erb +8 -0
- data/app/views/translations/edit.html.erb +8 -0
- data/app/views/translations/index.html.erb +22 -0
- data/app/views/translations/new.html.erb +7 -0
- data/app/views/translations/show.html.erb +12 -0
- data/config/locales/en.yml +33 -0
- data/config/locales/fr.yml +18 -0
- data/lib/mongo_translatable.rb +336 -0
- data/lib/mongo_translatable_configuration.rb +5 -0
- data/lib/translatables_helper.rb +227 -0
- data/lib/translations_controller_helpers.rb +37 -0
- data/rails/init.rb +3 -0
- data/test/full_2_3_5_app_with_tests/.gitignore +27 -0
- data/test/full_2_3_5_app_with_tests/README +1 -0
- data/test/full_2_3_5_app_with_tests/Rakefile +10 -0
- data/test/full_2_3_5_app_with_tests/app/controllers/application_controller.rb +26 -0
- data/test/full_2_3_5_app_with_tests/app/controllers/items_controller.rb +85 -0
- data/test/full_2_3_5_app_with_tests/app/helpers/application_helper.rb +3 -0
- data/test/full_2_3_5_app_with_tests/app/helpers/items_helper.rb +2 -0
- data/test/full_2_3_5_app_with_tests/app/models/comment.rb +3 -0
- data/test/full_2_3_5_app_with_tests/app/models/item.rb +5 -0
- data/test/full_2_3_5_app_with_tests/app/models/not_swapped_in_record.rb +3 -0
- data/test/full_2_3_5_app_with_tests/app/models/person.rb +3 -0
- data/test/full_2_3_5_app_with_tests/app/models/recipe.rb +21 -0
- data/test/full_2_3_5_app_with_tests/app/views/items/edit.html.erb +24 -0
- data/test/full_2_3_5_app_with_tests/app/views/items/index.html.erb +24 -0
- data/test/full_2_3_5_app_with_tests/app/views/items/new.html.erb +23 -0
- data/test/full_2_3_5_app_with_tests/app/views/items/show.html.erb +21 -0
- data/test/full_2_3_5_app_with_tests/app/views/layouts/items.html.erb +19 -0
- data/test/full_2_3_5_app_with_tests/config/boot.rb +110 -0
- data/test/full_2_3_5_app_with_tests/config/database.yml +22 -0
- data/test/full_2_3_5_app_with_tests/config/environment.rb +54 -0
- data/test/full_2_3_5_app_with_tests/config/environments/development.rb +17 -0
- data/test/full_2_3_5_app_with_tests/config/environments/production.rb +28 -0
- data/test/full_2_3_5_app_with_tests/config/environments/test.rb +28 -0
- data/test/full_2_3_5_app_with_tests/config/initializers/backtrace_silencers.rb +7 -0
- data/test/full_2_3_5_app_with_tests/config/initializers/inflections.rb +10 -0
- data/test/full_2_3_5_app_with_tests/config/initializers/mime_types.rb +5 -0
- data/test/full_2_3_5_app_with_tests/config/initializers/new_rails_defaults.rb +21 -0
- data/test/full_2_3_5_app_with_tests/config/initializers/session_store.rb +15 -0
- data/test/full_2_3_5_app_with_tests/config/locales.yml +5 -0
- data/test/full_2_3_5_app_with_tests/config/locales/en.yml +4 -0
- data/test/full_2_3_5_app_with_tests/config/locales/fr.yml +4 -0
- data/test/full_2_3_5_app_with_tests/config/locales/zh.yml +4 -0
- data/test/full_2_3_5_app_with_tests/config/routes.rb +4 -0
- data/test/full_2_3_5_app_with_tests/db/migrate/20100407010602_create_items.rb +14 -0
- data/test/full_2_3_5_app_with_tests/db/migrate/20100504234216_create_not_swapped_in_records.rb +15 -0
- data/test/full_2_3_5_app_with_tests/db/migrate/20100509011052_create_people.rb +13 -0
- data/test/full_2_3_5_app_with_tests/db/migrate/20100509042718_create_comments.rb +14 -0
- data/test/full_2_3_5_app_with_tests/db/migrate/20110112023516_create_recipes.rb +14 -0
- data/test/full_2_3_5_app_with_tests/db/schema.rb +56 -0
- data/test/full_2_3_5_app_with_tests/db/seeds.rb +7 -0
- data/test/full_2_3_5_app_with_tests/doc/README_FOR_APP +2 -0
- data/test/full_2_3_5_app_with_tests/public/404.html +30 -0
- data/test/full_2_3_5_app_with_tests/public/422.html +30 -0
- data/test/full_2_3_5_app_with_tests/public/500.html +30 -0
- data/test/full_2_3_5_app_with_tests/public/favicon.ico +0 -0
- data/test/full_2_3_5_app_with_tests/public/images/rails.png +0 -0
- data/test/full_2_3_5_app_with_tests/public/index.html +275 -0
- data/test/full_2_3_5_app_with_tests/public/javascripts/application.js +2 -0
- data/test/full_2_3_5_app_with_tests/public/javascripts/controls.js +963 -0
- data/test/full_2_3_5_app_with_tests/public/javascripts/dragdrop.js +973 -0
- data/test/full_2_3_5_app_with_tests/public/javascripts/effects.js +1128 -0
- data/test/full_2_3_5_app_with_tests/public/javascripts/prototype.js +4320 -0
- data/test/full_2_3_5_app_with_tests/public/robots.txt +5 -0
- data/test/full_2_3_5_app_with_tests/public/stylesheets/scaffold.css +54 -0
- data/test/full_2_3_5_app_with_tests/script/about +4 -0
- data/test/full_2_3_5_app_with_tests/script/console +3 -0
- data/test/full_2_3_5_app_with_tests/script/dbconsole +3 -0
- data/test/full_2_3_5_app_with_tests/script/destroy +3 -0
- data/test/full_2_3_5_app_with_tests/script/generate +3 -0
- data/test/full_2_3_5_app_with_tests/script/performance/benchmarker +3 -0
- data/test/full_2_3_5_app_with_tests/script/performance/profiler +3 -0
- data/test/full_2_3_5_app_with_tests/script/plugin +3 -0
- data/test/full_2_3_5_app_with_tests/script/runner +3 -0
- data/test/full_2_3_5_app_with_tests/script/server +3 -0
- data/test/full_2_3_5_app_with_tests/test/factories.rb +18 -0
- data/test/full_2_3_5_app_with_tests/test/functional/translations_controller_test.rb +66 -0
- data/test/full_2_3_5_app_with_tests/test/integration/translation_test.rb +72 -0
- data/test/full_2_3_5_app_with_tests/test/performance/browsing_test.rb +9 -0
- data/test/full_2_3_5_app_with_tests/test/selenium.rb +83 -0
- data/test/full_2_3_5_app_with_tests/test/test_helper.rb +86 -0
- data/test/full_2_3_5_app_with_tests/test/unit/helpers/translatables_helper_test.rb +37 -0
- data/test/full_2_3_5_app_with_tests/test/unit/helpers/translations_helper_test.rb +62 -0
- data/test/full_2_3_5_app_with_tests/test/unit/mongo_translatable_test.rb +342 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/init.rb +1 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter.rb +94 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/base.rb +31 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/force_extension.rb +57 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/locale.rb +70 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/pagination.rb +33 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/uuid_token.rb +78 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/force_extension_spec.rb +65 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/generation_spec.rb +367 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/pagination_extension_spec.rb +19 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/recognition_spec.rb +76 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/routing_filter_spec.rb +114 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/spec_helper.rb +108 -0
- metadata +309 -0
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "mongo_translatable"
|
8
|
+
gem.summary = %Q{MongoDB backed Rails specific I18n model localization meant to tie-in to existing ActiveRecord models}
|
9
|
+
gem.description = %Q{Rails specific I18n model localization meant to tie-in to existing ActiveRecord models, ala Globalize2, backed by MongoDB rather than an RDBMS. May include UI elements, too.}
|
10
|
+
gem.email = "walter@katipo.co.nz"
|
11
|
+
gem.homepage = "http://github.com/kete/mongo_translatable"
|
12
|
+
gem.authors = ["Walter McGinnis", "Kieran Pilkington", "Breccan McLeod-Lundy"]
|
13
|
+
gem.add_dependency "mongo_mapper", ">= 0.7.3"
|
14
|
+
gem.add_dependency "activerecord", "2.3.5"
|
15
|
+
gem.add_development_dependency "shoulda", ">= 2.10.3"
|
16
|
+
gem.add_development_dependency "factory_girl", "= 1.2.3"
|
17
|
+
gem.add_development_dependency "webrat", ">= 0.5.3"
|
18
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
19
|
+
end
|
20
|
+
Jeweler::GemcutterTasks.new
|
21
|
+
rescue LoadError
|
22
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'rake/testtask'
|
26
|
+
Rake::TestTask.new(:test) do |test|
|
27
|
+
puts "This gem includes a full rails app for running tests (and staging development not yet extracted to the gem proper). Run tests there by changing to test/full_[RAIlS_VERSION_#_with_underscores]_app_with_tests and doing 'rake test'."
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
require 'rcov/rcovtask'
|
32
|
+
Rcov::RcovTask.new do |test|
|
33
|
+
test.libs << 'test'
|
34
|
+
test.pattern = 'test/**/test_*.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
rescue LoadError
|
38
|
+
task :rcov do
|
39
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task :test => :check_dependencies
|
44
|
+
|
45
|
+
task :default => :test
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "mongo_translatable #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,150 @@
|
|
1
|
+
class TranslationsController < ApplicationController
|
2
|
+
# Prevents the following error from showing up, common in Rails engines
|
3
|
+
# A copy of ApplicationController has been removed from the module tree but is still active!
|
4
|
+
unloadable
|
5
|
+
|
6
|
+
before_filter :set_translatable_key_and_class
|
7
|
+
# just being picky about contextual naming for clarity in variable's purpose
|
8
|
+
before_filter :get_translatable, :only => [:new, :create]
|
9
|
+
before_filter :get_translated, :except => [:new, :create]
|
10
|
+
before_filter :get_translation, :except => [:new, :index, :create]
|
11
|
+
|
12
|
+
# GET /translations
|
13
|
+
# GET /translations.xml
|
14
|
+
def index
|
15
|
+
@translations = @translated.translations
|
16
|
+
|
17
|
+
respond_to do |format|
|
18
|
+
format.html # index.html.erb
|
19
|
+
format.xml { render :xml => @translations }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# GET /translations/1
|
24
|
+
# GET /translations/1.xml
|
25
|
+
def show
|
26
|
+
respond_to do |format|
|
27
|
+
format.html # show.html.erb
|
28
|
+
format.xml { render :xml => @translation }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# GET /translations/new
|
33
|
+
# GET /translations/new.xml
|
34
|
+
def new
|
35
|
+
@translation = @translatable.translate(:locale => (params[:to_locale] || I18n.locale.to_s))
|
36
|
+
|
37
|
+
respond_to do |format|
|
38
|
+
format.html # new.html.erb
|
39
|
+
format.js { render :layout => false } # needs to come after html for IE to work
|
40
|
+
format.xml { render :xml => @translation }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# GET /translations/1/edit
|
45
|
+
def edit
|
46
|
+
@translation = @translated.translation_for(params[:id]) || @translatable_class::Translation.find(params[:id])
|
47
|
+
end
|
48
|
+
|
49
|
+
# POST /translations
|
50
|
+
# POST /translations.xml
|
51
|
+
def create
|
52
|
+
translation_params = params[:translation] || params[@translatable_params_name + '_translation']
|
53
|
+
@translation = @translatable.translate(translation_params)
|
54
|
+
|
55
|
+
respond_to do |format|
|
56
|
+
if @translation.save
|
57
|
+
flash[:notice] = t('translations.controllers.created')
|
58
|
+
# we redirect to translated object in the new translated version
|
59
|
+
# assumes controller name is tableized version of class
|
60
|
+
format.html { redirect_to url_for_translated }
|
61
|
+
# TODO: adjust :location accordingly for being a nested route
|
62
|
+
format.xml { render :xml => @translation, :status => :created, :location => @translation }
|
63
|
+
else
|
64
|
+
format.html { render :action => "new" }
|
65
|
+
format.xml { render :xml => @translation.errors, :status => :unprocessable_entity }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# PUT /translations/1
|
71
|
+
# PUT /translations/1.xml
|
72
|
+
def update
|
73
|
+
respond_to do |format|
|
74
|
+
translation_params = params[:translation] || params[@translatable_params_name + '_translation']
|
75
|
+
if @translation.update_attributes(translation_params)
|
76
|
+
flash[:notice] = t('translations.controllers.updated')
|
77
|
+
format.html { redirect_to url_for_translated }
|
78
|
+
format.xml { head :ok }
|
79
|
+
else
|
80
|
+
format.html { render :action => "edit" }
|
81
|
+
format.xml { render :xml => @translation.errors, :status => :unprocessable_entity }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# DELETE /translations/1
|
87
|
+
# DELETE /translations/1.xml
|
88
|
+
def destroy
|
89
|
+
return_to = params[:return_to_translated].present? && params[:return_to_translated] ? url_for_translated : { :action =>:index }
|
90
|
+
@translation.destroy
|
91
|
+
|
92
|
+
respond_to do |format|
|
93
|
+
flash[:notice] = t('translations.controllers.deleted')
|
94
|
+
format.html { redirect_to return_to }
|
95
|
+
format.xml { head :ok }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
protected
|
100
|
+
# accepts translation.locale or translation.id for lookup
|
101
|
+
# translation.locale should be unique within the scope of @translated
|
102
|
+
def get_translation
|
103
|
+
@translation = @translated.translation_for(params[:id]) || @translatable_class::Translation.find(params[:id])
|
104
|
+
end
|
105
|
+
|
106
|
+
%w{translatable translated}.each do |term|
|
107
|
+
define_method("get_" + term) do
|
108
|
+
value = @translatable_class.find(params[@translatable_key])
|
109
|
+
|
110
|
+
# handle case of editing translation from another locale than original
|
111
|
+
if value.locale != value.original_locale &&
|
112
|
+
params[:controller] == 'translations' &&
|
113
|
+
params[:action] == 'edit'
|
114
|
+
|
115
|
+
starting_locale = I18n.locale
|
116
|
+
|
117
|
+
I18n.locale = value.original_locale
|
118
|
+
|
119
|
+
value.reload
|
120
|
+
|
121
|
+
I18n.locale = starting_locale
|
122
|
+
end
|
123
|
+
|
124
|
+
instance_variable_set("@" + term, value)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# assuming nested routing, this should return exactly one params key
|
129
|
+
# and its matching class
|
130
|
+
def set_translatable_key_and_class
|
131
|
+
translatable_keys = params.keys.select { |key| key.to_s.include?('_id') }
|
132
|
+
|
133
|
+
translatable_keys.each do |key|
|
134
|
+
key = key.to_s
|
135
|
+
if key != 'translation_id' && request
|
136
|
+
key_singular = key.sub('_id', '')
|
137
|
+
|
138
|
+
# make sure this is found in the request url
|
139
|
+
# thus making this a nested route
|
140
|
+
# assumes plural version for controller name
|
141
|
+
if request.path.split('/').include?(key_singular.pluralize)
|
142
|
+
@translatable_class = key_singular.camelize.constantize
|
143
|
+
@translatable_key = key.to_sym
|
144
|
+
@translatable_params_name = key_singular
|
145
|
+
break
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module TranslationsHelper
|
2
|
+
# outputs a display of translatable attributes
|
3
|
+
# internationalized, assumes translation key is made up of the following
|
4
|
+
# @translatable.class.name.tablize (i.e. controller name for routing purposes)
|
5
|
+
# .
|
6
|
+
# form (i.e. template name used by new and edit actions in most cases for forms)
|
7
|
+
# .
|
8
|
+
# the_attribute_name (i.e. what the accessor method name is for attribute in question on the model)
|
9
|
+
# expects @translatable var or @translated var
|
10
|
+
# returns an array with a hash per attribute where the key is the label (internationalized)
|
11
|
+
# and the value for the attribute
|
12
|
+
mattr_accessor :available_locales
|
13
|
+
@@available_locales ||= YAML.load(IO.read(File.join(RAILS_ROOT, 'config/locales.yml')))
|
14
|
+
|
15
|
+
%w{untranslated translated}.each do |term|
|
16
|
+
define_method(term + '_values_with_localized_labels') do
|
17
|
+
set_original
|
18
|
+
raise "No object supplied to translate." if @original.blank?
|
19
|
+
raise "No matching translation available." if term == 'translated' && @translation.blank?
|
20
|
+
|
21
|
+
@original.translatable_attributes.collect do |attribute_key|
|
22
|
+
value = (term == 'untranslated') ? @original.send(attribute_key) : @translation[attribute_key]
|
23
|
+
{ :attribute_key => attribute_key,
|
24
|
+
:localized_label => localized_label_for(attribute_key),
|
25
|
+
:value => modify_translation_value(value, @original) }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# We don't do anything here, just provide it for users to if they need it
|
31
|
+
def modify_translation_value(value, original_object)
|
32
|
+
value
|
33
|
+
end
|
34
|
+
|
35
|
+
def localized_label_for(attribute_key)
|
36
|
+
t(@translatable_class.name.tableize + '.' + 'form' + '.' + attribute_key.to_s)
|
37
|
+
end
|
38
|
+
|
39
|
+
def available_locales_for_options
|
40
|
+
@@available_locales.collect { |key,value| [value,key] }
|
41
|
+
end
|
42
|
+
|
43
|
+
def available_in_locales
|
44
|
+
set_original
|
45
|
+
list = @original.available_in_these_locales.collect do |locale|
|
46
|
+
link_to_unless_current(TranslationsHelper::available_locales[locale], url_for_translated(:locale => locale))
|
47
|
+
end
|
48
|
+
list = '<ul>' + '<li>' + list.join('</li><li>') + '</li>' + '</ul>'
|
49
|
+
end
|
50
|
+
|
51
|
+
def needed_in_locales
|
52
|
+
set_original
|
53
|
+
list = @original.needed_in_these_locales.collect do |locale|
|
54
|
+
link_to(TranslationsHelper::available_locales[locale],
|
55
|
+
:action => :new,
|
56
|
+
:controller => :translations,
|
57
|
+
@translatable_key => @original,
|
58
|
+
:to_locale => locale)
|
59
|
+
end
|
60
|
+
list = '<ul>' + '<li>' + list.join('</li><li>') + '</li>' + '</ul>'
|
61
|
+
end
|
62
|
+
|
63
|
+
def translatable_field_a_text_area?(form, translation_field)
|
64
|
+
form.object.translatable_class.columns_hash[translation_field.to_s].type == :text
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
def set_original
|
69
|
+
@original ||= @translatable || @translated
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
7
|
+
<title><%= controller.controller_name %>: <%= controller.action_name %></title>
|
8
|
+
<%= yield :add_on_scripts_and_links %>
|
9
|
+
<%= javascript_include_tag :defaults %>
|
10
|
+
</head>
|
11
|
+
<body>
|
12
|
+
|
13
|
+
<p style="color: green"><%= flash[:notice] %></p>
|
14
|
+
|
15
|
+
<%= yield %>
|
16
|
+
|
17
|
+
</body>
|
18
|
+
</html>
|
@@ -0,0 +1,50 @@
|
|
1
|
+
<% translatable = @translatable.present? ? @translatable : @translated %>
|
2
|
+
<h2 style="margin:0 0 10px 0;">
|
3
|
+
<%= I18n.t('translations.form.translate_from_and_to',
|
4
|
+
:from => TranslationsHelper::available_locales[translatable.original_locale],
|
5
|
+
:to => TranslationsHelper::available_locales[h(@translation.locale)]) %>
|
6
|
+
</h2>
|
7
|
+
|
8
|
+
<%= form.error_messages %>
|
9
|
+
<%= form.hidden_field :locale %>
|
10
|
+
<%= hidden_field_tag :version, params[:version] if params[:version] %>
|
11
|
+
|
12
|
+
<!-- Use a table instead of floated divs because it gives better results in IE -->
|
13
|
+
<table style="width: 98%;">
|
14
|
+
<tr>
|
15
|
+
<th colspan="2" style="width: 48%;">
|
16
|
+
<h3 style="margin:0 0 10px 0;"><%= TranslationsHelper::available_locales[translatable.original_locale] %></h3>
|
17
|
+
</th>
|
18
|
+
<th rowspan="<%= @translatable_class.translatable_attributes.size + 1 %>" style="width:1px; border-left: 1px solid #000; padding: 0; margin: 0"></th>
|
19
|
+
<th colspan="3" style="width: 48%;">
|
20
|
+
<h3 style="margin:0 0 10px 0;"><%= TranslationsHelper::available_locales[@translation.locale] %></h3>
|
21
|
+
</th>
|
22
|
+
</tr>
|
23
|
+
|
24
|
+
<% translatable_attributes = @translatable.present? ? @translatable.translatable_attributes : @translated.translatable_attributes
|
25
|
+
@untranslated_values_with_localized_labels = untranslated_values_with_localized_labels
|
26
|
+
-%>
|
27
|
+
<% translatable_attributes.each do |attribute_key| %>
|
28
|
+
<tr>
|
29
|
+
<% untranslated_value = @untranslated_values_with_localized_labels.find { |l| l[:attribute_key] == attribute_key }
|
30
|
+
locals = { :form => form, :untranslated_value => untranslated_value } %>
|
31
|
+
<%= render 'translatable_value', locals %>
|
32
|
+
<% if untranslated_value[:value].present? -%>
|
33
|
+
<%= render 'translation_field', locals.merge(:attribute_key => attribute_key) %>
|
34
|
+
<% else -%>
|
35
|
+
<td colspan="3" class="translatable_label_and_field" valign="top" style="padding: 5px;">
|
36
|
+
<%= I18n.t('translations.form.original_has_no_value') -%>
|
37
|
+
</td>
|
38
|
+
<% end -%>
|
39
|
+
</tr>
|
40
|
+
<% end %>
|
41
|
+
</table>
|
42
|
+
|
43
|
+
<div class="make_translation" style="text-align: center; margin-top: 20px; width: 98%;">
|
44
|
+
<%= form.submit @button_text %>
|
45
|
+
</div>
|
46
|
+
|
47
|
+
<div class="translate_links" style="margin-top: 20px;">
|
48
|
+
<%= available_in_locales_for(@original, :lightbox => request.xhr?) %>
|
49
|
+
<%= needed_in_locales_for(@original, :lightbox => request.xhr?) %>
|
50
|
+
</div>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<% if translatable_field_a_text_area?(form, untranslated_value[:attribute_key]) %>
|
2
|
+
|
3
|
+
<td colspan="2" class="original_label_and_value" valign="top" style="padding: 5px;">
|
4
|
+
<%= h(untranslated_value[:localized_label]) -%><br />
|
5
|
+
<%= h(untranslated_value[:value]) -%>
|
6
|
+
</td>
|
7
|
+
|
8
|
+
<% else %>
|
9
|
+
|
10
|
+
<td class="original_label" valign="top" style="width: 10%; padding: 5px;">
|
11
|
+
<%= h(untranslated_value[:localized_label]) -%>
|
12
|
+
</td>
|
13
|
+
<td class="original_value" valign="top" style="padding: 5px;">
|
14
|
+
<%= h(untranslated_value[:value]) -%>
|
15
|
+
</td>
|
16
|
+
|
17
|
+
<% end %>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<% locals = { :form => form, :untranslated_value => untranslated_value, :attribute_key => attribute_key } %>
|
2
|
+
|
3
|
+
<% if translatable_field_a_text_area?(form, attribute_key) %>
|
4
|
+
|
5
|
+
<td colspan="3" class="translatable_label_and_field" valign="top" style="padding: 5px;">
|
6
|
+
<%= form.label attribute_key, localized_label_for(attribute_key) %><br />
|
7
|
+
<%= render 'translation_field_input', locals %>
|
8
|
+
</td>
|
9
|
+
|
10
|
+
<% else %>
|
11
|
+
|
12
|
+
<td class="translatable_label" valign="top" style="width: 10%; padding: 5px;">
|
13
|
+
<%= form.label attribute_key, localized_label_for(attribute_key) %>
|
14
|
+
</td>
|
15
|
+
<td class="translatable_value" valign="top" style="padding: 5px;">
|
16
|
+
<%= render 'translation_field_input', locals %>
|
17
|
+
</td>
|
18
|
+
<td class="translatable_auto_translate" valign="top" style='font-size:0.8em;'>
|
19
|
+
<% if MongoTranslatableConfiguration.provide_autotranslate -%>
|
20
|
+
|
21
|
+
<span class="translate_link_span"></span>
|
22
|
+
<% translate_link = link_to('[auto translate]', '#', :title => 'Auto Translate Using Google', :class => 'translate_link') %>
|
23
|
+
<%= javascript_tag("
|
24
|
+
$$('.translate_link_span').last().update(#{::ActiveSupport::JSON.encode(translate_link)});
|
25
|
+
$$('.translate_link').last().observe('click', function(event) {
|
26
|
+
getGoogleTranslation(this.up('tr').down('.translatable_value').down('input').id,
|
27
|
+
'#{escape_javascript(h(untranslated_value[:value]))}',
|
28
|
+
'#{I18n.locale}', '#{h(@translation.locale)}');
|
29
|
+
event.stop();
|
30
|
+
});") %>
|
31
|
+
<% end -%>
|
32
|
+
</td>
|
33
|
+
|
34
|
+
<% end %>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<%# assign the value of the untranslated field if this record is a new object %>
|
2
|
+
<% form.object.send("#{attribute_key}=", untranslated_value[:value]) if form.object.new_record? %>
|
3
|
+
|
4
|
+
<% if translatable_field_a_text_area?(form, attribute_key) %>
|
5
|
+
<%= form.text_area attribute_key, :rows => 7, :cols => 35 %>
|
6
|
+
<% else %>
|
7
|
+
<%= form.text_field attribute_key %>
|
8
|
+
<% end %>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<% type = @translated.class.name.titleize.downcase -%>
|
2
|
+
<h2 style="margin:0 0 10px 0;"><%= t("translations.index.title", :type => type) -%></h2>
|
3
|
+
|
4
|
+
<ul>
|
5
|
+
<% @translations.each do |translation| %>
|
6
|
+
<li>
|
7
|
+
<%= link_to(TranslationsHelper::available_locales[translation.locale], { :action => :show, :id => h(translation.locale) }) -%>
|
8
|
+
[ <%= link_to(t('translations.index.edit').downcase, { :id => h(translation.locale), :action => :edit }) -%> |
|
9
|
+
<%= link_to(t('translations.index.delete').downcase, { :id => h(translation.locale), :action => :destroy },
|
10
|
+
{ :method => :delete, :confirm => t('translations.index.are_you_sure') }) -%> ]
|
11
|
+
</li>
|
12
|
+
<% end %>
|
13
|
+
</ul>
|
14
|
+
|
15
|
+
<ul style="list-style:none; padding:0; margin:0;">
|
16
|
+
<li style="float:left; padding: 0 5px;">
|
17
|
+
<%= link_to(t("translations.index.back", :type => type), url_for_translated) %>
|
18
|
+
</li>
|
19
|
+
<li style="float:left; padding: 0 5px; border-left: 1px solid #000;">
|
20
|
+
<%= link_to(t("translations.index.new"), { :action => :new }) %>
|
21
|
+
</li>
|
22
|
+
</ul>
|