+ <% end %>
+ <% end %>
+ <% end %>
+
+ <% end %>
+
+
+ <%= resource.file_name %> - <%= number_to_human_size(resource.size) %>
diff --git a/resources/config/locales/en.yml b/resources/config/locales/en.yml
index 332fc8c93f..1138e98bd8 100644
--- a/resources/config/locales/en.yml
+++ b/resources/config/locales/en.yml
@@ -13,6 +13,8 @@ en:
or: or
replace: " replace it with this one..."
maximum_file_size: The maximum file size is %{bytes}.
+ resource_title: Title
+ resource_title_help: The title visible to users.
resource:
download: Download this file (%{size})
actions:
diff --git a/resources/config/locales/fr.yml b/resources/config/locales/fr.yml
index d786bee86d..82a69a069a 100644
--- a/resources/config/locales/fr.yml
+++ b/resources/config/locales/fr.yml
@@ -13,6 +13,8 @@ fr:
or: ou
replace: " le remplacer par celui-ci..."
maximum_file_size: "La taille du fichier ne doit pas excéder %{bytes}."
+ resource_title: Titre
+ resource_title_help: Le titre visible pour les utilisateurs.
resource:
download: Télécharger ce fichier (%{size})
actions:
diff --git a/resources/db/migrate/20150430180959_add_translated_title_to_refinery_resources.rb b/resources/db/migrate/20150430180959_add_translated_title_to_refinery_resources.rb
new file mode 100644
index 0000000000..f0efe1867f
--- /dev/null
+++ b/resources/db/migrate/20150430180959_add_translated_title_to_refinery_resources.rb
@@ -0,0 +1,11 @@
+class AddTranslatedTitleToRefineryResources < ActiveRecord::Migration
+ def self.up
+ Refinery::Resource.create_translation_table!({
+ resource_title: :string
+ })
+ end
+
+ def self.down
+ Refinery::Resource.drop_translation_table!
+ end
+end
\ No newline at end of file
diff --git a/resources/lib/refinery/resources.rb b/resources/lib/refinery/resources.rb
index 298d950647..fd82058f4a 100644
--- a/resources/lib/refinery/resources.rb
+++ b/resources/lib/refinery/resources.rb
@@ -22,3 +22,7 @@ def factory_paths
end
end
end
+
+ActiveSupport.on_load(:active_record) do
+ require 'globalize'
+end
\ No newline at end of file
diff --git a/resources/refinerycms-resources.gemspec b/resources/refinerycms-resources.gemspec
index a950cfbb5f..3ff0aa2195 100644
--- a/resources/refinerycms-resources.gemspec
+++ b/resources/refinerycms-resources.gemspec
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
s.add_dependency 'acts_as_indexed', '~> 0.8.0'
s.add_dependency 'dragonfly', '~> 1.0.0'
+ s.add_dependency 'globalize', ['>= 4.0.0', '< 5.2']
s.add_dependency 'refinerycms-core', version
s.required_ruby_version = Refinery::Version.required_ruby_version
diff --git a/resources/spec/features/refinery/admin/resources_spec.rb b/resources/spec/features/refinery/admin/resources_spec.rb
index 24c184424c..8028ce5e4f 100644
--- a/resources/spec/features/refinery/admin/resources_spec.rb
+++ b/resources/spec/features/refinery/admin/resources_spec.rb
@@ -32,7 +32,7 @@ module Admin
click_button ::I18n.t('save', :scope => 'refinery.admin.form_actions')
end
- expect(page).to have_content("Refinery Is Awesome.txt")
+ expect(page).to have_content("Refinery Is Awesome")
expect(Refinery::Resource.count).to eq(1)
end
@@ -78,7 +78,7 @@ module Admin
it "updates file" do
visit refinery.admin_resources_path
- expect(page).to have_content("Refinery Is Awesome.txt")
+ expect(page).to have_content("Refinery Is Awesome")
expect(page).to have_selector("a[href='/refinery/resources/#{resource.id}/edit']")
click_link "Edit this file"
@@ -92,6 +92,30 @@ module Admin
expect(page).to have_content("Refinery Is Awesome2")
expect(Refinery::Resource.count).to eq(1)
end
+
+ describe "translate", focus: true do
+ before do
+ allow(Refinery::I18n).to receive(:frontend_locales).and_return([:en, :fr])
+ end
+
+ it "can have a second locale added to it" do
+ visit refinery.admin_resources_path
+ expect(page).to have_content("Refinery Is Awesome")
+ expect(page).to have_selector("a[href='/refinery/resources/#{resource.id}/edit']")
+
+ click_link "Edit this file"
+
+ within "#switch_locale_picker" do
+ click_link "FR"
+ end
+
+ fill_in "Title", :with => "Premier fichier"
+ click_button "Save"
+
+ expect(page).to have_content("'Premier fichier' was successfully updated.")
+ expect(Resource.translation_class.count).to eq(1)
+ end
+ end
end
context "destroy" do
diff --git a/resources/spec/models/refinery/resource_spec.rb b/resources/spec/models/refinery/resource_spec.rb
index 85f99c211e..bb1c8e5829 100644
--- a/resources/spec/models/refinery/resource_spec.rb
+++ b/resources/spec/models/refinery/resource_spec.rb
@@ -3,6 +3,7 @@
module Refinery
describe Resource, :type => :model do
let(:resource) { FactoryGirl.create(:resource) }
+ let(:titled_resource) { FactoryGirl.create(:resource, resource_title: 'Resource Title')}
context "with valid attributes" do
it "should create successfully" do
@@ -31,8 +32,15 @@ module Refinery
end
describe "#title" do
- it "returns a titleized version of the filename" do
- expect(resource.title).to eq("Refinery Is Awesome")
+ context 'when a specific title has not been given' do
+ it "returns a titleized version of the filename" do
+ expect(resource.title).to eq("Refinery Is Awesome")
+ end
+ end
+ context 'when a specific title has been given' do
+ it 'returns that title' do
+ expect(titled_resource.title).to eq('Resource Title')
+ end
end
end