Godwin
8 years ago
15 changed files with 347 additions and 516 deletions
@ -1,36 +1,42 @@ |
|||||
- if @events.present? |
- if @this_conference.event_locations.blank? |
||||
%ul.events.admin-blocks |
.warning-info=_'articles.admin.events.no_locations_warning' |
||||
- @events.each do | event | |
- else |
||||
%li |
- if @events.present? |
||||
%h4.title=event.title |
%table.events.admin-edit |
||||
.details |
%tr |
||||
= data_set(:h5, 'forms.labels.generic.event_location', class: :location) do |
%th=_'forms.labels.generic.title' |
||||
=event.event_location.present? ? event.event_location.title : '' |
%th=_'forms.labels.generic.event_location' |
||||
= data_set(:h5, 'forms.labels.generic.day', class: :day) do |
%th=_'forms.labels.generic.day' |
||||
= date(event.start_time.to_date, :weekday) |
%th=_'forms.labels.generic.time' |
||||
= data_set(:h5, 'forms.labels.generic.time', class: :time) do |
%th=_'forms.labels.generic.time_span' |
||||
= time(event.start_time, :short) |
%th.form |
||||
= data_set(:h5, 'forms.labels.generic.time_span', class: 'time-span') do |
- @events.each do | event | |
||||
= hours(event.start_time, event.end_time) |
%tr |
||||
= form_tag administration_update_path(@this_conference.slug, :events), class: [:actions, :fill] do |
%th=event.title |
||||
= hidden_field_tag :id, event.id |
%td=_!(event.event_location.present? ? event.event_location.title : '') |
||||
= button_with_confirmation :delete, (_'modals.admin.generic.delete.confirm', :p, vars: { title: event.title }), value: :delete, class: [:delete, :small] |
%td=date(event.start_time.to_date, :weekday) |
||||
= button_tag :edit, value: :edit, class: [:small] |
%td=time(event.start_time, :short) |
||||
|
%td=hours(event.start_time, event.end_time) |
||||
|
%td.form |
||||
|
= form_tag administration_update_path(@this_conference.slug, :events) do |
||||
|
= hidden_field_tag :id, event.id |
||||
|
= button_tag :edit, value: :edit, class: :small |
||||
|
= button_with_confirmation :delete, (_'modals.admin.generic.delete.confirm', :p, vars: { title: event.title }), value: :delete, class: [:delete, :small] |
||||
|
|
||||
%h4=_"articles.admin.locations.headings.#{@event.id.present? ? 'edit' : 'add'}_event", :t |
%h4=_"articles.admin.locations.headings.#{@event.id.present? ? 'edit' : 'add'}_event", :t |
||||
= form_tag administration_update_path(@this_conference.slug, :events) do |
= form_tag administration_update_path(@this_conference.slug, :events) do |
||||
= hidden_field_tag :id, @event.id if @event.id.present? |
= hidden_field_tag :id, @event.id if @event.id.present? |
||||
= textfield :title, @event.title!, required: true, big: true, lang: @event.locale |
= textfield :title, @event.title!, required: true, big: true, lang: @event.locale |
||||
= textarea :info, @event.info!, heading: 'articles.conference_registration.headings.admin.edit.info', help: 'articles.conference_registration.paragraphs.admin.edit.info', lang: @event.locale, edit_on: :focus |
= textarea :info, @event.info!, heading: 'articles.conference_registration.headings.admin.edit.info', help: 'articles.conference_registration.paragraphs.admin.events.info', lang: @event.locale, edit_on: :focus |
||||
.flex-inputs |
.flex-inputs |
||||
= location_select @event.event_location_id, small: true, stretch: true |
= location_select @event.event_location_id, small: true, stretch: true |
||||
= day_select @day, small: true, format: :weekday |
= day_select @day, small: true, format: :weekday |
||||
= time_select @time, small: true |
= time_select @time, small: true |
||||
= length_select @length, small: true |
= length_select @length, small: true |
||||
- I18n.backend.enabled_locales.each do | locale | |
- I18n.backend.enabled_locales.each do | locale | |
||||
- if locale.to_s != @event.locale.to_s |
- if locale.to_s != @event.locale.to_s |
||||
= textfield "title_translations[#{locale.to_s}]", @event._title(locale), big: true, heading: 'translate.pages.Locale_Translation', vars: { language: _("languages.#{locale}") }, label: 'forms.labels.generic.title', lang: locale |
= textfield "title_translations[#{locale.to_s}]", @event._title(locale), big: true, heading: 'translate.pages.Locale_Translation', vars: { language: _("languages.#{locale}") }, label: 'forms.labels.generic.title', lang: locale |
||||
= textarea "info_translations[#{locale.to_s}]", @event._info(locale), lang: locale, label: 'forms.labels.generic.info', edit_on: :focus |
= textarea "info_translations[#{locale.to_s}]", @event._info(locale), lang: locale, label: 'forms.labels.generic.info', edit_on: :focus |
||||
.actions.next-prev |
.actions.next-prev |
||||
= button_tag :save, value: :save |
= button_tag :save, value: :save |
||||
= button_tag :cancel, value: :cancel, class: :subdued, formnovalidate: true if @event.id.present? |
= button_tag :cancel, value: :cancel, class: :subdued, formnovalidate: true if @event.id.present? |
||||
|
@ -1,30 +1,34 @@ |
|||||
- if @this_conference.meals.present? |
- if @this_conference.event_locations.present? |
||||
%table.meals |
- if @this_conference.meals.present? |
||||
%tr |
%table.meals.admin-edit |
||||
%th=_'forms.labels.generic.title' |
|
||||
%th=_'forms.labels.generic.info' |
|
||||
%th=_'forms.labels.generic.event_location' |
|
||||
%th=_'forms.labels.generic.day' |
|
||||
%th=_'forms.labels.generic.time' |
|
||||
%th.form |
|
||||
- @meals.each do | time, meal | |
|
||||
%tr |
%tr |
||||
%th |
%th=_'forms.labels.generic.title' |
||||
=_!(meal['title'] || '') |
%th=_'forms.labels.generic.info' |
||||
%td=_!(meal['info'] || '') |
%th=_'forms.labels.generic.event_location' |
||||
%td=_!location_name(meal['location'].to_i) |
%th=_'forms.labels.generic.day' |
||||
%td=date(meal['day'], :weekday) |
%th=_'forms.labels.generic.time' |
||||
%td=time(meal['time'].to_f) |
%th.form |
||||
%td.form |
- @meals.each do | time, meal | |
||||
= form_tag administration_update_path(@this_conference.slug, :meals) do |
%tr |
||||
= hidden_field_tag :meal, time |
%th |
||||
= button_tag :delete, value: :delete, class: [:small, :delete] |
=_!(meal['title'] || '') |
||||
= form_tag administration_update_path(@this_conference.slug, :meals) do |
%td=_!(meal['info'] || '') |
||||
.flex-inputs |
%td=_!location_name(meal['location'].to_i) |
||||
= location_select nil, small: true, stretch: true |
%td=date(meal['day'], :weekday) |
||||
= day_select nil, small: true, format: :weekday |
%td=time(meal['time'].to_f) |
||||
= time_select nil, small: true |
%td.form |
||||
= textfield :title, nil, required: true, big: true |
= form_tag administration_update_path(@this_conference.slug, :meals) do |
||||
= textfield :info, nil |
= hidden_field_tag :meal, time |
||||
.actions.next-prev |
= button_tag :delete, value: :delete, class: [:small, :delete] |
||||
= button_tag :add_meal, value: :add_meal |
= form_tag administration_update_path(@this_conference.slug, :meals) do |
||||
|
%h4=_'articles.admin.locations.headings.add_meal', :t |
||||
|
.flex-inputs |
||||
|
= location_select nil, small: true, stretch: true |
||||
|
= day_select nil, small: true, format: :weekday |
||||
|
= time_select nil, small: true |
||||
|
= textfield :title, nil, required: true, big: true, help: 'articles.admin.locations.paragraphs.meal_title' |
||||
|
= textfield :info, nil, help: 'articles.admin.locations.paragraphs.meal_info' |
||||
|
.actions.next-prev |
||||
|
= button_tag :add_meal, value: :add_meal |
||||
|
- else |
||||
|
.warning-info=_'articles.admin.meals.no_locations_warning' |
@ -1,134 +1,136 @@ |
|||||
- conference = @this_conference || @conference |
- conference = @this_conference || @conference |
||||
- if @entire_page |
- if conference.event_locations.blank? && @entire_page |
||||
= form_tag administration_update_path(conference.slug, :schedule) do |
.warning-info=_'articles.admin.schedule.no_locations_warning' |
||||
- if conference.workshop_schedule_published |
- else |
||||
%p=_'articles.conference_registration.paragraphs.admin.schedule.published', :p |
- if @entire_page |
||||
.actions= button_tag :un_publish, value: :publish, class: :delete |
= form_tag administration_update_path(conference.slug, :schedule) do |
||||
- else |
- if conference.workshop_schedule_published |
||||
%p=_'articles.conference_registration.paragraphs.admin.schedule.un_published', :p |
%p=_'articles.conference_registration.paragraphs.admin.schedule.published', :p |
||||
.actions= button_tag :publish, value: :publish |
.actions= button_tag :un_publish, value: :publish, class: :delete |
||||
|
- else |
||||
|
%p=_'articles.conference_registration.paragraphs.admin.schedule.un_published', :p |
||||
|
.actions= button_tag :publish, value: :publish |
||||
|
|
||||
#schedule-preview |
#schedule-preview |
||||
- @schedule.each do | day, data | |
- @schedule.each do | day, data | |
||||
%h4=date(day, :weekday) |
%h4=date(day, :weekday) |
||||
%table.schedule{class: [data[:locations].present? ? 'has-locations' : 'no-locations', "locations-#{data[:locations].size}"]} |
%table.schedule{class: [data[:locations].present? ? 'has-locations' : 'no-locations', "locations-#{data[:locations].size}"]} |
||||
- if data[:locations].present? |
- if data[:locations].present? |
||||
%thead |
%thead |
||||
%tr |
%tr |
||||
%th.corner |
%th.corner |
||||
- data[:locations].each do | id, location | |
- data[:locations].each do | id, location | |
||||
%th=location.title |
%th=location.title |
||||
%th.status |
%th.status |
||||
%tbody |
%tbody |
||||
- data[:times].each do | time, time_data | |
- data[:times].each do | time, time_data | |
||||
%tr |
%tr |
||||
- rowspan = (time_data[:length] * 2).to_i |
- rowspan = (time_data[:length] * 2).to_i |
||||
%th=time(time) |
%th=time(time) |
||||
- if time_data[:type] == :workshop |
- if time_data[:type] == :workshop |
||||
- if time_data[:item][:workshops].present? |
- if time_data[:item][:workshops].present? |
||||
- data[:locations].each do | id, location | |
- data[:locations].each do | id, location | |
||||
- if time_data[:item][:workshops][id].present? |
- if time_data[:item][:workshops][id].present? |
||||
- workshop = time_data[:item][:workshops][id][:workshop] |
- workshop = time_data[:item][:workshops][id][:workshop] |
||||
- status = time_data[:item][:workshops][id][:status] |
- status = time_data[:item][:workshops][id][:status] |
||||
- else |
- else |
||||
- workshop = status = nil |
- workshop = status = nil |
||||
%td{class: [time_data[:type], workshop.present? ? :filled : nil], rowspan: rowspan} |
%td{class: [time_data[:type], workshop.present? ? :filled : nil], rowspan: rowspan} |
||||
- if workshop.present? |
- if workshop.present? && workshop.event_location.present? |
||||
= link_to off_screen(workshop.title), view_workshop_path(@conference.slug, workshop.id), class: 'event-detail-link' |
= link_to off_screen(workshop.title), view_workshop_path(@conference.slug, workshop.id), class: 'event-detail-link' |
||||
%template.event-details{data: { href: view_workshop_path(@conference.slug, workshop.id) }} |
%template.event-details{data: { href: view_workshop_path(@conference.slug, workshop.id) }} |
||||
%h1.title=workshop.title |
%h1.title=workshop.title |
||||
%p.address |
%p.address |
||||
= workshop.event_location.title + _!(': ') |
= workshop.event_location.title + _!(': ') |
||||
%a{ href: "http://www.google.com/maps/place/#{workshop.event_location.latitude},#{workshop.event_location.longitude}" } |
= location_link workshop.event_location |
||||
= workshop.event_location.address |
.workshop-description= richtext workshop.info, 1 |
||||
.workshop-description= richtext workshop.info, 1 |
.title=workshop.title |
||||
.title=workshop.title |
- if @can_edit |
||||
- if @can_edit |
= form_tag administration_update_path(conference.slug, :schedule), class: 'js-xhr' do |
||||
= form_tag administration_update_path(conference.slug, :schedule), class: 'js-xhr' do |
.status |
||||
.status |
.conflict-score |
||||
.conflict-score |
%span.title Conflict Score: |
||||
%span.title Conflict Score: |
%span.value="#{status[:conflict_score] * 100.0}%" |
||||
%span.value="#{status[:conflict_score] * 100.0}%" |
- if status[:errors].present? |
||||
- if status[:errors].present? |
.errors |
||||
.errors |
- status[:errors].each do | error | |
||||
- status[:errors].each do | error | |
.error=_"errors.messages.schedule.#{error[:name].to_s}", vars: error[:i18nVars] |
||||
.error=_"errors.messages.schedule.#{error[:name].to_s}", vars: error[:i18nVars] |
= hidden_field_tag :id, workshop.id |
||||
= hidden_field_tag :id, workshop.id |
= button_tag :deschedule, value: :deschedule_workshop, class: [:delete, :small] |
||||
= button_tag :deschedule, value: :deschedule_workshop, class: [:delete, :small] |
- elsif @can_edit |
||||
- elsif @can_edit |
.title="Block #{time_data[:item][:block] + 1}" |
||||
|
- else |
||||
|
%td{class: time_data[:type], rowspan: rowspan, colspan: data[:locations].present? ? data[:locations].size : 1} |
||||
|
- if @can_edit |
||||
.title="Block #{time_data[:item][:block] + 1}" |
.title="Block #{time_data[:item][:block] + 1}" |
||||
- else |
%td.status{rowspan: rowspan} |
||||
|
- if time_data[:status].present? && time_data[:status][:errors].present? |
||||
|
%ul.errors |
||||
|
- time_data[:status][:errors].each do | error | |
||||
|
%li=error.to_json.to_s |
||||
|
- elsif time_data[:type] != :nil |
||||
%td{class: time_data[:type], rowspan: rowspan, colspan: data[:locations].present? ? data[:locations].size : 1} |
%td{class: time_data[:type], rowspan: rowspan, colspan: data[:locations].present? ? data[:locations].size : 1} |
||||
- if @can_edit |
- case time_data[:type] |
||||
.title="Block #{time_data[:item][:block] + 1}" |
- when :meal |
||||
%td.status{rowspan: rowspan} |
- location = EventLocation.where(id: time_data[:item]['location'].to_i).first |
||||
- if time_data[:status].present? && time_data[:status][:errors].present? |
- if location.present? |
||||
%ul.errors |
%a.event-detail-link=off_screen(time_data[:item]['title']) |
||||
- time_data[:status][:errors].each do | error | |
%template.event-details |
||||
%li=error.to_json.to_s |
%h1.title=time_data[:item]['title'] |
||||
- elsif time_data[:type] != :nil |
%p.address |
||||
%td{class: time_data[:type], rowspan: rowspan, colspan: data[:locations].present? ? data[:locations].size : 1} |
= location.title + _!(': ') |
||||
- case time_data[:type] |
= location_link location |
||||
- when :meal |
.title= time_data[:item]['title'] |
||||
%a.event-detail-link=off_screen(time_data[:item]['title']) |
.location= location.title |
||||
- location = EventLocation.find(time_data[:item]['location'].to_i) |
- when :event |
||||
%template.event-details |
- if time_data[:item].event_location.present? |
||||
%h1.title=time_data[:item]['title'] |
%a.event-detail-link=off_screen(time_data[:item][:title]) |
||||
%p.address |
%template.event-details |
||||
= location.title + _!(': ') |
%h1.title=time_data[:item][:title] |
||||
%a{ href: "http://www.google.com/maps/place/#{location.latitude},#{location.longitude}" } |
%p.address |
||||
= location.address |
= time_data[:item].event_location.title + _!(': ') |
||||
.title= time_data[:item]['title'] |
= location_link time_data[:item].event_location |
||||
.location= location.title |
= richtext time_data[:item][:info], 1 |
||||
- when :event |
.title= time_data[:item][:title] |
||||
%a.event-detail-link=off_screen(time_data[:item][:title]) |
.location= time_data[:item].event_location.title |
||||
%template.event-details |
%td.status{rowspan: rowspan} |
||||
%h1.title=time_data[:item][:title] |
- if @entire_page |
||||
%p.address |
%ul.workshops-to-schedule |
||||
= time_data[:item].event_location.title + _!(': ') |
- @workshops.each do | workshop | |
||||
%a{ href: "http://www.google.com/maps/place/#{time_data[:item].event_location.latitude},#{time_data[:item].event_location.longitude}" } |
%li{id: "workshop-#{workshop.id}", class: workshop.block.present? ? 'booked' : 'not-booked'} |
||||
= time_data[:item].event_location.address |
%h4.title= workshop.title |
||||
= richtext time_data[:item][:info], 1 |
= form_tag administration_update_path(conference.slug, :schedule), class: 'js-xhr' do |
||||
.title= time_data[:item][:title] |
.already-booked |
||||
.location= time_data[:item].event_location.title |
.field-error='This block is already booked' |
||||
%td.status{rowspan: rowspan} |
.workshop-description |
||||
- if @entire_page |
.details |
||||
%ul.workshops-to-schedule |
= data_set(:h5, 'articles.workshops.headings.interested_count') do |
||||
- @workshops.each do | workshop | |
= workshop.interested_count |
||||
%li{id: "workshop-#{workshop.id}", class: workshop.block.present? ? 'booked' : 'not-booked'} |
= data_set(:h5, 'articles.workshops.headings.facilitators') do |
||||
%h4.title= workshop.title |
- facilitators = [] |
||||
= form_tag administration_update_path(conference.slug, :schedule), class: 'js-xhr' do |
- workshop.active_facilitators.each do | facilitator | |
||||
.already-booked |
- facilitators << facilitator.name |
||||
.field-error='This block is already booked' |
= facilitators.join ', ' |
||||
.workshop-description |
= data_set(:h5, 'articles.workshops.headings.needs') do |
||||
.details |
- needs = [] |
||||
= data_set(:h5, 'articles.workshops.headings.interested_count') do |
- JSON.parse(workshop.needs || '[]').each do | need | |
||||
= workshop.interested_count |
- needs << (_"workshop.options.needs.#{need}") |
||||
= data_set(:h5, 'articles.workshops.headings.facilitators') do |
= _!(needs.join ', ') |
||||
- facilitators = [] |
= data_set(:h5, 'articles.workshops.headings.theme') do |
||||
- workshop.active_facilitators.each do | facilitator | |
= workshop.theme.present? ? (_"workshop.options.theme.#{workshop.theme}") : '' |
||||
- facilitators << facilitator.name |
= data_set(:h5, 'articles.workshops.headings.space') do |
||||
= facilitators.join ', ' |
= workshop.space.present? ? (_"workshop.options.space.#{workshop.space}") : '' |
||||
= data_set(:h5, 'articles.workshops.headings.needs') do |
= data_set(:h5, 'forms.labels.generic.info') do |
||||
- needs = [] |
= link_info_dlg truncate(workshop.info), (richtext workshop.info.html_safe), workshop.title |
||||
- JSON.parse(workshop.needs || '[]').each do | need | |
- if workshop.notes.present? && strip_tags(workshop.notes).length > 0 |
||||
- needs << (_"workshop.options.needs.#{need}") |
= data_set(:h5, 'forms.labels.generic.notes') do |
||||
= _!(needs.join ', ') |
= link_info_dlg truncate(workshop.notes), (richtext workshop.notes.html_safe), workshop.title |
||||
= data_set(:h5, 'articles.workshops.headings.theme') do |
|
||||
= workshop.theme.present? ? (_"workshop.options.theme.#{workshop.theme}") : '' |
|
||||
= data_set(:h5, 'articles.workshops.headings.space') do |
|
||||
= workshop.space.present? ? (_"workshop.options.space.#{workshop.space}") : '' |
|
||||
= data_set(:h5, 'forms.labels.generic.info') do |
|
||||
= link_info_dlg truncate(workshop.info), (richtext workshop.info.html_safe), workshop.title |
|
||||
- if workshop.notes.present? && strip_tags(workshop.notes).length > 0 |
|
||||
= data_set(:h5, 'forms.labels.generic.notes') do |
|
||||
= link_info_dlg truncate(workshop.notes), (richtext workshop.notes.html_safe), workshop.title |
|
||||
|
|
||||
= hidden_field_tag :id, workshop.id |
= hidden_field_tag :id, workshop.id |
||||
.drop-downs |
.drop-downs |
||||
= location_select workshop.event_location_id, small: true |
= location_select workshop.event_location_id, small: true |
||||
= block_select workshop.block.present? ? "#{workshop.block['day']}:#{workshop.block['block']}" : nil, small: true |
= block_select workshop.block.present? ? "#{workshop.block['day']}:#{workshop.block['block']}" : nil, small: true |
||||
.actions.next-prev |
.actions.next-prev |
||||
= button_tag :deschedule, value: :deschedule_workshop, class: [:delete, 'booked-only', :small] |
= button_tag :deschedule, value: :deschedule_workshop, class: [:delete, 'booked-only', :small] |
||||
= button_tag :reschedule, value: :schedule_workshop, class: [:secondary, 'booked-only', :small] |
= button_tag :reschedule, value: :schedule_workshop, class: [:secondary, 'booked-only', :small] |
||||
= button_tag :schedule_workshop, value: :schedule_workshop, class: ['not-booked-only', :small] |
= button_tag :schedule_workshop, value: :schedule_workshop, class: ['not-booked-only', :small] |
||||
|
@ -1,263 +0,0 @@ |
|||||
# require 'i18n/backend/active_record' |
|
||||
# require 'yaml' |
|
||||
|
|
||||
# if Rails.env.test? |
|
||||
# class DevTranslation < Translation |
|
||||
# self.table_name = 'translations' |
|
||||
# establish_connection :development |
|
||||
# end |
|
||||
# end |
|
||||
|
|
||||
# module I18n |
|
||||
# class MissingTranslationExceptionHandler < ExceptionHandler |
|
||||
# def self.lorem_ipsum(method, size) |
|
||||
# options = {:random => true} |
|
||||
# case method.to_s |
|
||||
# when 'c', 'char', 'character', 'characters' |
|
||||
# if size |
|
||||
# return (Forgery::LoremIpsum.characters size, options).capitalize |
|
||||
# end |
|
||||
# return Forgery::LoremIpsum.character, options |
|
||||
# when 'w', 'word', 'words' |
|
||||
# if size |
|
||||
# return (Forgery::LoremIpsum.words size, options).capitalize |
|
||||
# end |
|
||||
# #return'LOREM' |
|
||||
# return (Forgery::LoremIpsum.word options).capitalize |
|
||||
# when 's', 'sentence', 'sentences' |
|
||||
# if size |
|
||||
# return Forgery::LoremIpsum.sentences size, options |
|
||||
# end |
|
||||
# return (Forgery::LoremIpsum.sentence options).capitalize |
|
||||
# when 'p', 'paragraph', 'paragraphs' |
|
||||
# if size |
|
||||
# return Forgery::LoremIpsum.paragraphs size, options.merge({:sentences => 10}) |
|
||||
# end |
|
||||
# return Forgery::LoremIpsum.sentences 10, options |
|
||||
# when 't', 'title' |
|
||||
# return (Forgery::LoremIpsum.sentences 1, options).capitalize |
|
||||
# end |
|
||||
# return method |
|
||||
# end |
|
||||
|
|
||||
# def self.note(key, behavior = nil, behavior_size = nil) |
|
||||
# I18n.backend.needs_translation(key) |
|
||||
# if behavior |
|
||||
# if behavior.to_s == 'strict' |
|
||||
# return nil |
|
||||
# end |
|
||||
# return self.lorem_ipsum(behavior, behavior_size) |
|
||||
# end |
|
||||
# #key.to_s.gsub(/^world\..*\.(.+)\.name$/, '\1').gsub(/^.*\.(.+)?$/, '\1').gsub('_', ' ') |
|
||||
# key.to_s.gsub(/^world\.(.+)\.name$/, '\1').gsub(/^.*\.(.+)?$/, '\1').gsub('_', ' ') |
|
||||
# end |
|
||||
|
|
||||
# def call(exception, locale, key, options) |
|
||||
# if exception.is_a?(MissingTranslation) |
|
||||
# I18n::MissingTranslationExceptionHandler.note(key, options[:behavior] || nil, options[:behavior_size] || nil) |
|
||||
# else |
|
||||
# super |
|
||||
# end |
|
||||
# end |
|
||||
# end |
|
||||
|
|
||||
# module Backend |
|
||||
# class BikeBike < I18n::Backend::ActiveRecord |
|
||||
# @@needs_translation |
|
||||
|
|
||||
# @@translations_file = 'config/locales/translation-info.yml' |
|
||||
# @@translation_cache_file = 'config/locales/.translation-cache.yml' |
|
||||
# @@pluralization_rules_file = 'config/locales/pluralization-rules.yml' |
|
||||
# @@translation_cache |
|
||||
# @@testing_started = false |
|
||||
# @@hosts |
|
||||
|
|
||||
# def self.init_tests!(new_translations = nil) |
|
||||
# if Rails.env.test? |
|
||||
# if !@@testing_started |
|
||||
# @@testing_started = true |
|
||||
# File.open(@@translations_file, 'w+') |
|
||||
# File.open(@@translation_cache_file, 'w+') |
|
||||
# end |
|
||||
# if !new_translations.nil? |
|
||||
# record_translation(new_translations) |
|
||||
# end |
|
||||
# end |
|
||||
# end |
|
||||
|
|
||||
# def needs_translation(key) |
|
||||
# @@needs_translation ||= Array.new |
|
||||
# @@needs_translation << key |
|
||||
# end |
|
||||
|
|
||||
# def translate_control(translation) |
|
||||
# @@translationsOnThisPage = true |
|
||||
# datakeys = '' |
|
||||
# translation['vars'].each { |key, value| datakeys += ' data-var-' + key.to_s + '="' + value.to_s.gsub('"', '"') + '"' } |
|
||||
# ('<span class="translate-me ' + (translation['is_translated'] ? '' : 'un') + 'translated lang-' + (translation['lang']) + ' key--' + translation['key'].gsub('.', '--') + '" data-translate-key="' + translation['key'] + '" data-translate-untranslated="' + translation['untranslated'].gsub('"', '"') + (translation['translated'] ? '" data-translate-translated="' + translation['translated'] : '') + '" data-vars="' + (translation['vars'].length ? translation['vars'].to_json.gsub('"', '"') : '') + '" title="' + ('translate.alt_click') + '">' + (translation['html'] || translation['untranslated']) + '</span>').to_s.html_safe |
|
||||
# end |
|
||||
|
|
||||
# def initialized? |
|
||||
# begin |
|
||||
# super |
|
||||
# rescue |
|
||||
# return false |
|
||||
# end |
|
||||
# end |
|
||||
|
|
||||
# def initialize |
|
||||
# if !File.exist?(@@translation_cache_file) |
|
||||
# File.open(@@translation_cache_file, 'w+') |
|
||||
# end |
|
||||
# @@translation_cache = YAML.load(File.read(@@translation_cache_file)) || Hash.new |
|
||||
# super |
|
||||
# end |
|
||||
|
|
||||
# def get_translation_info() |
|
||||
# begin |
|
||||
# YAML.load_file(@@translations_file) || {} |
|
||||
# rescue Exception => e |
|
||||
# # sometimes concurrency issues cause an exception during testing |
|
||||
# sleep(1/2.0) |
|
||||
# get_translation_info() |
|
||||
# end |
|
||||
# end |
|
||||
|
|
||||
# def get_pluralization_rules(locale) |
|
||||
# rules = YAML.load_file(@@pluralization_rules_file) |
|
||||
# rules[locale.to_sym] |
|
||||
# end |
|
||||
|
|
||||
# def get_language_codes() |
|
||||
# YAML.load_file(@@pluralization_rules_file).keys |
|
||||
# end |
|
||||
|
|
||||
# def set_locale(host) |
|
||||
# @@hosts ||= Hash.new |
|
||||
# default = I18n.default_locale.to_s |
|
||||
# lang = @@hosts[host] |
|
||||
# if lang === false |
|
||||
# lang = nil |
|
||||
# elsif lang.nil? |
|
||||
# if (lang = host.gsub(/^(dev|test|www)[\-\.](.*)$/, '\2').gsub(/^(([^\.]+)\.)?[^\.]+\.[^\.]+$/, '\2')).blank? || (host == "localhost") |
|
||||
# lang = default |
|
||||
# end |
|
||||
# if get_language_codes().include? lang |
|
||||
# if !language_enabled? lang |
|
||||
# I18n.locale = default |
|
||||
# return lang |
|
||||
# end |
|
||||
# else |
|
||||
# lang = nil |
|
||||
# end |
|
||||
# end |
|
||||
# I18n.locale = default unless lang.present? |
|
||||
# # return nil if the language doesn exist, false if it is not enabled, or the code if it is enabled |
|
||||
# lang.present? ? true : false |
|
||||
# end |
|
||||
|
|
||||
# def get_language_completion(lang) |
|
||||
# total = 0 |
|
||||
# complete = 0 |
|
||||
# get_translation_info().each { |k,v| |
|
||||
# total += 1 |
|
||||
# complete += v['languages'].include?(lang.to_s) ? 1 : 0 |
|
||||
# } |
|
||||
# (total ? complete / total.to_f : 0.0) * 100.0 |
|
||||
# end |
|
||||
|
|
||||
# def language_enabled?(lang) |
|
||||
# lang.to_s == I18n.default_locale.to_s || get_language_completion(lang) > 66 |
|
||||
# end |
|
||||
|
|
||||
# def request_translation(key, vars, options) |
|
||||
# locale = options[:locale].to_s |
|
||||
# options[:locale] = :en |
|
||||
# translation = I18n.translate(key, vars, options) |
|
||||
# result = JSON.load(open("http://translate.google.com/translate_a/t?client=t&text=#{URI::escape(translation)}&hl=en&sl=en&tl=#{locale}&ie=UTF-8&oe=UTF-8&multires=1&otf=1&ssel=3&tsel=3&sc=1").read().gsub(/,+/, ',').gsub(/\[,+/, '[').gsub(/,+\]/, ']')) |
|
||||
# while result.is_a?(Array) |
|
||||
# result = result[0] |
|
||||
# end |
|
||||
# return result |
|
||||
# end |
|
||||
|
|
||||
# def record_translation(key) |
|
||||
# translations = get_translation_info() |
|
||||
# translations ||= Hash.new |
|
||||
|
|
||||
# if key.is_a(Array) |
|
||||
# key.each { |k| translations[k.to_s] ||= Hash.new } |
|
||||
# else |
|
||||
# translations[key.to_s] ||= Hash.new |
|
||||
# end |
|
||||
# File.open(@@translations_file, 'w') { |f| f.write translations.to_yaml } |
|
||||
# end |
|
||||
|
|
||||
# protected |
|
||||
# def lookup(locale, key, scope = [], options = {}) |
|
||||
# result = nil |
|
||||
|
|
||||
# if key.is_a?(String) |
|
||||
# key = key.gsub(/(^\[|\])/, '').gsub(/\[/, '.') |
|
||||
# end |
|
||||
|
|
||||
# if @@translation_cache && @@translation_cache.has_key?(locale.to_s) && @@translation_cache[locale.to_s].has_key?(key.to_s) |
|
||||
# result = @@translation_cache[locale.to_s][key.to_s] |
|
||||
# end |
|
||||
# if !result |
|
||||
# result = super(locale, key, scope, options) |
|
||||
|
|
||||
# if Rails.env.test? && options[:behavior].to_s != 'scrict' |
|
||||
# if result |
|
||||
# @@translation_cache[locale.to_s] ||= Hash.new |
|
||||
# @@translation_cache[locale.to_s][key.to_s] = result |
|
||||
# File.open(@@translation_cache_file, 'w') { |f| f.write @@translation_cache.to_yaml } |
|
||||
# end |
|
||||
|
|
||||
# translations = get_translation_info() |
|
||||
# translations ||= Hash.new |
|
||||
# translations[key.to_s] ||= Hash.new |
|
||||
# translations[key.to_s]['languages'] ||= Array.new |
|
||||
# translations[key.to_s]['pages'] ||= Array.new |
|
||||
# if options['behavior'] |
|
||||
# translations[key.to_s]['behavior'] ||= options['behavior'] |
|
||||
# end |
|
||||
# vars = [] |
|
||||
# options.each { |o,v| |
|
||||
# if !I18n::RESERVED_KEYS.include?(o.to_sym) && o.to_s != 'behavior' && o.to_s != 'behavior_size' |
|
||||
# vars << o.to_sym |
|
||||
# end |
|
||||
# } |
|
||||
# if vars.size() > 0 |
|
||||
# translations[key.to_s]['vars'] = vars |
|
||||
# end |
|
||||
# unless translations[key.to_s].has_key?('data') |
|
||||
# translations[key.to_s]['data'] = Array.new |
|
||||
# DevTranslation.where("key = '#{key.to_s}' OR key LIKE '#{key.to_s}#{I18n::Backend::Flatten::FLATTEN_SEPARATOR}%'").each { |t| |
|
||||
# translations[key.to_s]['data'] << ActiveSupport::JSON.encode(t.becomes(Translation)) |
|
||||
# unless translations[key.to_s]['languages'].include?(t.locale.to_s) |
|
||||
# translations[key.to_s]['languages'] << t.locale.to_s |
|
||||
# end |
|
||||
# } |
|
||||
# end |
|
||||
# path = $page_info[:path] |
|
||||
# route = nil |
|
||||
# Rails.application.routes.routes.each { |r| |
|
||||
# if !route && r.path.match(path) |
|
||||
# route = r.path.spec.to_s.gsub(/\s*\(\.:\w+\)\s*$/, '') |
|
||||
# end |
|
||||
# } |
|
||||
# unless translations[key.to_s]['pages'].include?(route) |
|
||||
# translations[key.to_s]['pages'] << route |
|
||||
# end |
|
||||
# File.open(@@translations_file, 'w') { |f| f.write translations.to_yaml } |
|
||||
# end |
|
||||
# end |
|
||||
|
|
||||
# result |
|
||||
# end |
|
||||
# end |
|
||||
# end |
|
||||
# end |
|
||||
|
|
||||
# I18n.exception_handler = I18n::MissingTranslationExceptionHandler.new |
|
Loading…
Reference in new issue