-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
116 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |