Skip to content
Browse files

Fixed issue 4 reported David Calavera. When prototype.js was not in t…

…he javascript default sources translate wouldn't work. We now check for the presence of prototype.js in the Rails app and load it from Google if it's not there
  • Loading branch information...
1 parent 41fcc03 commit c8f46ff7aee90218d7df95e27766ec1a40dbe5ff Peter Marklund committed Jan 26, 2010
Showing with 15 additions and 3 deletions.
  1. +13 −0 lib/translate_helper.rb
  2. +2 −3 views/layouts/translate.rhtml
View
13 lib/translate_helper.rb
@@ -29,4 +29,17 @@ def n_lines(text, line_size)
end
n_lines
end
+
+ def translate_javascript_includes
+ sources = []
+ if File.exists?(File.join(Rails.root, "public", "javascripts", "prototype.js"))
+ sources << "/javascripts/prototype.js"
+ else
+ sources << "http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"
+ end
+ sources << "http://www.google.com/jsapi"
+ sources.map do |src|
+ %Q{<script src="#{src}" type="text/javascript"></script>}
+ end.join("\n")
+ end
end
View
5 views/layouts/translate.rhtml
@@ -3,10 +3,9 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
- <%= javascript_include_tag :defaults %>
<title><%= h(@page_title) %></title>
-
-<script type="text/javascript" src="http://www.google.com/jsapi"></script>
+
+ <%= translate_javascript_includes %>
<script type="text/javascript">
google.load("language", "1");

0 comments on commit c8f46ff

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