Permalink
Browse files

work on routes

added address
finished setting up gettext
  • Loading branch information...
1 parent 2635e96 commit 3def6f51d5633b961b8f199d2e0f01cd2163852f @colindean committed Jul 16, 2010
Showing with 1,026 additions and 62 deletions.
  1. +3 −0 .gitignore
  2. +3 −2 Gemfile
  3. +0 −13 Rakefile
  4. +3 −0 app/models/address.rb
  5. +4 −0 app/models/user.rb
  6. +1 −42 app/views/users/index.html.erb
  7. +0 −3 config/custom_environment.rb
  8. +0 −2 config/environment.rb
  9. +2 −0 config/routes.rb
  10. +23 −0 db/migrate/20100716020339_create_addresses.rb
  11. 0 {po → locale}/en_US/plas.po
  12. 0 {po → locale}/eo/plas.po
  13. 0 {po → locale}/notes.txt
  14. +21 −0 locale/plas.pot
  15. 0 po/plas.pot
  16. +27 −0 test/fixtures/addresses.yml
  17. +8 −0 test/unit/address_test.rb
  18. +32 −0 vendor/plugins/gettext_i18n_rails/Rakefile
  19. +163 −0 vendor/plugins/gettext_i18n_rails/Readme.md
  20. +1 −0 vendor/plugins/gettext_i18n_rails/VERSION
  21. +63 −0 vendor/plugins/gettext_i18n_rails/gettext_i18n_rails.gemspec
  22. +14 −0 vendor/plugins/gettext_i18n_rails/init.rb
  23. +20 −0 vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails.rb
  24. +6 −0 vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/action_controller.rb
  25. +21 −0 vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/active_record.rb
  26. +47 −0 vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/backend.rb
  27. +43 −0 vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/haml_parser.rb
  28. +24 −0 vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/i18n_hacks.rb
  29. +51 −0 vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/model_attributes_finder.rb
  30. +136 −0 vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/ruby_gettext_extractor.rb
  31. +112 −0 vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/tasks.rb
  32. +1 −0 vendor/plugins/gettext_i18n_rails/lib/tasks/gettext_rails_i18n.rake
  33. +40 −0 vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/action_controller_spec.rb
  34. +52 −0 vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/active_record_spec.rb
  35. +41 −0 vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/backend_spec.rb
  36. +47 −0 vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails_spec.rb
  37. +17 −0 vendor/plugins/gettext_i18n_rails/spec/spec_helper.rb
