Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of git://github.com/tokumine/tolk

Conflicts:
	app/models/tolk/locale.rb
  • Loading branch information...
commit efab25a2792d3328ed46f4077fa372aced2be77a 2 parents 39a6b45 + 4f7da04
@cover authored
View
4 README
@@ -1,5 +1,9 @@
Tolk is a Rails engine designed to facilitate the translators doing the dirty work of translating your application to other languages.
+* This Fork
+
+Adds auto translations on click via google translate. video is available here: http://www.tokumine.com/2010/07/18/using-tolk-with-google-translate/
+
* Installation & Setup
To install :
View
10 app/models/tolk/locale.rb
@@ -25,7 +25,7 @@ class Locale < ActiveRecord::Base
'id' => 'Indonesian',
'is' => 'Icelandic',
'it' => 'Italian',
- 'jp' => 'Japanese',
+ 'ja' => 'Japanese',
'ko' => 'Korean',
'lo' => 'Lao',
'lt' => 'Lithuanian',
@@ -34,8 +34,8 @@ class Locale < ActiveRecord::Base
'nl' => 'Dutch',
'no' => 'Norwegian',
'pl' => 'Polish',
- 'pt-BR' => 'Portuguese (Brazilian)',
- 'pt-PT' => 'Portuguese (Portugal)',
+ 'pt-br' => 'Portuguese (Brazilian)',
+ 'pt-pt' => 'Portuguese (Portugal)',
'ro' => 'Romanian',
'ru' => 'Russian',
'se' => 'Swedish',
@@ -47,8 +47,8 @@ class Locale < ActiveRecord::Base
'tr' => 'Turkish',
'uk' => 'Ukrainian',
'vi' => 'Vietnamese',
- 'zh-CN' => 'Chinese (Simplified)',
- 'zh-TW' => 'Chinese (Traditional)'
+ 'zh-cn' => 'Chinese (Simplified)',
+ 'zh-tw' => 'Chinese (Traditional)'
}
has_many :phrases, :through => :translations, :class_name => 'Tolk::Phrase'
View
7 app/views/layouts/tolk/application.html.erb
@@ -5,11 +5,13 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Tolk</title>
+
+ <script src="http://www.google.com/jsapi" type="text/javascript"></script>
<% if respond_to?(:sprockets_include_tag) %>
<%= sprockets_include_tag %>
<% else %>
- <%= javascript_include_tag :defaults %>
+ <%= javascript_include_tag :defaults, '/tolk/application' %>
<% end %>
<%= stylesheet_link_tag "/tolk/reset", "/tolk/screen" %>
@@ -21,12 +23,13 @@
<div id="head">
<h1><span class="home"><%= link_to "Tolk", tolk_root_path %></span><%= yield :locale %></h1>
</div>
+ <span id ="target_language" style="display:none;"><%= @locale.name if @locale %></span>
<%= yield %>
</div>
<script type="text/javascript">
$$('td textarea').each(function(element) {
- element.setStyle({height: element.up('td').measure('height')+'px'});
+ element.setStyle({height: element.up('td').getDimensions().height +'px'});
});
</script>
</body>
View
14 app/views/tolk/locales/show.html.erb
@@ -28,17 +28,19 @@
<tr>
<% translation = Tolk::Translation.new(:locale => @locale, :phrase => phrase) %>
<td class="translation">
- <%= hidden_field_tag :"translations[][id]", translation.id, :id => "#{translation.object_id}_id" %>
+ <%= hidden_field_tag :"translations[][id]", translation.id, :id => "#{translation.object_id}_id" unless translation.id.blank? %>
<%= hidden_field_tag :"translations[][phrase_id]", phrase.id, :id => "#{translation.object_id}_phrase_id" %>
<%= hidden_field_tag :"translations[][locale_id]", translation.locale_id, :id => "#{translation.object_id}_locale_id" %>
<%= text_area_tag :"translations[][text]", format_i18n_text_area_value(translation.text), :class => "locale", :id => "#{translation.object_id}_text", :onfocus => "$(this).up('tr').addClassName('active');", :onblur => "$(this).up('tr').removeClassName('active');" %>
</td>
<td class="phrase">
- <% if params[:q].present? -%>
- <%= highlight(format_i18n_value(phrase.translations.primary.text), params[:q]) -%>
- <% else -%>
- <%= format_i18n_value(phrase.translations.primary.text) -%>
- <% end -%>
+ <span class="to_translate">
+ <% if params[:q].present? -%>
+ <%= highlight(format_i18n_value(phrase.translations.primary.text), params[:q]) -%>
+ <% else -%>
+ <%= format_i18n_value(phrase.translations.primary.text) -%>
+ <% end -%>
+ </span>
<span class="key" title="<%= phrase.key %>"><%= truncate(phrase.key, :length => 100) %></span>
</td>
</tr>
View
9 db/migrate/20101123233022_add_key_index_on_tolk_phrases.rb
@@ -0,0 +1,9 @@
+class AddKeyIndexOnTolkPhrases < ActiveRecord::Migration
+ def self.up
+ add_index :tolk_phrases, :key, :unique => true
+ end
+
+ def self.down
+ remove_index :tolk_phrases, :key
+ end
+end
View
23 public/tolk/application.js
@@ -0,0 +1,23 @@
+google.load("language", "1");
+
+Event.observe(window, 'load', function() {
+
+ // Translate the phrase when the translator clicks on the text area
+ // only fires if textarea is blank
+ $$('textarea').invoke('observe', 'click', function(event) {
+ var phrase = this.up('tr').down('span.to_translate');
+ var textarea = this;
+ var target_language = $('target_language').innerHTML;
+
+ if (phrase && textarea && $F(textarea).blank()){
+ //translate it using google translate, autodetect source language
+ var to_trans = phrase.innerHTML;
+ google.language.translate(to_trans, "", target_language, function(result) {
+ if (!result.error) {
+ textarea.setValue(result.translation);
+ textarea.select();
+ }
+ });
+ }
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.