Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ui tweaks for translation, validation for blanks

  • Loading branch information...
commit 1ac61f89479c674469453ec4f8380989bdf3c063 1 parent a327756
Alexander Mekelburg authored
View
1  .env.ENVNAME.example
@@ -1,3 +1,2 @@
AIRBRAKE_API_KEY: 'Airbrake API Key'
-COOKIE_SECRET: 'Cookie verification secret'
SECRET_TOKEN: 'Session store token'
View
72 app/assets/stylesheets/state_configuration.css.scss
@@ -6,7 +6,7 @@
padding:10px;
font-size: 13px;
line-height: 1.25em;
-
+ padding-bottom:75px;
form ul {
zoom: 1;
margin: 0;
@@ -43,12 +43,25 @@
}
}
- ul.translation_instructions {
- padding:0;
- li {
- border:0;
- list-style: disc inside none;
- display:list-item;
+ .translation_instructions {
+ font-size: 110%;
+ padding:10px;
+ margin-top:10px;
+ background:#fDD;
+ width:800px;
+
+ h3 {
+ font-weight:bold;
+ }
+ ul {
+ padding:0;
+ margin:0;
+ font-weight: bold;
+ li {
+ border:0;
+ list-style: disc inside none;
+ display:list-item;
+ }
}
}
@@ -64,6 +77,9 @@
padding-left:5px;
ul {
margin-left:20px;
+ &.locales {
+ margin-left:0;
+ }
}
.method {
font-weight: bold;
@@ -71,15 +87,25 @@
.values {
display: none;
}
+ &.translation_key_part_list {
+ border:0;
+ border-left:1px solid #aaa;
+ .translation_key_part {
+ font-weight:bold;
+ }
+ }
&.locale {
- float: left;
margin-top:5px;
padding:5px;
- width:400px;
- border: 1px solid #ccc;
+ width:800px;
+ border: 0;
+ margin-bottom:10px;
+ h4.locale_name {
+ margin-bottom:5px;
+ }
.translation {
textarea {
- width:290px;
+ width:750px;
height:4em;
}
.substitution {
@@ -96,16 +122,34 @@
}
}
+ &.translatable {
+ background: #ccf;
+ }
+ &.blank {
+ background: #f66;
+ span.error_message {
+ font-weight:bold;
+ margin:8px 10px;
+ font-size:110%;
+ display:block;
+ }
+ }
}
}
#submission {
padding:25px;
- border:1px solid #aaa;
- background: #ccc;
+ background: #ccf;
position: fixed;
- top:0;
+ bottom:0;
right:0;
+ left:0;
+ input {
+ padding:15px 10px;
+ background-color:#fff;
+ font-size:110%;
+ font-weight:bold;
+ }
}
}
View
20 app/controllers/translations_controller.rb
@@ -2,19 +2,21 @@ class TranslationsController < ApplicationController
layout 'state_configuration'
before_filter :get_translations
+ before_filter :get_locale_and_translation, :except=>:index
def index
end
def show
- @locale = params[:locale]
- @translation = Translation.find(params[:id])
end
def submit
- @translation = Translation.find(params[:id])
file = @translation.generate_yml(params[:locale], params[params[:locale]])
- send_data file, :filename=>"#{params[:id]}-#{params[:locale]}.yml", :type=>"text"
+ if @translation.blanks.size > 0
+ render :action=>:show
+ else
+ submit_data(file, params[:id], params[:locale])
+ end
end
private
@@ -22,4 +24,14 @@ def get_translations
@types = Translation.types
end
+ def get_locale_and_translation
+ @locale = params[:locale]
+ @translation = Translation.find(params[:id])
+ end
+
+ def submit_data(file, group_name, locale)
+ # later this will be 'email'
+ send_data file, :filename=>"#{group_name}-#{locale}.yml", :type=>"text"
+ end
+
end
View
4 app/views/layouts/state_configuration.html.erb
@@ -16,14 +16,10 @@
</head>
<body>
<div id="container">
- <div id="header">
- </div>
<div id="config_ui">
<%= flash_messages.html_safe %>
<%= yield %>
</div>
- <div id="footer">
- </div>
</div>
<!-- port: <%= request.port %> | process: <%= $$ %> | <%= Time.now.to_s(:db) %> -->
</body>
View
29 app/views/translations/_key_value.html.haml
@@ -2,19 +2,23 @@
- value.each do |k,v|
- unless k =~ /_translation_instructions$/
%ul
- %li
- %span.translation_key_part{:class=>v.is_a?(Hash) ? 'collapsable' : ''}= k
+ %li.translation_key_part_list
+ %span.translation_key_part= k
= render :partial=>'key_value', :locals=>{:key=>"#{key}.#{k}", :value=>v, :id_ct=>id_ct + 1}
- else
%br
%span.translation_key= key
- %ul.translation_instructions
- - Translation.instructions_for(key).each do |inst|
- %li=inst
+ - instructions = Translation.instructions_for(key)
+ - if instructions.size > 0
+ .translation_instructions
+ %h3= "Instructions for Translator: "
+ %ul
+ - instructions.each do |inst|
+ %li=inst
- %ul
+ %ul.locales
%li.locale
- %h4.locale_name en
+ %h4.locale_name English:
.translation
- if value.is_a?(Array)
%ul
@@ -22,14 +26,17 @@
%li= v
- else
= I18n.t(key, :locale=>'en', :default=>'')
- %li.locale
- %h4.locale_name= @locale
+ %li.locale.translatable{:class=>@translation.is_blank?(key) ? 'blank' : ''}
+ %h4.locale_name= "#{Translation.language_name(@locale)}:"
.translation
+ - if @translation.is_blank?(key)
+ %span.error_message ** You must provide a translation **
- if value.is_a?(Array)
%ul
- - I18n.t(key, :locale=>@locale, :default=>'').each do |v|
+ - @translation.get_from_contents(key, @locale).each do |v|
+ -# I18n.t(key, :locale=>@locale, :default=>'').each do |v|
%li
%input{:type=>'text', :name=>"#{@locale}[#{key}][]", :value=>v}
- else
%textarea{:name=>"#{@locale}[#{key}]"}
- = I18n.t(key, :locale=>@locale, :default=>'')
+ = @translation.get_from_contents(key, @locale)
View
2  app/views/translations/show.html.haml
@@ -4,7 +4,7 @@
%h2= "Translate '#{@translation.name}' in #{Translation.language_name(@locale)}"
= form_tag submit_translation_path(:locale=>@locale) do
#submission
- = submit_tag 'Submit'
+ = submit_tag 'Save and Email Translations'
.languages
- @translation.contents['en'].each do |k,v|
%ul= render :partial=>'key_value', :locals=>{:key=>k, :value=>v, :id_ct=>1}
View
1  config/initializers/cookie_verification_secret.rb
@@ -1 +0,0 @@
-Rails.application.config.cookie_secret = ENV['COOKIE_SECRET']
View
27 config/locales/email/es.yml
@@ -1,13 +1,14 @@
-email:
- confirmation:
- subject: "Reminder: Mail your voter registration form"
- reminder:
- subject: "Reminder: Mail your voter registration form"
- thank_you_external:
- subject: "Gracias por usar el instrumento de registración de votantes en línea"
- tell_friend:
- subject: "I just registered to vote and you should too"
- body: "Hey, I just registered to vote at %{rtv_url} and you can too. It is really easy.\n\nJust fill out the online form here: %{rtv_url}. You can't vote if you're not registered. Whether you need to register to vote for the first time or just need to update your address or change your name, it only takes a few minutes. To learn more, go to: %{rtv_url}.\n\nAlready registered to vote? You can help get others registered to vote. Send an email to your friends and family asking them to register to vote at %{rtv_url}.\n\nHappy voting!"
- tell_friend_under_18:
- subject: "Register to vote!"
- body: "Are you registered to vote? I may not be old enough to vote yet, but you are. You can't vote unless you are registered.\n\nYou can fill out a voter registration form only at %{rtv_url}. It is super easy. Whether you need to register to vote for the first time or just need to update your address or change your name, it only takes a few minutes. Go to %{rtv_url}.\n\nAlready registered to vote or not old enough to vote yet? Help others get registered to vote by sending an email to your friends and family asking them to register at %{rtv_url}.\n\nHappy voting!"
+es:
+ email:
+ confirmation:
+ subject: "Reminder: Mail your voter registration form"
+ reminder:
+ subject: "Reminder: Mail your voter registration form"
+ thank_you_external:
+ subject: "Gracias por usar el instrumento de registración de votantes en línea"
+ tell_friend:
+ subject: "I just registered to vote and you should too"
+ body: "Hey, I just registered to vote at %{rtv_url} and you can too. It is really easy.\n\nJust fill out the online form here: %{rtv_url}. You can't vote if you're not registered. Whether you need to register to vote for the first time or just need to update your address or change your name, it only takes a few minutes. To learn more, go to: %{rtv_url}.\n\nAlready registered to vote? You can help get others registered to vote. Send an email to your friends and family asking them to register to vote at %{rtv_url}.\n\nHappy voting!"
+ tell_friend_under_18:
+ subject: "Register to vote!"
+ body: "Are you registered to vote? I may not be old enough to vote yet, but you are. You can't vote unless you are registered.\n\nYou can fill out a voter registration form only at %{rtv_url}. It is super easy. Whether you need to register to vote for the first time or just need to update your address or change your name, it only takes a few minutes. Go to %{rtv_url}.\n\nAlready registered to vote or not old enough to vote yet? Help others get registered to vote by sending an email to your friends and family asking them to register at %{rtv_url}.\n\nHappy voting!"
View
21 lib/translation.rb
@@ -70,11 +70,13 @@ def self.language_name(locale)
attr_reader :directory
attr_reader :type
+ attr_reader :blanks
def initialize(type)
raise "Not Found" if !self.class.type_names.include?(type)
@type = type
@directory = self.class.directory(type)
+ @blanks = []
end
def name
@@ -106,6 +108,22 @@ def contents
@contents
end
+ def get_from_contents(key, locale, group=nil)
+ hash_keys = key.split('.')
+ group ||= contents[locale]
+ if hash_keys.size == 1
+ return group[hash_keys.first]
+ else
+ group = group[hash_keys.shift]
+
+ get_from_contents(hash_keys.join('.'), locale, group)
+ end
+ end
+
+ def is_blank?(key)
+ blanks.include?(key)
+ end
+
def generate_yml(locale, key_values)
full_hash = {locale=>{}}
key_values.each do |k,v|
@@ -114,12 +132,15 @@ def generate_yml(locale, key_values)
key_chain.each_with_index do |key, i|
if (i+1 == key_chain.size)
last_hash[key] = v
+ blanks << k if v.blank?
else
last_hash[key] ||= {}
last_hash = last_hash[key]
end
end
end
+ contents #load it
+ @contents[locale] = full_hash[locale]
full_hash.to_yaml
end
Please sign in to comment.
Something went wrong with that request. Please try again.