Browse Source

Translations

development
Godwin 11 years ago
parent
commit
52e5e10232
  1. 8
      Gemfile
  2. 17
      Gemfile.lock
  3. BIN
      Thumbs.db
  4. 61
      app/assets/javascripts/application.js.coffee
  5. 1
      app/assets/stylesheets/application.css.scss
  6. 88
      app/assets/stylesheets/sass/_base.scss
  7. 10
      app/assets/stylesheets/sass/_layout.scss
  8. 50
      app/controllers/pages_controller.rb
  9. 202
      app/helpers/application_helper.rb
  10. 22
      app/views/pages/translation_list.html.haml
  11. 41
      app/views/pages/translations.html.haml
  12. 2
      app/views/user_sessions/_form.html.haml
  13. 3
      config/application.rb
  14. 90
      config/initializers/i18n.rb
  15. 23
      config/routes.rb
  16. 4
      spec/features/pages/login_spec.rb
  17. 2
      spec/features/pages/organization_registration_spec.rb
  18. 22
      spec/features/pages/translations_spec.rb
  19. 1
      spec/spec_helper.rb

8
Gemfile

@ -21,7 +21,7 @@ gem 'pg'
# Security
# gem 'secure_headers'
gem 'dotenv-rails', :groups => [:development, :test]
#gem 'dotenv-rails', :groups => [:development, :test]
# Miscellanea
# gem 'google-analytics-rails'
@ -43,7 +43,7 @@ gem 'jquery-turbolinks'
gem 'sass-rails', '~> 4.0.0'
gem "compass-rails", "~> 1.1.3"
gem 'foundation-rails'
gem 'turbolinks'
#gem 'turbolinks' # This would be great to have working, right now lets focus on gettting it working without it.
gem 'uglifier', '>= 1.3.0'
gem 'sorcery', '>= 0.8.1'
gem 'oauth2', '~> 0.8.0'
@ -52,7 +52,9 @@ gem 'redis'
gem 'carrierwave'
gem 'carrierwave-imageoptimizer'
gem 'mini_magick'
#gem 'carmen', :path => '../carmen /'
if File.directory?('../carmen/')
gem 'carmen', :path => '../carmen/', require: false
end
gem 'carmen-rails'
gem 'nested_form'
gem 'acts_as_list'

17
Gemfile.lock

@ -12,6 +12,11 @@ GIT
i18n-active_record (0.0.2)
i18n (>= 0.5.0)
PATH
remote: ../carmen/
specs:
carmen (1.0.1)
GEM
remote: http://rubygems.org/
specs:
@ -66,8 +71,6 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
carmen (1.0.1)
unicode_utils (~> 1.4.0)
carmen-rails (1.0.1)
carmen (~> 1.0.0)
rails
@ -124,11 +127,6 @@ GEM
chronic
diff-lcs (1.2.5)
docile (1.1.3)
dotenv (0.11.1)
dotenv-deployment (~> 0.0.2)
dotenv-deployment (0.0.2)
dotenv-rails (0.11.1)
dotenv (= 0.11.1)
email_spec (1.5.0)
launchy (~> 2.1)
mail (~> 2.2)
@ -340,14 +338,12 @@ GEM
uglifier (2.5.0)
execjs (>= 0.3.0)
json (>= 1.8.0)
unicode_utils (1.4.0)
uniform_notifier (1.4.0)
wdm (0.1.0)
webmock (1.17.4)
addressable (>= 2.2.7)
crack (>= 0.3.2)
websocket (1.0.7)
win32console (1.3.2)
win32console (1.3.2-x86-mingw32)
xpath (2.0.0)
nokogiri (~> 1.3)
@ -363,6 +359,7 @@ DEPENDENCIES
binding_of_caller
bullet
capybara
carmen!
carmen-rails
carrierwave
carrierwave-imageoptimizer
@ -372,7 +369,6 @@ DEPENDENCIES
database_cleaner
debugger
delorean
dotenv-rails
email_spec
eventmachine
factory_girl_rails
@ -407,7 +403,6 @@ DEPENDENCIES
selenium-webdriver
simplecov
sorcery (>= 0.8.1)
turbolinks
uglifier (>= 1.3.0)
wdm (>= 0.1.0)
webmock

BIN
Thumbs.db

Binary file not shown.

61
app/assets/javascripts/application.js.coffee

