Skip to content

Commit

Permalink
made everything work
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed May 1, 2009
1 parent 411054f commit a45d1ac
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 13 deletions.
35 changes: 27 additions & 8 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
A interface for translation editing as rails engine.
A interface for translation editing as rails engine.
Very alpha/hacky atm, but already used runs in production ;D

### Configure fast_gettext
See fast_gettext/README, use the default models or rename your model to TranslationKey.
Setup
=====
`script/plugin install git://github.com/grosser/translation_db.git `

### If you do not have translation models yet
./script/generate migration create_translation_keys_and_translation_texts
#insert migration from fast_gettext/examples
###Default
- Setup FastGettext to run from database and include the db_models, see [FastGettext Readme](http://github.com/grosser/fast_gettext)
- Run migrations from fast_gettext/examples/migration
- Add initial translations through import or create them through the script/console (you NEED a translation for every locale so that `available_locales` is populated and edit fields are shown correctly)
- Start translating!

visit /translation_keys to get started.
### Personalized
- Setup whichever I18n framework supports a database
- Create a `TranslationKey` model that `has_many :translations`, `available_locales` and `accepts_nested_attributes_for :translations`
- Make available locales return the locales you need
- Start translating!

All it needs are [fast_gettext](http://github.com/grosser/fast_gettext) and the models TranslationKey and TranslationText, which are both provided via fast-gettext.
Visit `/translation_keys` in your browser.

TODO
====
- authentification (atm i just added http basic auth in my local checkout...)
- layout/title/styles/js/search

Author
======
[Michael Grosser](http://pragmatig.wordpress.com)
grosser.michael@gmail.com
Hereby placed under public domain, do what you want, just do not hold me accountable...
46 changes: 46 additions & 0 deletions app/controllers/translation_keys_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,51 @@
class TranslationKeysController < ActionController::Base
before_filter :find_translation_key, :only=>%w[show edit update]

def index
@translation_keys = TranslationKey.find(:all)
end

def new
@translation_key = TranslationKey.new
add_default_locales_to_translation
render :action=>:edit
end

def create
@translation_key = TranslationKey.new(params[:translation_key])
if @translation_key.save
redirect_to translation_key_path(@translation_key)
else
render :action=>:edit
end
end

def show
render :action=>:edit
end

def edit
end

def update
if @translation_key.update_attributes(params[:translation_key])
flash[:notice] = 'Succesfully saved!'
redirect_to @translation_key
else
flash[:error] = 'Failed to save!'
render :action=>:edit
end
end

protected

def find_translation_key
@translation_key = TranslationKey.find(params[:id])
end

def add_default_locales_to_translation
TranslationKey.available_locales.each do |locale|
@translation_key.translations.build(:locale=>locale)
end
end
end
17 changes: 17 additions & 0 deletions app/views/translation_keys/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<% new = @translation_key.new_record? %>
<h1><%= @translation_key.key || "New translation" %></h1>
<% form_for @translation_key do |f|%>
<p>
<%= f.label :key %>
<%= f.text_area :key, :size=>'80x4' %>
</p>

<% f.fields_for :translations do |tf|%>
<p>
<%= tf.label :text, tf.object.locale %>
<%= tf.text_area :text, :size=>'80x4' %>
</p>
<% end %>
<%= f.submit(new ? "Create" : "Save") %>
<% end %>
26 changes: 25 additions & 1 deletion app/views/translation_keys/index.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
HELLO
<% locales = TranslationKey.available_locales %>
<%= link_to "New", new_translation_key_url %>

<table>
<thead>
<tr>
<td>Key</td>
<% locales.each do |locale| %>
<td><%= locale%></td>
<% end %>
</tr>
</thead>
<tbody>
<% @translation_keys.each do |key| %>
<tr>
<td><%= key.key %></td>
<% translations = key.translations.map{|t| [t.locale, t]} %>
<% locales.each do |locale| %>
<td><%= translations.assoc(locale)[1].text if translations.assoc(locale) %></td>
<% end %>
<td><%= link_to "Edit", key %></td>
</tr>
<% end %>
</tbody>
</table>
4 changes: 1 addition & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
ActionController::Routing::Routes.draw do |map|
map.resources :translation_keys
end

raise "sdsd"
end
1 change: 0 additions & 1 deletion init.rb

This file was deleted.

0 comments on commit a45d1ac

Please sign in to comment.