Skip to content
Browse files

set up dummy app for testing along with a show view to kick sending.

  • Loading branch information...
1 parent c702eef commit e469d4c8751c93528cd9d0bb42cc9052cf319085 @randym committed Mar 22, 2012
View
4 Gemfile.lock
@@ -45,6 +45,9 @@ GEM
i18n-js (2.1.2)
i18n
journey (1.0.3)
+ jquery-rails (2.0.1)
+ railties (>= 3.2.0, < 5.0)
+ thor (~> 0.14)
json (1.6.5)
localeapp (0.4.2)
gli
@@ -103,5 +106,6 @@ PLATFORMS
ruby
DEPENDENCIES
+ jquery-rails
localeapp-i18n-js!
sqlite3
View
9 app/controllers/localeapp_i18n_js/localeapp_i18n_js_controller.rb
@@ -1,9 +1,13 @@
module LocaleappI18nJs
class LocaleappI18nJsController < ActionController::Base
+ def show
+ render "localeapp_i18n_js/show", :layout => "application"
+ end
+
def update
- Rails.logger.info "[LocaleappI18nJs] update: locale=#{params[:locale]}, key=#{params[:key]}"
- add_missing_translation params[:locale], params[:key]
+ Localeapp.log "[LocaleappI18nJs] update: locale=#{params[:locale]}, key=#{params[:key]}"
+ add_missing_translation params[:locale], params[:key] unless Localeapp.configuration.sending_disabled?
render :json => true
end
@@ -17,3 +21,4 @@ def add_missing_translation(locale, key)
end
end
+
View
8 app/views/localeapp_i18n_js/show.erb
@@ -0,0 +1,8 @@
+<script type="text/javascript">
+$(document).ready(function() {
+ $("#missing_translation").text(I18n.t('.missing_translation'))
+});
+</script>
+Here lies... a missing translation...
+<div id="missing_translation">
+</div>
View
5 config/routes.rb
@@ -1,5 +1,6 @@
Rails.application.routes.draw do
- scope :module => 'LocaleappI18nJs' do
- post "localeapp_i18n_js", :to => 'LocaleappI18nJs#update'
+ scope :module => LocaleappI18nJs do
+ post "localeapp_i18n_js", :to => "LocaleappI18nJs#update"
+ get "localeapp_i18n_js", :to => "LocaleappI18nJs#show"
end
end
View
19 lib/localeapp-i18n-js.rb
@@ -1,20 +1 @@
require 'localeapp-i18n-js/engine'
-module LocaleappI18nJs
-
- extend self
-
- def report_missing_translations?
- ['development'].concat(configured_environments).include?(::Rails.env)
- end
-
- protected
-
- def configured_environments
- cfg = ::Rails.application.config
- return [] unless cfg.respond_to?(:localeapp_i18n_js)
- envs = cfg.localeapp_i18n_js
- raise ArgumentError, "Rails.application.config.localeapp_18n_js must be an array. e.g. ['test', 'custom']. You specified: #{envs}" unless envs.is_a?(Array)
- envs
- end
-
-end
View
5 lib/localeapp-i18n-js/engine.rb
@@ -1,5 +1,8 @@
module LocaleappI18nJs
class Engine < ::Rails::Engine
- isolate_namespace LocaleappI18nJs
+ initializer 'localeapp_i18n_js.setup', :after => "i18n-js.asset_dependencies" do |app|
+ raise "Localeapp does not exist" unless defined?(Localeapp)
+ raise "SimplesIdeias::I18n does not exist" unless defined?(SimplesIdeias::I18n)
+ end
end
end
View
1 localeapp-i18n-js.gemspec
@@ -19,5 +19,6 @@ Gem::Specification.new do |s|
s.add_dependency "i18n-js"
s.add_dependency "localeapp"
s.add_development_dependency "sqlite3"
+ s.add_development_dependency "jquery-rails"
end
View
22 test/controller_test.rb
@@ -1,14 +1,16 @@
require 'test_helper'
+# The contorller should not even be defined unless we are in an environment that
+# is configured to use this. (development by default, other environments specified with config.
+ class LocaleappI18nJs::LocaleappI18nJsControllerTest < ActionController::TestCase
+ test "update" do
+ post :update, :locale =>"en", :key => "test"
+ assert_response :success
+ end
-class LocaleappI18nJs::LocaleappI18nJsControllerTest < ActionController::TestCase
- test "update" do
- post :update, :locale =>"en", :key => "test"
- assert_response :success
- end
+ test "show" do
+ get :show
+ assert_response :success
+ end
- test "get is dead" do
- assert_raise(AbstractController::ActionNotFound) { get :index }
- assert_raise(AbstractController::ActionNotFound) { get :show }
- end
-end
+ end
View
7 test/dummy/Gemfile
@@ -1,5 +1,4 @@
source :rubygems
-
-group :development, :test do
- gem "localeapp", '~> 0.4.1'
-end
+gem "jquery-rails"
+gem "i18n-js"
+gem "localeapp", '~> 0.4.1'
View
73 test/dummy/Gemfile.lock
@@ -0,0 +1,73 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ actionpack (3.2.2)
+ activemodel (= 3.2.2)
+ activesupport (= 3.2.2)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ journey (~> 1.0.1)
+ rack (~> 1.4.0)
+ rack-cache (~> 1.1)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.1.2)
+ activemodel (3.2.2)
+ activesupport (= 3.2.2)
+ builder (~> 3.0.0)
+ activesupport (3.2.2)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ builder (3.0.0)
+ erubis (2.7.0)
+ gli (1.5.1)
+ hike (1.2.1)
+ i18n (0.6.0)
+ i18n-js (2.1.2)
+ i18n
+ journey (1.0.3)
+ jquery-rails (2.0.1)
+ railties (>= 3.2.0, < 5.0)
+ thor (~> 0.14)
+ json (1.6.5)
+ localeapp (0.4.2)
+ gli
+ i18n
+ json
+ rest-client
+ ya2yaml
+ mime-types (1.18)
+ multi_json (1.1.0)
+ rack (1.4.1)
+ rack-cache (1.2)
+ rack (>= 0.4)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ railties (3.2.2)
+ actionpack (= 3.2.2)
+ activesupport (= 3.2.2)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ rest-client (1.6.7)
+ mime-types (>= 1.16)
+ sprockets (2.1.2)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ thor (0.14.6)
+ tilt (1.3.3)
+ ya2yaml (0.31)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ i18n-js
+ jquery-rails
+ localeapp (~> 0.4.1)
View
4 test/dummy/app/assets/javascripts/application.js
@@ -10,6 +10,10 @@
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
+
//= require jquery
//= require jquery_ujs
//= require_tree .
+//= require i18n
+//= require i18n/translations
+//= require localeapp-i18n-js
View
8 test/dummy/config/application.rb
@@ -3,6 +3,8 @@
require 'rails/all'
Bundler.require
+require 'jquery-rails'
+require 'i18n-js'
require 'localeapp'
require "localeapp-i18n-js"
@@ -27,8 +29,8 @@ class Application < Rails::Application
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
- # config.i18n.default_locale = :de
+ config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
+ config.i18n.default_locale = :de
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
@@ -49,6 +51,8 @@ class Application < Rails::Application
# Enable the asset pipeline
config.assets.enabled = true
+ config.assets.version = '1.0sc'
+ config.serve_static_assets = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
View
22 test/dummy/config/i18n-js.yml
@@ -0,0 +1,22 @@
+# Split context in several files.
+# By default only one file with all translations is exported and
+# no configuration is required. Your settings for asset pipeline
+# are automatically recognized.
+#
+# If you want to split translations into several files or specify
+# locale contexts that will be exported, just use this file to do
+# so.
+#
+# If you're going to use the Rails 3.1 asset pipeline, change
+# the following configuration to something like this:
+#
+# translations:
+# - file: "app/assets/javascripts/i18n/translations.js"
+#
+# If you're running an old version, you can use something
+# like this:
+#
+# translations:
+# - file: "public/javascripts/translations.js"
+# only: "*"
+#
View
1 test/dummy/config/initializers/localeapp.rb
@@ -2,4 +2,5 @@
Localeapp.configure do |config|
config.api_key = "FkwhnLq9XzGfuz2yJec4NVeQ1MQlfR4YHBK0wFlbOzOhzUfB0v"
+ config.sending_environments = ['test', 'development']
end
View
198 test/dummy/config/locales/en-US.yml
@@ -0,0 +1,198 @@
+en-US:
+ date:
+ abbr_day_names:
+ - Sun
+ - Mon
+ - Tue
+ - Wed
+ - Thu
+ - Fri
+ - Sat
+ abbr_month_names:
+ - !!null
+ - Jan
+ - Feb
+ - Mar
+ - Apr
+ - May
+ - Jun
+ - Jul
+ - Aug
+ - Sep
+ - Oct
+ - Nov
+ - Dec
+ day_names:
+ - Sunday
+ - Monday
+ - Tuesday
+ - Wednesday
+ - Thursday
+ - Friday
+ - Saturday
+ formats:
+ default: ! '%Y-%m-%d'
+ long: ! '%B %d, %Y'
+ short: ! '%b %d'
+ month_names:
+ - !!null
+ - January
+ - February
+ - March
+ - April
+ - May
+ - June
+ - July
+ - August
+ - September
+ - October
+ - November
+ - December
+ order:
+ - :year
+ - :month
+ - :day
+ datetime:
+ distance_in_words:
+ about_x_hours:
+ one: about 1 hour
+ other: about %{count} hours
+ about_x_months:
+ one: about 1 month
+ other: about %{count} months
+ about_x_years:
+ one: about 1 year
+ other: about %{count} years
+ almost_x_years:
+ one: almost 1 year
+ other: almost %{count} years
+ half_a_minute: half a minute
+ less_than_x_minutes:
+ one: less than a minute
+ other: less than %{count} minutes
+ less_than_x_seconds:
+ one: less than 1 second
+ other: less than %{count} seconds
+ over_x_years:
+ one: over 1 year
+ other: over %{count} years
+ x_days:
+ one: 1 day
+ other: ! '%{count} days'
+ x_minutes:
+ one: 1 minute
+ other: ! '%{count} minutes'
+ x_months:
+ one: 1 month
+ other: ! '%{count} months'
+ x_seconds:
+ one: 1 second
+ other: ! '%{count} seconds'
+ prompts:
+ day: Day
+ hour: Hour
+ minute: Minute
+ month: Month
+ second: Seconds
+ year: Year
+ errors:
+ format: ! '%{attribute} %{message}'
+ messages:
+ accepted: must be accepted
+ blank: can't be blank
+ confirmation: doesn't match confirmation
+ empty: can't be empty
+ equal_to: must be equal to %{count}
+ even: must be even
+ exclusion: is reserved
+ greater_than: must be greater than %{count}
+ greater_than_or_equal_to: must be greater than or equal to %{count}
+ inclusion: is not included in the list
+ invalid: is invalid
+ less_than: must be less than %{count}
+ less_than_or_equal_to: must be less than or equal to %{count}
+ not_an_integer: must be an integer
+ not_a_number: is not a number
+ odd: must be odd
+ record_invalid: ! 'Validation failed: %{errors}'
+ taken: has already been taken
+ too_long:
+ one: is too long (maximum is 1 character)
+ other: is too long (maximum is %{count} characters)
+ too_short:
+ one: is too short (minimum is 1 character)
+ other: is too short (minimum is %{count} characters)
+ wrong_length:
+ one: is the wrong length (should be 1 character)
+ other: is the wrong length (should be %{count} characters)
+ template:
+ body: ! 'There were problems with the following fields:'
+ header:
+ one: 1 error prohibited this %{model} from being saved
+ other: ! '%{count} errors prohibited this %{model} from being saved'
+ helpers:
+ select:
+ prompt: Please select
+ submit:
+ create: Create %{model}
+ submit: Save %{model}
+ update: Update %{model}
+ number:
+ currency:
+ format:
+ delimiter: ! ','
+ format: ! '%u%n'
+ precision: 2
+ separator: .
+ significant: false
+ strip_insignificant_zeros: false
+ unit: $
+ format:
+ delimiter: ! ','
+ precision: 3
+ separator: .
+ significant: false
+ strip_insignificant_zeros: false
+ human:
+ decimal_units:
+ format: ! '%n %u'
+ units:
+ billion: Billion
+ million: Million
+ quadrillion: Quadrillion
+ thousand: Thousand
+ trillion: Trillion
+ unit: ''
+ format:
+ delimiter: ''
+ precision: 3
+ significant: true
+ strip_insignificant_zeros: true
+ storage_units:
+ format: ! '%n %u'
+ units:
+ byte:
+ one: Byte
+ other: Bytes
+ gb: GB
+ kb: KB
+ mb: MB
+ tb: TB
+ percentage:
+ format:
+ delimiter: ''
+ precision:
+ format:
+ delimiter: ''
+ support:
+ array:
+ last_word_connector: ! ', and '
+ two_words_connector: ! ' and '
+ words_connector: ! ', '
+ time:
+ am: am
+ formats:
+ default: ! '%a, %d %b %Y %H:%M:%S %z'
+ long: ! '%B %d, %Y %H:%M'
+ short: ! '%d %b %H:%M'
+ pm: pm
View
19 test/lib/localeapp_i18n_js_test.rb
@@ -5,23 +5,4 @@ class LocaleappI18nJsTest < ActiveSupport::TestCase
assert_kind_of Module, LocaleappI18nJs
end
- test "should not run in test environment by default" do
- assert_equal(LocaleappI18nJs.report_missing_translations?, false)
- end
-
- test "should report in development" do
- Rails.env = 'development'
- assert_equal(LocaleappI18nJs.report_missing_translations?, true)
- end
-
- test "should report in configured environments" do
- Rails.application.config.localeapp_i18n_js = ['test']
- assert_equal(LocaleappI18nJs.report_missing_translations?, true)
- end
-
- test "should raise an error if application configurate is not an array" do
- Rails.application.config.localeapp_i18n_js = 'test'
- assert_raise(ArgumentError) { LocaleappI18nJs.report_missing_translations? }
- end
-
end
View
17 test/routes_test.rb
@@ -2,15 +2,20 @@
class RoutesTest < ActionController::TestCase
include Rails.application.routes.url_helpers
+ puts LocaleappI18nJs::Engine.routes.routes.inspect
+ test 'localeapp_i18n_js update is set' do
+ assert_generates "localeapp_i18n_js", {
+ :controller => "LocaleappI18nJs",
+ :action => "update"}
+ end
- test 'localeapp_i18n_js route is set' do
-
+ test 'localeapp_i18n_js show is set' do
assert_generates "/localeapp_i18n_js", {
- :controller => "LocaleappI18nJs/LocaleappI18nJs",
- :action => "update"}
+ :controller => "LocaleappI18nJs",
+ :action => "show"}
+ end
# TODO what gives? The route is clearly shown, and the controller post works - so why does this fail?
- #assert_routing({:path => "localeapp_i18n_js", :method => :post }, { :controller => "LocaleappI18nJs/LocaleappI18nJs", :action => "update"})
+ # assert_routing({:path => "localeapp_i18n_js", :method => :post }, { :controller => "LocaleappI18nJs/LocaleappI18nJs", :action => "update"})
- end
end
View
2 test/test_helper.rb
@@ -2,9 +2,9 @@
ENV["RAILS_ENV"] = "test"
require File.expand_path("../dummy/config/environment.rb", __FILE__)
+
require "rails/test_help"
Rails.backtrace_cleaner.remove_silencers!
-
# Load support files
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
View
10 vendor/assets/javascripts/localeapp-i18n-js.js.erb
@@ -1,25 +1,24 @@
var I18n = I18n || {};
-I18n.report_missing_translations = <%= LocaleappI18nJs.report_missing_translations? %>
+I18n.report_missing_translations = <%= !Localeapp.configuration.sending_disabled? %>
//override the default I18n-js missingTranslation method to post back missing translations
+if (I18n.report_missing_translations) {
I18n.missingTranslation = function() {
var path = [], count = arguments.length
for (var i = 0; i < count; i++) {
path.push(arguments[i]);
}
path = path.join('.')
- if(this.report_missing_translations) {
- this.add_missing_translation(this.currentLocale(), path);
- }
+ this.add_missing_translation(this.currentLocale(), path);
return '[missing "' + this.currentLocale() + path + '" translation]';
};
I18n.add_missing_translation = function add_missing_translation(locale, key) {
$.ajax({
- url: "/localeapp_i18n_js",
+ url: "localeapp_i18n_js",
type: 'POST',
dataType: 'json',
data: {locale: locale, key: key},
@@ -28,3 +27,4 @@ I18n.add_missing_translation = function add_missing_translation(locale, key) {
}
});
}
+}

0 comments on commit e469d4c

Please sign in to comment.
Something went wrong with that request. Please try again.