@ -1,8 +1,8 @@
#= require jquery
#= require jquery_ujs
#= require jquery.ui.sortable
#= require jquery.turbolinks
#= require turbolinks
# = #require jquery.turbolinks
# = #require turbolinks
#= require foundation
# FRONT END
@ -123,6 +123,50 @@ updateFormFieldList = () ->
updateFormFieldList()
return
saveTranslation = ($td, $move_to, auto_translate) ->
val = ''
do_auto_translate = true
if typeof auto_translate == "undefined" || !auto_translate
val = $td.find('textarea').val()
do_auto_translate = false
key = $td.parent().data().key
params = {translationkey: key, translationvalue: val, translationlang: window.location.href.replace(/^.*\/(\w+)\/$/, '$1')}
if do_auto_translate
params['auto_translate'] = true
$.post '/translate/', params,
(json) ->
#console.log json
$td.html(json.translation)
if $td.parent().hasClass('not-exists')
$td.parent().removeClass('not-exists')
$td.parent().addClass('exists')
$('.translation-form').remove()
if typeof $move_to != "undefined" && $move_to
startTranslating $move_to
return
return
stopTranslating = () -> $('.translation-form').remove()
startTranslating = ($td) ->
stopTranslating()
value = if $td.parent().hasClass('not-exists') then '' else $td.html().trim()
$tr = $td.parent()
key = $tr.data().key
$td.append('<div class="translation-form"><textarea>' + value + '</textarea><button class="small" data-key="' + key + '">Save</textarea>')
$textarea = $td.find('textarea')
$textarea.select()
$td.find('.translation-form button').click () -> saveTranslation($td)
$textarea.keydown (event) ->
if event.keyCode == 9
event.preventDefault()
$new_tr = if event.shiftKey then $tr.prev() else $tr.next()
saveTranslation $td, $new_tr.find('.value')
else if event.keyCode == 27
stopTranslating()
return
return
$ ->
$(document).foundation();
$('.field.country-select select').change () ->
@ -169,3 +213,16 @@ $ ->
# (json) ->
# console.log json
#, 'json'
$('table#translations td.value').click () ->
$this = $(this)
if !$this.find('.translation-form').length
startTranslating($this)
if $('table#translations').length
$(document).click (event) ->
$target = $(event.target)
if $target.closest('table#translations').length < 1 && !$target.hasClass('auto-translate')
stopTranslating()
$('.auto-translate').click (event) ->
event.preventDefault()
$td = $(this).parent()
saveTranslation($td, null, true)

1
app/assets/stylesheets/application.css.scss

@ -22,3 +22,4 @@
// Local settings (also edit foundation_and_overrides.scss to modify global variables)
@import "sass/layout";
@import "sass/typography";
@import "sass/base";

88
app/assets/stylesheets/sass/_base.scss

@ -0,0 +1,88 @@
table#translations {
td.value {
position: relative;
cursor: text;
&:hover,
.translation-form {
color: $white;
background-color: $body-font-color;
}
}
.not-exists {
td.value {
font-style: italic;
color: lighten($body-font-color, 45);
}
}
.translation-form {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 10;
padding: inherit;
textarea {
height: 100%;
font-size: inherit;
padding: 0;
color: inherit;
background-color: inherit;
}
button {
right: 100%;
position: absolute;
border-radius: 0;
top: 0;
}
}
.auto-translate {
float: right;
}
}
.grid.links {
li > a {
display: block;
background-color: $color-5;
color: $white;
padding: 1em;
min-height: 7em;
&:hover {
background-color: $color-1;
}
h3 {
color: inherit;
}
}
}
ul.tags,
.tags > ul {
display: inline;
list-style: none;
font-size: 0.9em;
margin: 0;
}
.tags {
li {
display: inline-block;
background-color: $black;
color: $white;
padding: 0 0.5em;
margin: 0.6em 0 0 0.3em;
}
h5 {
float: left;
color: lighten($body-font-color, 10);
}
}

10
app/assets/stylesheets/sass/_layout.scss

@ -379,3 +379,13 @@ body.organizations-show {
text-align: inherit;
}
}
table {
td {
vertical-align: top;
&.primary {
width: 100%;
}
}
}

50
app/controllers/pages_controller.rb

