Skip to content

Commit

Permalink
main functionality done
Browse files Browse the repository at this point in the history
  • Loading branch information
hubertlepicki committed Oct 7, 2010
1 parent 2613148 commit a585ac8
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 130 deletions.
Expand Up @@ -4,5 +4,14 @@ def edit
@keys = GoTranslateYourself.current_store.keys_without_prefix
@locales = GoTranslateYourself.locales
end

def update
if params[:translations] && !params[:translations].empty?
params[:translations].each do |key, value|
GoTranslateYourself.current_store[key] = value
end
end
redirect_to site_translations_path
end
end
end
1 change: 1 addition & 0 deletions app/modles/go_translate_yourself/base_store.rb
Expand Up @@ -14,6 +14,7 @@ def keys
end

def default_translation(key)
load_dev_translations unless @dev_translations
@dev_translations[key.to_s.gsub(/^[a-z]*\./, "")]
end

Expand Down
18 changes: 16 additions & 2 deletions app/views/go_translate_yourself/site_translations/edit.html.erb
@@ -1,3 +1,17 @@
<% @keys.each do |key| %>
<%= key %>
<%= form_tag update_site_translations_path, :method => :post do %>
<table>
<% @keys.each do |key| %>
<tr>
<td>
<%= key %>
</td>
<% @locales.each do |locale| %>
<td>
<%= text_field_tag "translations[#{locale}.#{key}]", GoTranslateYourself.current_store["#{locale}.#{key}"] %>
</td>
<% end %>
</tr>
<% end %>
</table>
<%= submit_tag "Save" %>
<% end %>
3 changes: 2 additions & 1 deletion config/routes.rb
@@ -1,3 +1,4 @@
Rails.application.routes.draw do
match 'site_translations' => 'GoTranslateYourself::SiteTranslations#edit', :as => :site_translations
match 'site_translations' => 'GoTranslateYourself::SiteTranslations#edit', :as => :site_translations, :method => :get
match 'site_translations/save' => 'GoTranslateYourself::SiteTranslations#update', :as => :update_site_translations, :method => :post
end
6 changes: 3 additions & 3 deletions spec/acceptance/support/paths.rb
@@ -1,12 +1,12 @@
module NavigationHelpers
# Put helper methods related to the paths in your application here.

def homepage(lang = nil)
"/#{"?lang=#{lang}" if lang}"
def homepage(locale = nil)
"/#{"?locale=#{locale}" if locale}"
end

def translate
"/translate_site"
"/site_translations"
end
end

Expand Down
8 changes: 3 additions & 5 deletions spec/acceptance/translations_management_spec.rb
Expand Up @@ -13,15 +13,13 @@
scenario "Seeing a list of default translations" do
visit translate
page.should have_content "hello"
page.should have_content "Hello world!"
page.should have_content "site[name]"
page.should have_content "Some random web site"
page.should have_content "site.name"
end

scenario "Entering translations" do
visit translate
fill_in "Witaj, świecie", with: "t[pl][hello]"
fill_in "Wilkommen!", with: "t[de][hello]"
fill_in "translations[pl.hello]", with: "Witaj, świecie"
fill_in "translations[de.hello]", with: "Wilkommen!"
click_button "Save"
visit homepage("pl")
page.should have_content("Witaj, świecie")
Expand Down
5 changes: 5 additions & 0 deletions spec/dummy/app/controllers/application_controller.rb
@@ -1,3 +1,8 @@
class ApplicationController < ActionController::Base
before_filter :set_locale
protect_from_forgery

def set_locale
I18n.locale = params[:locale] || :en
end
end
2 changes: 2 additions & 0 deletions spec/dummy/config/initializers/go_translate_yourself.rb
@@ -1,2 +1,4 @@
GoTranslateYourself.current_store = GoTranslateYourself::MongoStore.new(Mongo::Connection.new.db("go_translate_yourself_test").collection("translations"))
GoTranslateYourself.locales = [:pl, :de]

I18n.backend = I18n::Backend::KeyValue.new GoTranslateYourself.current_store
5 changes: 0 additions & 5 deletions spec/dummy/config/locales/en.yml

This file was deleted.

114 changes: 0 additions & 114 deletions spec/dummy/log/development.log

This file was deleted.

0 comments on commit a585ac8

Please sign in to comment.