View
@@ -2,3 +2,6 @@
db/*.sqlite3
log/*.log
tmp/**/*
+Gemfile.lock
+gettext/
+vendor/cache/
View
@@ -24,5 +24,6 @@ gem 'sqlite3-ruby', :require => 'sqlite3'
# group :test do
# gem 'webrat'
# end
-gem "fast_gettest"
-gem '>=1.9.3', "gettext", :require => false
+gem "fast_gettext"
+gem "gettext",">=1.9.3", :require => false
+gem 'gettext_i18n_rails', :git => 'git://github.com/grosser/gettext_i18n_rails.git'
View
@@ -13,17 +13,4 @@ rescue LoadError
puts "gettext_i18n_rails is not installed, you should probably run 'bundle install'"
end
-desc "Create .mo files for gettext i18n/l10n"
-task :makemo do
- GetText.create_mofiles
-end
-desc "Update pot/po files to match new version."
-take :updatepo do
- PLAS_TEXT_DOMAIN = "plas"
- PLAS_VERSION = "plas 2010"
- GetText.update_pofiles(PLAS_TEXT_DOMAIN,
- Dir.glob("{app,lib}/**/*.{rb,rhtml}"),
- PLAS_VERSION)
-end
-
Rails::Application.load_tasks
View
@@ -0,0 +1,3 @@
+class Address < ActiveRecord::Base
+ belongs_to :user
+end
View
@@ -8,4 +8,8 @@ class User < ActiveRecord::Base
:with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
validates_inclusion_of :gender, :in => %w{ m f male female guy girl dude dudette transsexual t hermaphrodite h }
+ def self.find_by_handle(handle)
+ find(:all, :conditions => ["LOWER(handle) = ?", handle.downcase])
+ end
+
end
@@ -1,49 +1,8 @@
<h1>Listing users</h1>
-<table>
- <tr>
- <th>Given name</th>
- <th>Family name</th>
- <th>Handle</th>
- <th>Email</th>
- <th>Password</th>
- <th>Date</th>
- <th>Picture</th>
- <th>Enabled</th>
- <th>Gaming group</th>
- <th>Date arrival</th>
- <th>Date departure</th>
- <th>Gamer type</th>
- <th>Birthdate</th>
- <th>Gender</th>
- <th></th>
- <th></th>
- <th></th>
- </tr>
-
<% @users.each do |user| %>
- <tr>
- <td><%= user.given_name %></td>
- <td><%= user.family_name %></td>
- <td><%= user.handle %></td>
- <td><%= user.email %></td>
- <td><%= user.password %></td>
- <td><%= user.date %></td>
- <td><%= user.picture %></td>
- <td><%= user.enabled %></td>
- <td><%= user.gaming_group %></td>
- <td><%= user.date_arrival %></td>
- <td><%= user.date_departure %></td>
- <td><%= user.gamer_type %></td>
- <td><%= user.birthdate %></td>
- <td><%= user.gender %></td>
- <td><%= link_to 'Show', user %></td>
- <td><%= link_to 'Edit', edit_user_path(user) %></td>
- <td><%= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete %></td>
- </tr>
+<li><%= link_to user.handle, user %> - <%= user.given_name %> <%= user.family_name %> <%= _('of') %> <%= user.gaming_group %></li>
<% end %>
-</table>
-
<br />
<%= link_to 'New User', new_user_path %>
@@ -1,3 +0,0 @@
-#http://www.digitale-wertschoepfung.de/artikel/gettext/gettext.html
-$KCODE = 'u'
-require 'jcode'
View
@@ -1,5 +1,3 @@
-require 'custom_environment.rb'
-
# Load the rails application
require File.expand_path('../application', __FILE__)
View
@@ -3,6 +3,8 @@
root :to => "home#index"
+ match 'user/:handle' => 'users#show'
+
#get "home/index"
# The priority is based upon order of creation:
@@ -0,0 +1,23 @@
+class CreateAddresses < ActiveRecord::Migration
+ def self.up
+ create_table :addresses do |t|
+ t.string :line1
+ t.string :line2
+ t.string :line3
+ t.string :neighborhood
+ t.string :city
+ t.string :region
+ t.string :country
+ t.string :postcode
+ t.int :type
+ t.boolean :primary
+ t.references :user
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :addresses
+ end
+end
File renamed without changes.
File renamed without changes.
File renamed without changes.
View
@@ -0,0 +1,21 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: version 0.0.1\n"
+"POT-Creation-Date: 2010-07-15 21:57-0400\n"
+"PO-Revision-Date: 2010-07-15 21:57-0400\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
+
+#: app/views/users/index.html.erb:4
+msgid "of"
+msgstr ""
View
No changes.
@@ -0,0 +1,27 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+one:
+ line1: MyString
+ line2: MyString
+ line3: MyString
+ neighborhood: MyString
+ city: MyString
+ region: MyString
+ country: MyString
+ postcode: MyString
+ type:
+ primary: false
+ user:
+
+two:
+ line1: MyString
+ line2: MyString
+ line3: MyString
+ neighborhood: MyString
+ city: MyString
+ region: MyString
+ country: MyString
+ postcode: MyString
+ type:
+ primary: false
+ user:
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class AddressTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
@@ -0,0 +1,32 @@
+require 'spec/rake/spectask'
+Spec::Rake::SpecTask.new {|t| t.spec_opts = ['--color']}
+
+task :default do
+ # test with 2.x
+ puts `VERSION='~>2' rake spec RSPEC_COLOR=1`
+
+ # gem 'activerecord', '>=3' did not work for me, but just require gets the right version...
+ require 'active_record'
+ if ActiveRecord::VERSION::MAJOR >= 3
+ puts `rake spec RSPEC_COLOR=1`
+ else
+ 'install rails 3 to get full test coverage...'
+ end
+end
+
+begin
+ require 'jeweler'
+ project_name = 'gettext_i18n_rails'
+ Jeweler::Tasks.new do |gem|
+ gem.name = project_name
+ gem.summary = "Simple FastGettext Rails integration."
+ gem.email = "grosser.michael@gmail.com"
+ gem.homepage = "http://github.com/grosser/#{project_name}"
+ gem.authors = ["Michael Grosser"]
+ gem.add_dependency 'fast_gettext'
+ end
+
+ Jeweler::GemcutterTasks.new
+rescue LoadError
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler"
+end
@@ -0,0 +1,163 @@
+Simple [FastGettext](http://github.com/grosser/fast_gettext) / Rails integration.
+
+Do all translations you want with FastGettext, use any other I18n backend as extension/fallback.
+
+Rails does: `I18n.t('weir.rails.syntax.i.hate')`
+We do: `_('Just translate my damn text!')`
+To use I18n calls define a `weir.rails.syntax.i.hate` translation.
+
+[See it working in the example application.](https://github.com/grosser/gettext_i18n_rails_example)
+
+Setup
+=====
+###Installation
+As plugin: ` script/plugin install git://github.com/grosser/gettext_i18n_rails.git `
+Or Gem: ` sudo gem install gettext_i18n_rails `
+
+[FastGettext](http://github.com/grosser/fast_gettext): ` sudo gem install fast_gettext `
+
+### Want to find used messages in your ruby files ?
+GetText 1.93 or GetText 2.0: ` sudo gem install gettext `
+GetText 2.0 will render 1.93 unusable, so only install if you do not have apps that use 1.93!
+
+` sudo gem install ruby_parser `
+
+### Locales & initialisation
+Copy default locales with dates/sentence-connectors/AR-errors you want from e.g.
+[rails i18n](http://github.com/svenfuchs/rails-i18n/tree/master/rails/locale/) into 'config/locales'
+
+If you are not using bundler:
+
+ #config/environment.rb
+ Rails::Initializer.run do |config|
+ ...
+ config.gem "fast_gettext", :version => '>=0.4.8'
+ #only used for mo/po file generation in development, !do not load(:lib=>false), will needlessly eat ram!
+ config.gem "gettext", :lib => false, :version => '>=1.9.3'
+ end
+
+If you are using bundler:
+
+ #Gemfile
+ gem "fast_gettext", '>=0.4.8'
+ gem '>=1.9.3', "gettext", :require => false
+
+If you installed it as a gem add to your Rakefile
+
+ #Rakefile
+ begin
+ require "gettext_i18n_rails/tasks"
+ rescue LoadError
+ puts "gettext_i18n_rails is not installed, you probably should run 'rake gems:install' or 'bundle install'."
+ end
+
+To initialize:
+
+ #config/initialisers/fast_gettext.rb
+ FastGettext.add_text_domain 'app', :path => 'locale'
+ FastGettext.default_available_locales = ['en','de'] #all you want to allow
+ FastGettext.default_text_domain = 'app'
+
+And in your application:
+
+ #app/controllers/application_controller.rb
+ class ApplicationController < ...
+ before_filter :set_gettext_locale
+
+
+Translating
+===========
+###Getting started
+####Option A: Traditional mo/po files
+ - use some _('translations')
+ - run `rake gettext:find`, to let GetText find all translations used
+ - (optional) run `rake gettext:store_model_attributes`, to parse the database for columns that can be translated
+ - if this is your first translation: `cp locale/app.pot locale/de/app.po` for every locale you want to use
+ - translate messages in 'locale/de/app.po' (leave msgstr blank and msgstr == msgid)
+new translations will be marked "fuzzy", search for this and remove it, so that they will be used.
+Obsolete translations are marked with ~#, they usually can be removed since they are no longer needed
+ - run `rake gettext:pack` to write GetText format translation files
+
+####Option B: Database
+This is the most scalable method, since all translators can work simultanousely and online.
+
+Most easy to use with the [translation database Rails engine](http://github.com/grosser/translation_db_engine).
+FastGettext setup would look like:
+ include FastGettext::TranslationRepository::Db.require_models #load and include default models
+ FastGettext.add_text_domain 'app', :type=>:db, :model=>TranslationKey
+Translations can be edited under `/translation_keys`
+
+###I18n
+
+ I18n.locale <==> FastGettext.locale.to_sym
+ I18n.locale = :de <==> FastGettext.locale = 'de'
+
+Any call to I18n that matches a gettext key will be translated through FastGettext.
+
+Namespaces
+==========
+Car|Model means Model in namespace Car.
+You do not have to translate this into english "Model", if you use the
+namespace-aware translation
+ s_('Car|Model') == 'Model' #when no translation was found
+
+ActiveRecord - error messages
+=============================
+ActiveRecord error messages are translated through Rails::I18n, but
+model names and model attributes are translated through FastGettext.
+Therefore a validation error on a BigCar's wheels_size needs `_('big car')` and `_('BigCar|Wheels size')`
+to display localized.
+
+The model/attribute translations can be found through `rake gettext:store_model_attributes`,
+(which ignores some commonly untranslated columns like id,type,xxx_count,...).
+
+Error messages can be translated through FastGettext, if the ':message' is a translation-id or the matching Rails I18n key is translated.
+In any other case they go through the SimpleBackend.
+
+####Option A:
+Define a translation for "I need my rating!" and use it as message.
+ validates_inclusion_of :rating, :in=>1..5, :message=>N_('I need my rating!')
+
+####Option B:
+Do not use :message
+ validates_inclusion_of :rating, :in=>1..5
+and make a translation for the I18n key: `activerecord.errors.models.rating.attributes.rating.inclusion`
+
+####Option C:
+Add a translation to each config/locales/*.yml files
+ en:
+ activerecord:
+ errors:
+ models:
+ rating:
+ attributes:
+ rating:
+ inclusion: " -- please choose!"
+The [rails I18n guide](http://guides.rubyonrails.org/i18n.html) can help with Option B and C.
+
+Plurals
+=======
+FastGettext supports pluralization
+ n_('Apple','Apples',3) == 'Apples'
+
+Unfound translations
+====================
+Sometimes translations like `_("x"+"u")` cannot be fond. You have 4 options:
+
+ - add `N_('xu')` somewhere else in the code, so the parser sees it
+ - add `N_('xu')` in a totally seperate file like `locale/unfound_translations.rb`, so the parser sees it
+ - use the [gettext_test_log rails plugin ](http://github.com/grosser/gettext_test_log) to find all translations that where used while testing
+ - add a Logger to a translation Chain, so every unfound translations is logged ([example]((http://github.com/grosser/fast_gettext)))
+
+
+Contributors
+======
+ - [ruby gettext extractor](http://github.com/retoo/ruby_gettext_extractor/tree/master) from [retoo](http://github.com/retoo)
+ - [Paul McMahon](http://github.com/pwim)
+ - [Duncan Mac-Vicar P](http://duncan.mac-vicar.com/blog/)
+ - [Ramihajamalala Hery](http://my.rails-royce.org/)
+ - [J. Pablo Fernández](http://pupeno.com/)
+
+[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...
@@ -0,0 +1 @@
+0.2.1
Oops, something went wrong.

0 comments on commit 3def6f5

Please sign in to comment.