@ -14,7 +14,13 @@ class PagesController < ApplicationController
def translate
key = params[:translationkey]
value = params[:translationvalue]
if params[:translationhascount] == '1'
if params[:auto_translate]
if params[:translationlang] == 'en'
value = I18n::MissingTranslationExceptionHandler.note(key)
else
value = I18n.backend.request_translation(key, {}, {fallback: true, locale: params[:translationlang]})
end
elsif params[:translationhascount] == '1'
['zero', 'one', 'two', 'few', 'many'].each { |c|
if params['translationpluralization_' + c]
if !value.is_a?(Hash)
@ -34,18 +40,46 @@ class PagesController < ApplicationController
end
store_translations(params[:translationlang], {key => value}, :escape => false)
begin
render json: {success: true, key: key, jkey: key.gsub('.', '--'), translation: I18n.translate!(key, {:raise => false})}
render json: {success: true, key: key, jkey: key.gsub('.', '--'), translation: I18n.translate(key, {:raise => false, :locale => params[:translationlang].to_sym})}
rescue
render json: {error: 'Failed to load translation'}
end
end
def location_territories
#render json: (Carmen:::RegionCollection.new(Carmen::Country.coded(params[:country])) || []).to_json
territories = {}
Carmen::Country.coded(params[:country]).subregions.each { |t| territories[t.code] = t.name }
render json: territories.to_json
end
def location_territories
#render json: (Carmen:::RegionCollection.new(Carmen::Country.coded(params[:country])) || []).to_json
territories = {}
Carmen::Country.coded(params[:country]).subregions.each { |t| territories[t.code] = t.name }
render json: territories.to_json
end
def translations
@lang = params[:lang]
@translations = I18n.backend.get_translation_info
I18n.config.enforce_available_locales = false
end
def translation_list
total = 0
complete = 0
@completeness = Hash.new
translation_info = I18n.backend.get_translation_info()
translation_info.each { |k,v|
#total += 1
#complete += v['languages'].include?(lang.to_s) ? 1 : 0
v['languages'].each { |l|
@completeness[l] ||= 0
@completeness[l] += 1
}
}
#@test = total ? complete / total : 0
@total_translations = translation_info.size()
@language_codes = I18n.backend.get_language_codes().select { |s| s }.sort{ | a1, a2 |
c2 = @completeness.has_key?(a2.to_s) ? @completeness[a2.to_s] : 0
c1 = @completeness.has_key?(a1.to_s) ? @completeness[a1.to_s] : 0
c1 == c2 ? a1 <=> a2 : c2 <=> c1
}
end
private
def store_translations(locale, data, options = {})

202
app/helpers/application_helper.rb

@ -60,98 +60,82 @@ module ApplicationHelper
content_for?(section) ? content_for(section) : default
end
def _lorem_ipsum(method, size)
options = {:random => true}
case method.to_s
when 'c', 'char', 'character', 'characters'
if size
return Forgery::LoremIpsum.characters size, options
end
return Forgery::LoremIpsum.character, options
when 'w', 'word', 'words'
if size
return Forgery::LoremIpsum.words size, options
end
#return'LOREM'
return Forgery::LoremIpsum.word options
when 's', 'sentence', 'sentences'
if size
return Forgery::LoremIpsum.sentences size, options
end
return Forgery::LoremIpsum.sentence options
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
end
return nil
end
def _(key, behavior = nil, behavior_size = nil, vars: {}, html: nil, blockData: {}, &block)
def _(key, behavior = nil, behavior_size = nil, locale: nil, vars: {}, html: nil, blockData: {}, &block)
options = vars
options[:fallback] = true
if behavior
options[:behavior] = behavior
options[:behavior_size] = behavior_size
end
if locale
options[:locale] = locale.to_sym
end
#if vars
# puts "\nVARS:\t#{vars}\n"
#end
I18n.translate(key, options)
queued_keys = nil
result = nil
if key.kind_of?(Hash)
blockData.merge!(key)
key = key.keys
end
if block_given?
@@keyQueue ||= Array.new
if key.kind_of?(Array)
@@keyQueue += key
else
@@keyQueue << key
end
end
if key.kind_of?(Array)
new_key = key.shift
if key.count > 0
queued_keys = key.dup
end
key = new_key
end
if blockData[key]
behavior = blockData[key][:behavior] || nil
behavior_size = blockData[key][:behavior_size] || nil
vars = blockData[key][:vars] || {}
end
@@lastTranslation = nil
generate_control = _can_translate?
translation = _do_translate(key, vars, behavior, behavior_size)
if block_given?
html = capture(&block)
end
if html
translation['html'] = html.gsub('%' + key + '%', translation['untranslated'])
end
if generate_control
@@lastTranslation = translation
@@allTranslations ||= Hash.new
@@allTranslations[key] = key
result = _translate_me(translation)
end
result ||= translation['html'] || translation['untranslated']
if queued_keys
return _ queued_keys, behavior, behavior_size, vars: vars, html: result, blockData: blockData
end
return result
#queued_keys = nil
# #result = nil
#
# #if key.kind_of?(Hash)
# # blockData.merge!(key)
# # key = key.keys
# #end
#
# #if block_given?
# # @@keyQueue ||= Array.new
#
# # if key.kind_of?(Array)
# # @@keyQueue += key
# # else
# # @@keyQueue << key
# # end
# #end
#
# #if key.kind_of?(Array)
# # new_key = key.shift
# # if key.count > 0
# # queued_keys = key.dup
# # end
# # key = new_key
# #end
#
# #if blockData[key]
# # behavior = blockData[key][:behavior] || nil
# # behavior_size = blockData[key][:behavior_size] || nil
# # vars = blockData[key][:vars] || {}
# #end
#
# #@@lastTranslation = nil
# #generate_control = _can_translate?
#
# #puts "\nLLOOCCAALLEE:\t#{locale.to_s}"
# #translation = _do_translate(key, vars, behavior, behavior_size, locale)
#
# #if block_given?
# # html = capture(&block)
# #end
#
# #if html
# # translation['html'] = html.gsub('%' + key + '%', translation['untranslated'])
# #end
#
# #if generate_control
# # @@lastTranslation = translation
# # @@allTranslations ||= Hash.new
# # @@allTranslations[key] = key
#
# # result = _translate_me(translation)
# #end
#
# #result ||= translation['html'] || (behavior.to_s == 'strict' ? nil : translation['untranslated'])
#
# #if queued_keys
# # return _ queued_keys, behavior, behavior_size, vars: vars, html: result, blockData: blockData
# #end
#
#return result
end
def _translate_me(translation)
@ -161,27 +145,39 @@ module ApplicationHelper
('<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('"', '&quot;') + (translation['translated'] ? '" data-translate-translated="' + translation['translated'] : '') + '" data-vars="' + (translation['vars'].length ? translation['vars'].to_json.gsub('"', '&quot;') : '') + '" title="' + ('translate.alt_click') + '">' + (translation['html'] || translation['untranslated']) + '</span>').to_s.html_safe
end
def _do_translate(key, vars, behavior, behavior_size)
def _do_translate(key, vars, behavior, behavior_size, locale)
translation = {'key' => key, 'lang' => '0', 'vars' => vars}
v = vars.dup
#locale ||= I18n.locale
begin
v[:raise] = true
translation['untranslated'] = I18n.translate!(key, v)
translation['lang'] = I18n.locale.to_s
#v[:locale] = locale.to_sym
#v[:fallback] = false
#puts "\nSTART\n"
options = {:raise => true}
if locale
options[:locale] = locale.to_sym
end
#puts "\n#{options.to_json.to_s}\n"
translation['untranslated'] = I18n.translate(key, v, options)
#puts "\nEND\n"
translation['lang'] = locale.to_s
translation['is_translated'] = true
hash = Hash.new
translations = Translation.where(["locale = ? AND key LIKE ?", I18n.locale, key + '%']).take(6).each { |o| hash[o.key] = o.value }
translations = Translation.where(["locale = ? AND key LIKE ?", locale.to_s, key + '%']).take(6).each { |o| hash[o.key] = o.value }
translation['translated'] = hash.to_json.gsub('"', '&quot;')
rescue I18n::MissingTranslationData
begin
translation['untranslated'] = I18n.translate!(config.i18n.default_locale, key, vars)
translation['lang'] = config.i18n.default_locale.to_s
rescue
default_translation = I18n::MissingTranslationExceptionHandler.note(key, behavior, behavior_size)
translation['untranslated'] = default_translation
end
end
#begin
#translation['untranslated'] = I18n.translate!(config.i18n.default_locale, key, vars)
#translation['lang'] = config.i18n.default_locale.to_s
#rescue
#puts "BEHAVIOR:\t#{behavior.to_s}"
default_translation = I18n::MissingTranslationExceptionHandler.note(key, behavior, behavior_size)
translation['untranslated'] = default_translation
#end
end
puts "TRANSLATION:\t#{translation.to_json.to_s}"
return translation
end

22
app/views/pages/translation_list.html.haml

@ -0,0 +1,22 @@
.row
%h1
= _ 'languages.list'
%h2
= _ 'languages.active'
%ul.languages.active.small-block-grid-1.medium-block-grid-3.large-block-grid-4.grid.links
- @language_codes.each do |code|
- if code && @completeness.has_key?(code.to_s)
%li.text-center
%a{:href => "/translations/#{code}/"}
%h3=_"languages.#{code}"
- completeness = @completeness[code.to_s]
- percent = @total_translations ? ((completeness / @total_translations.to_f) * 100).round() : 0
.completeness
= "#{completeness} / #{@total_translations} (#{percent}%)"
%h2= _ 'languages.inactive'
%ul.languages.inactive.small-block-grid-1.medium-block-grid-3.large-block-grid-4.grid.links
- @language_codes.each do |code|
- if code && !@completeness.has_key?(code.to_s)
%li.text-center
%a{:href => "/translations/#{code}/"}
%h3=_"languages.#{code}"

41
app/views/pages/translations.html.haml

@ -0,0 +1,41 @@
.row
%h1
= _ 'language_translations', vars: {:language => (_ ('languages.' + @lang))}
%table.columns#translations
%thead
%tr
%th.key=_'translations.Key'
%th.key=_'translations.Pages'
%th.key=_'translations.Value'
- @translations.sort{| a1, a2 | a1[0].downcase <=> a2[0].downcase}.each do |k,translation|
- current_translation = Translation.locale(@lang.to_sym).lookup(k)#[0].value #_ translation[0], :strict, locale: @lang.to_sym
- current_translation = current_translation.size() > 0 ? current_translation = current_translation[0].value : nil
- cached = (translation['languages'] && translation['languages'].include?(@lang))
- vars = translation.has_key?('vars') && translation['vars'].size() > 0 ? translation['vars'] : nil
- (vars && vars.include?(:count) ? I18n.backend.get_pluralization_rules(@lang) : [nil]).each do |pluralization|
- key = k + (pluralization ? ".#{pluralization.to_s}" : '')
%tr{:class => current_translation ? 'exists' : 'not-exists', :data => {:key => key}}
%td.key
= key
- if vars
.tags
%h5=_'translations.Vars'
%ul
- vars.each do |v|
%li=v
%td.pages
%ul
- translation['pages'].each do |page|
%li
%a{:href => page}=page
%td.value.primary
- if current_translation
= current_translation
- elsif I18n.locale.to_s == @lang.to_s
Nil
- else
- translation_hint = Translation.locale(I18n.locale).lookup(k)
- translation_hint = translation_hint && translation_hint.size() > 0 ? translation_hint = translation_hint[0].value : nil
= translation_hint ? (_ "languages.#{I18n.locale.to_s}") + " = \"#{translation_hint}\"" : 'Nil'
- unless current_translation
%a{:href => '#', :class => 'auto-translate button small'}='Auto'

2
app/views/user_sessions/_form.html.haml

@ -1,4 +1,4 @@
= form_tag user_sessions_path, :method => :post do
= field :email, :email_field
= field :password, :password_field_tag
= actions [:sign_in, :facebook_sign_in]
= actions [:Sign_In, :facebook_sign_in]

3
config/application.rb

@ -1,8 +1,7 @@
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# require 'carmen'
# require 'pry'
#require 'dotenv'; Dotenv.load ".env.local", ".env.#{Rails.env}"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.

90
config/initializers/i18n.rb

@ -41,6 +41,9 @@ module I18n
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('_', ' ')
@ -61,6 +64,7 @@ module I18n
@@translations_file = 'config/locales/.translations.yml'
@@translation_cache_file = 'config/locales/.translation-cache.yml'
@@pluralization_rules_file = 'config/locales/.pluralization-rules.yml'
@@translation_cache
def needs_translation(key)
@ -68,6 +72,13 @@ module I18n
@@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('"', '&quot;') + '"' }
('<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('"', '&quot;') + (translation['translated'] ? '" data-translate-translated="' + translation['translated'] : '') + '" data-vars="' + (translation['vars'].length ? translation['vars'].to_json.gsub('"', '&quot;') : '') + '" title="' + ('translate.alt_click') + '">' + (translation['html'] || translation['untranslated']) + '</span>').to_s.html_safe
end
def initialized?
begin
super
@ -85,47 +96,104 @@ module I18n
super
end
def get_translation_info()
begin
YAML.load_file(@@translations_file) || {}
rescue Exception => e
# sometimes concurrency issues cause an exception during testing
puts e
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 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 : 0
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
protected
def lookup(locale, key, scope = [], options = {})
result = nil
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?
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 = YAML.load_file(@@translations_file)
translations = get_translation_info()
translations ||= Hash.new
translations[key.to_s] ||= Hash.new
translations[key.to_s]['langauges'] ||= Hash.new
if result != nil
translations[key.to_s]['langauges'][locale.to_s] = result
end
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'] << 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]
unless translations[key.to_s]['pages'].include?(path)
translations[key.to_s]['pages'] << 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
if Rails.env.test?
end
result
end
end

23
config/routes.rb

@ -8,18 +8,8 @@ BikeBike::Application.routes.draw do
resources :workshop_facilitators
#resources :conference_registration_responses
#resources :conference_registrations
#resources :conference_registraton_form_fields
resources :registration_form_fields
#resources :conference_admins
#resources :conference_host_organizations
resources :conferences, :param => 'slug' do
get :hosts
get :registration
@ -37,8 +27,6 @@ BikeBike::Application.routes.draw do
post 'registration/form/reorder' => 'conferences#reorder', as: 'registration_reorder'
end
#resources :user_organization_relationships
resources :organizations, :param => 'slug' do
get :members
get :identity
@ -48,8 +36,6 @@ BikeBike::Application.routes.draw do
resources :users
resources :user_sessions
#resources :organization_statuses
resources :conference_types
resources :workshop_streams
@ -60,14 +46,17 @@ BikeBike::Application.routes.draw do
post '/translate/' => 'pages#translate'
post '/location/territories/' => 'pages#location_territories'
get '/translations/:lang', to: 'pages#translations'
get '/translations', to: 'pages#translation_list'
get 'login' => 'user_sessions#new', :as => :login
post 'logout' => 'user_sessions#destroy', :as => :logout
get 'register' => 'users#new', :as => 'register'
post "oauth/callback" => "oauths#callback"
get "oauth/callback" => "oauths#callback"
get "oauth/:provider" => "oauths#oauth", :as => :auth_at_provider
post "oauth/callback" => "oauths#callback"
get "oauth/callback" => "oauths#callback"
get "oauth/:provider" => "oauths#oauth", :as => :auth_at_provider
root 'pages#home'

4
spec/features/pages/login_spec.rb

@ -30,7 +30,7 @@ describe 'Login' do
it "has a login form" do
visit login_path
form = find 'form[action$="/user_sessions"]'
expect(form).to have_button 'sign in'
expect(form).to have_button 'Sign In'
expect(form).to have_field 'email_'
expect(form).to have_field 'password'
expect(form).to have_link 'facebook'
@ -64,7 +64,7 @@ describe 'Login' do
form = find 'form[action$="/user_sessions"]'
form.find("#email_").set(user.email)
form.find("#password").set('secret')
click_button "sign_in"
click_button "Sign_In"
end
end

2
spec/features/pages/organization_registration_spec.rb

@ -9,7 +9,7 @@ describe 'Organization Registration' do
form = find 'form[action$="/user_sessions"]'
form.find("#email_").set(user.email)
form.find("#password").set('secret')
click_button "sign_in"
click_button "Sign_In"
visit new_organization_path
end

22
spec/features/pages/translations_spec.rb

@ -0,0 +1,22 @@
require 'spec_helper'
describe 'Translations' do
describe 'Translate list' do
before(:each) do
visit '/translations'
end
it "does something" do
end
end
describe 'Translate english' do
before(:each) do
visit '/translations/en'
end
it "does something" do
end
end
end

1
spec/spec_helper.rb

@ -3,6 +3,7 @@ ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
#+require 'dotenv'; Dotenv.overload ".env.test"
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.

Loading…
Cancel
Save