Permalink
Browse files

Add i18n

  • Loading branch information...
1 parent c8bb4a1 commit 8a1b200017ef385e0ca184e95f9647c6fd14f6bc @davec committed Jun 28, 2010
@@ -1,8 +1,5 @@
-# Uncomment this if you reference any of your controllers in activate
-# require_dependency 'application'
-
class AdBannersExtension < Radiant::Extension
- version "0.2"
+ version "0.9" # Compatible with Radiant 0.9
description "Manage ad banners"
url "http://github.com/davec/radiant-ad_banners-extension"
@@ -6,7 +6,7 @@ class AdBanner < ActiveRecord::Base
validates_presence_of :name, :asset_id#, :link_url
validates_format_of :link_url, :allow_blank => true,
:with => /\Ahttps?:\/\/.+\z/,
- :message => "doesn't look like a URL"
+ :message => :invalid
def self.select_banner(options = {})
exclusions = options[:exclude] || []
@@ -7,18 +7,21 @@
#asset-tabs
- render_region :asset_tabs do |asset_tabs|
-# asset_tabs.upload_tab do
- %a.asset-tab{ :href => "#upload-assets", :id => "tab_upload-assets" } Upload
+ %a.asset-tab{ :href => "#upload-assets", :id => "tab_upload-assets" }
+ = t('ad_banner_upload')
- asset_tabs.bucket_tab do
- %a.asset-tab{ :href => "#bucket", :id => "tab_bucket" } Bucket
+ %a.asset-tab{ :href => "#bucket", :id => "tab_bucket" }
+ = t('ad_banner_bucket')
#assets
#bucket.pane
- render_region :bucket_pane do |bucket_pane|
- bucket_pane.bucket_notes do
%p
- %span.note The Bucket provides temporary storage for your items.
+ %span.note
+ = t('ad_banner_bucket_note')
%span#clear-bucket
- = link_to_remote('Clear Bucket', {:url => clear_bucket_url} )
+ = link_to_remote(t('ad_banner_bucket_clear'), {:url => clear_bucket_url} )
- bucket_pane.bucket do
= render :partial => "bucket"
- bucket_pane.bucket_bottom do
@@ -4,7 +4,6 @@
= render :partial => 'bucket_asset', :locals => { :asset_url => url, :asset_id => info[:id], :asset_type => info[:type], :asset_title => info[:title], :asset_thumbnail =>info[:thumbnail], :page => @page }
- else
%li
- %p.note Your bucket is empty
-
-
+ %p.note
+ = t('ad_banner_bucket_empty')
@@ -4,4 +4,4 @@
= link_to image_tag(asset_thumbnail), asset_url, :title => asset_title, :class => "bucket_link"
.info{ :id => "#{asset_id}_info" }
- = link_to_function image_tag('/images/assets/add.png'), "AdBanner.attach($('bucket_#{asset_id}'), $('image-thumbnail'))", { :class => 'add_asset', :title => 'Attach to ad' }
+ = link_to_function image_tag('/images/assets/add.png'), "AdBanner.attach($('bucket_#{asset_id}'), $('image-thumbnail'))", { :class => 'add_asset', :title => t('ad_banner_attach_title') }
@@ -1,37 +1,45 @@
- thumb_width, thumb_height = Asset.thumbnail_sizes[:thumbnail].first.split(/\D/)
- min_weight = @ad_banner.new_record? ? 1 : 0
- unless @ad_banner.new_record?
- %p To change the ad banner image, drag an image from the asset bucket over the existing image thumbnail, or click the <b>+</b> (plus) icon next to the image in the asset bucket.
- %p You can temporarily disable the display of the ad banner by setting the weight to <b>0</b> (zero). This will allow you to reenable the ad banner later without having to recreate it.
+ %p
+ != t('ad_banner_form.instructions.change')
+ %p
+ != t('ad_banner_form.instructions.disable')
- form_for [:admin, @ad_banner] do |f|
.form-area
#ad_banner_form_area
#ad_banner-data
%p.title
- %label{:for => 'ad_banner_name'} Banner Name
+ %label{:for => 'ad_banner_name'}
+ = t('ad_banner_form.label.name')
= f.text_field :name, :class => 'textbox', :maxlength => 255
%p.title
- %label{:for => 'ad_banner_asset_id'} Image Thumbnail
+ %label{:for => 'ad_banner_asset_id'}
+ = t('ad_banner_form.label.thumbnail')
%span#image-thumbnail{ :style => "width:#{thumb_width}px;height:#{thumb_height}px;" }
- if @ad_banner.asset.nil?
- %span.note Drag an image from the assets bucket to here
+ %span.note
+ = t('ad_banner_form.label.drag')
- else
= image_tag(@ad_banner.asset.thumbnail(:thumbnail))
= f.hidden_field :asset_id
%p.title
- %label{:for => 'ad_banner_link_url'} Link URL
+ %label{:for => 'ad_banner_link_url'}
+ = t('ad_banner_form.label.url')
= f.text_field :link_url, :class => 'textbox', :maxlength => 255
%p.title
%label{:for => 'ad_banner_weight'}
- Weight
- %span.note (The greater the weight, the more likely the ad banner is to appear.)
+ = t('ad_banner_form.label.weight')
+ %span.note
+ = t('ad_banner_form.label.weight_note')
= f.select :weight, (min_weight..10).to_a
%p.title
- %label{:for => 'ad_banner_link_target'} Target Window
- = f.select :link_target, [ [ 'Default', '' ], [ 'New Window', '_blank' ], [ 'Same Window', '_top' ] ]
+ %label{:for => 'ad_banner_link_target'}
+ = t('ad_banner_form.label.target')
+ = f.select :link_target, [ [ t('ad_banner_form.targets.default'), '' ], [ t('ad_banner_form.targets.new'), '_blank' ], [ t('ad_banner_form.targets.same'), '_top' ] ]
= javascript_tag "$('ad_banner_name').activate()"
%p.buttons
= save_model_button(@ad_banner)
= save_model_and_continue_editing_button(@ad_banner)
- or
- = link_to('Cancel', admin_ad_banners_url)
+ = t('or')
+ = link_to(t('cancel'), admin_ad_banners_url)
@@ -3,7 +3,7 @@
- render_region :main do |main|
- main.edit_header do
- %h1 Edit Ad Banner
+ %h1= t('ad_banner_action.edit')
- main.edit_form do
= render :partial => 'form'
@@ -1,42 +1,42 @@
- include_stylesheet 'admin/ad_banners'
-%h1 Ad Banners
+%h1= t('ad_banner_index_title')
%p
- Click on an ad banner name below to edit it, or click <code>Remove</code> to delete it.
+ != t('ad_banner_index_instructions')
%table#ad_banners.index
%thead
%tr
%th.name
- Name
+ = t('ad_banner_index_column.name')
%th.image
- Image Preview
+ = t('ad_banner_index_column.image')
%th.weight
- Weight
+ = t('ad_banner_index_column.weight')
%th.url
- URL
+ = t('ad_banner_index_column.url')
%th.modify
- Modify
+ = t('modify')
%tbody
- if @ad_banners.empty?
%tr
%td.note{ :colspan => '5' }
- No Ad Banners
+ = t('ad_banner_index_none')
- else
- @ad_banners.each do |ad_banner|
%tr.node.level-1
%td.name
= image('ad_banners/ad')
= link_to(h(ad_banner.name), edit_admin_ad_banner_url(ad_banner))
%td.image
- = ad_banner.asset ? image_tag(ad_banner.asset.thumbnail(:icon)) : '<span class="warning">MISSING</span>'
+ = ad_banner.asset ? image_tag(ad_banner.asset.thumbnail(:icon)) : %Q{<span class="warning">#{t('ad_banner_missing')}</span>}
%td.weight
= ad_banner.weight
%td.url
= auto_link ad_banner.link_url
%td.remove
- = link_to(image('remove', :alt => 'Remove Ad Banner'), remove_admin_ad_banner_url(ad_banner))
+ = link_to(t('remove'), remove_admin_ad_banner_url(ad_banner))
%p
- = link_to(image('ad_banners/new-ad', :alt => 'New Ad Banner'), new_admin_ad_banner_url)
+ = link_to(image('ad_banners/new-ad', :alt => t('ad_banner_action.new')), new_admin_ad_banner_url)
@@ -3,7 +3,7 @@
- render_region :main do |main|
- main.edit_header do
- %h1 New Ad Banner
+ %h1= t('ad_banner_action.new')
- main.edit_form do
= render :partial => 'form'
@@ -1,21 +1,22 @@
- include_stylesheet 'admin/ad_banners'
-%h1 Remove Ad Banner
+%h1= t('ad_banner_action.remove')
-%p Are you sure you want to <strong class="warning">permanently remove</strong> the following ad banner?
+%p
+ = t('ad_banner_action.remove_confirm')
%table#ad_banners.index
%tbody
%tr.node.level-1
%td.name
- = h @ad_banner.name
+ &= @ad_banner.name
%td.image
- = @ad_banner.asset ? image_tag(@ad_banner.asset.thumbnail(:icon)) : '<span class="warning">MISSING</span>'
+ = @ad_banner.asset ? image_tag(@ad_banner.asset.thumbnail(:icon)) : %Q{<span class="warning">#{t('ad_banner_missing')}</span>}
%td.link_url
= @ad_banner.link_url
- form_for [:admin, @ad_banner], :html => { :method => :delete } do
%p.buttons
- %input.button{ :type => 'submit', :value => 'Delete Ad Banner' }/
- or
- = link_to('Cancel', admin_ad_banners_url)
+ %input.button{ :type => 'submit', :value => t('ad_banner_action.delete') }/
+ = t('or')
+ = link_to(t('cancel'), admin_ad_banners_url)
View
@@ -0,0 +1,46 @@
+---
+en:
+ activerecord:
+ errors:
+ models:
+ ad_banner:
+ attributes:
+ link_url:
+ invalid: 'This is not a valid URL'
+ ad_banner_upload: 'Upload'
+ ad_banner_bucket: 'Bucket'
+ ad_banner_bucket_note: 'The Bucket provides temporary storage for your items.'
+ ad_banner_bucket_clear: 'Clear Bucket'
+ ad_banner_attach_title: 'Attach to ad'
+ ad_banner_bucket_empty: 'Your bucket is empty'
+ ad_banner_missing: 'MISSING'
+ ad_banner_index_title: 'Ad Banners'
+ ad_banner_index_instructions: 'Click on an ad banner name below to edit it, or click <code>Remove</code> to delete it.'
+ ad_banner_form:
+ instructions:
+ change: 'To change the ad banner image, drag an image from the asset bucket over the existing image thumbnail, or click the <b>+</b> (plus) icon next to the image in the asset bucket.'
+ disable: 'You can temporarily disable the display of the ad banner by setting the weight to <b>0</b> (zero). This will allow you to reenable the ad banner later without having to recreate it.'
+ label:
+ name: 'Banner Name'
+ thumbnail: 'Image Thumbnail'
+ drag: 'Drag an image from the assets bucket to here'
+ url: 'Link URL'
+ weight: 'Weight'
+ weight_note: '(The greater the weight, the more likely the ad banner is to appear.)'
+ target: 'Target Window'
+ targets:
+ default: 'Browser Default'
+ new: 'New Window'
+ same: 'Same Window'
+ ad_banner_index_column:
+ name: 'Name'
+ image: 'Image Preview'
+ weight: 'Weight'
+ url: 'URL'
+ ad_banner_index_none: 'No Ad Banners'
+ ad_banner_action:
+ delete: 'Delete Ad Banner'
+ edit: 'Edit Ad Banner'
+ new: 'New Ad Banner'
+ remove: 'Remove Ad Banner'
+ remove_confirm: 'Are you sure you want to <strong class="warning">permanently remove</strong> the following ad banner?'
@@ -7,8 +7,10 @@ namespace :radiant do
require 'radiant/extension_migrator'
if ENV["VERSION"]
AdBannersExtension.migrator.migrate(ENV["VERSION"].to_i)
+ Rake::Task['db:schema:dump'].invoke
else
AdBannersExtension.migrator.migrate
+ Rake::Task['db:schema:dump'].invoke
end
end
@@ -19,10 +21,36 @@ namespace :radiant do
Dir[AdBannersExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
path = file.sub(AdBannersExtension.root, '')
directory = File.dirname(path)
- mkdir_p RAILS_ROOT + directory
- cp file, RAILS_ROOT + path
+ mkdir_p RAILS_ROOT + directory, :verbose => false
+ cp file, RAILS_ROOT + path, :verbose => false
+ end
+
+ unless AdBannersExtension.root.starts_with? RAILS_ROOT # don't need to copy vendored tasks
+ puts "Copying rake tasks from AdBannerExtension"
+ local_tasks_path = File.join(RAILS_ROOT, %w(lib tasks))
+ mkdir_p local_tasks_path, :verbose => false
+ Dir[File.join AdBannerExtension.root, %w(lib tasks *.rake)].each do |file|
+ cp file, local_tasks_path, :verbose => false
+ end
end
end
+
+ desc "Syncs all available translations for this ext to the English ext master"
+ task :sync => :environment do
+ # The main translation root, basically where English is kept
+ language_root = AdBannerExtension.root + "/config/locales"
+ words = TranslationSupport.get_translation_keys(language_root)
+
+ Dir["#{language_root}/*.yml"].each do |filename|
+ next if filename.match('_available_tags')
+ basename = File.basename(filename, '.yml')
+ puts "Syncing #{basename}"
+ (comments, other) = TranslationSupport.read_file(filename, basename)
+ words.each { |k,v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist
+ other.delete_if { |k,v| !words[k] } # Remove if not defined in en.yml
+ TranslationSupport.write_file(filename, basename, comments, other)
+ end
+ end
end
end
end
@@ -41,7 +41,7 @@
it 'should require a valid URL' do
@ad_banner.link_url = 'example.com'
@ad_banner.should_not be_valid
- @ad_banner.errors.on(:link_url).should == "doesn't look like a URL"
+ @ad_banner.errors.on(:link_url).should == "This is not a valid URL"
end
end

0 comments on commit 8a1b200

Please sign in to comment.