Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit ba1fb1d5af0c9ec21133edc7872d7daefd882080 @raul committed Jun 6, 2008
Showing with 4,550 additions and 0 deletions.
  1. +6 −0 ChangeLog
  2. +20 −0 MIT-LICENSE
  3. +149 −0 README.rdoc
  4. +22 −0 Rakefile
  5. +256 −0 SampleApp/README
  6. +10 −0 SampleApp/Rakefile
  7. +17 −0 SampleApp/app/controllers/application.rb
  8. +85 −0 SampleApp/app/controllers/users_controller.rb
  9. +3 −0 SampleApp/app/helpers/application_helper.rb
  10. +2 −0 SampleApp/app/helpers/users_helper.rb
  11. +2 −0 SampleApp/app/models/user.rb
  12. +35 −0 SampleApp/app/views/layouts/application.html.erb
  13. +22 −0 SampleApp/app/views/users/edit.html.erb
  14. +22 −0 SampleApp/app/views/users/index.html.erb
  15. +21 −0 SampleApp/app/views/users/new.html.erb
  16. +13 −0 SampleApp/app/views/users/show.html.erb
  17. +109 −0 SampleApp/config/boot.rb
  18. +19 −0 SampleApp/config/database.yml
  19. +67 −0 SampleApp/config/environment.rb
  20. +17 −0 SampleApp/config/environments/development.rb
  21. +22 −0 SampleApp/config/environments/production.rb
  22. +22 −0 SampleApp/config/environments/test.rb
  23. +10 −0 SampleApp/config/initializers/inflections.rb
  24. +5 −0 SampleApp/config/initializers/mime_types.rb
  25. +15 −0 SampleApp/config/initializers/new_rails_defaults.rb
  26. +14 −0 SampleApp/config/routes.rb
  27. 0 SampleApp/config/routes_en.yml
  28. +4 −0 SampleApp/config/routes_es.yml
  29. BIN SampleApp/db/development.sqlite3
  30. +14 −0 SampleApp/db/migrate/20080606095256_create_users.rb
  31. +21 −0 SampleApp/db/schema.rb
  32. BIN SampleApp/db/test.sqlite3
  33. +2 −0 SampleApp/doc/README_FOR_APP
  34. +14 −0 SampleApp/lang/es.yml
  35. +30 −0 SampleApp/public/404.html
  36. +30 −0 SampleApp/public/422.html
  37. +30 −0 SampleApp/public/500.html
  38. +10 −0 SampleApp/public/dispatch.cgi
  39. +24 −0 SampleApp/public/dispatch.fcgi
  40. +10 −0 SampleApp/public/dispatch.rb
  41. +54 −0 SampleApp/public/stylesheets/scaffold.css
  42. +3 −0 SampleApp/script/about
  43. +3 −0 SampleApp/script/console
  44. +3 −0 SampleApp/script/dbconsole
  45. +3 −0 SampleApp/script/destroy
  46. +3 −0 SampleApp/script/generate
  47. +3 −0 SampleApp/script/performance/benchmarker
  48. +3 −0 SampleApp/script/performance/profiler
  49. +3 −0 SampleApp/script/performance/request
  50. +3 −0 SampleApp/script/plugin
  51. +3 −0 SampleApp/script/process/inspector
  52. +3 −0 SampleApp/script/process/reaper
  53. +3 −0 SampleApp/script/process/spawner
  54. +3 −0 SampleApp/script/runner
  55. +3 −0 SampleApp/script/server
  56. +9 −0 SampleApp/test/fixtures/users.yml
  57. +45 −0 SampleApp/test/functional/users_controller_test.rb
  58. +55 −0 SampleApp/test/test_helper.rb
  59. +8 −0 SampleApp/test/unit/user_test.rb
  60. +18 −0 SampleApp/vendor/plugins/gibberish/LICENSE
  61. +118 −0 SampleApp/vendor/plugins/gibberish/README
  62. +14 −0 SampleApp/vendor/plugins/gibberish/Rakefile
  63. +3 −0 SampleApp/vendor/plugins/gibberish/init.rb
  64. +3 −0 SampleApp/vendor/plugins/gibberish/lang/es.yml
  65. +3 −0 SampleApp/vendor/plugins/gibberish/lang/fr.yml
  66. +8 −0 SampleApp/vendor/plugins/gibberish/lib/gibberish.rb
  67. +88 −0 SampleApp/vendor/plugins/gibberish/lib/gibberish/localize.rb
  68. +17 −0 SampleApp/vendor/plugins/gibberish/lib/gibberish/string_ext.rb
  69. +203 −0 SampleApp/vendor/plugins/gibberish/test/gibberish_test.rb
  70. +1 −0 SampleApp/vendor/plugins/gibberish/test/lang/es.yml
  71. +1 −0 SampleApp/vendor/plugins/gibberish/test/lang/fr.yml
  72. +6 −0 SampleApp/vendor/plugins/translate_routes/ChangeLog
  73. +20 −0 SampleApp/vendor/plugins/translate_routes/MIT-LICENSE
  74. +150 −0 SampleApp/vendor/plugins/translate_routes/README
  75. +22 −0 SampleApp/vendor/plugins/translate_routes/Rakefile
  76. 0 SampleApp/vendor/plugins/translate_routes/config/routes_en.yml
  77. +1 −0 SampleApp/vendor/plugins/translate_routes/config/routes_es.yml
  78. +1 −0 SampleApp/vendor/plugins/translate_routes/doc/created.rid
  79. +351 −0 SampleApp/vendor/plugins/translate_routes/doc/files/README.html
  80. +26 −0 SampleApp/vendor/plugins/translate_routes/doc/fr_class_index.html
  81. +27 −0 SampleApp/vendor/plugins/translate_routes/doc/fr_file_index.html
  82. +26 −0 SampleApp/vendor/plugins/translate_routes/doc/fr_method_index.html
  83. +24 −0 SampleApp/vendor/plugins/translate_routes/doc/index.html
  84. +208 −0 SampleApp/vendor/plugins/translate_routes/doc/rdoc-style.css
  85. +1 −0 SampleApp/vendor/plugins/translate_routes/init.rb
  86. +1 −0 SampleApp/vendor/plugins/translate_routes/install.rb
  87. +172 −0 SampleApp/vendor/plugins/translate_routes/lib/translate_routes.rb
  88. +4 −0 SampleApp/vendor/plugins/translate_routes/tasks/translate_routes_tasks.rake
  89. +222 −0 SampleApp/vendor/plugins/translate_routes/test/translate_routes_test.rb
  90. +1 −0 SampleApp/vendor/plugins/translate_routes/uninstall.rb
  91. 0 config/routes_en.yml
  92. +1 −0 config/routes_es.yml
  93. +1 −0 doc/created.rid
  94. +351 −0 doc/files/README.html
  95. +358 −0 doc/files/README_rdoc.html
  96. +26 −0 doc/fr_class_index.html
  97. +27 −0 doc/fr_file_index.html
  98. +26 −0 doc/fr_method_index.html
  99. +24 −0 doc/index.html
  100. +208 −0 doc/rdoc-style.css
  101. +1 −0 init.rb
  102. +1 −0 install.rb
  103. +172 −0 lib/translate_routes.rb
  104. +4 −0 tasks/translate_routes_tasks.rake
  105. +222 −0 test/translate_routes_test.rb
  106. +1 −0 uninstall.rb
@@ -0,0 +1,6 @@
+-- 0.95 (Jan 21st 2008)
+ * Still beta version
+ * Added yaml files support for dictionaries
+
+-- 0.9 (Dec 27th 2007)
+ * Beta version
@@ -0,0 +1,20 @@
+Copyright (c) 2007 Raul Murciano [http://raul.murciano.net], Domestika INTERNET S.L. [http://domestika.org]
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,149 @@
+=TranslateRoutes
+This Rails plugin provides a simple way to translate your URLs to any number of languages.
+All routes automatically add a <tt>:lang</tt> parameter to the request so your controllers can setup an internationalized user experience.
+
+The plugin has been designed to be easy to use and customize.
+As it works after routing processing, it plays nice with all kind of routing definitions, including RESTful and named routes.
+It also takes care of your current routing helpers by translating them transparently.
+
+==Installation
+Just check it out on your app's <tt>/vendor/plugins</tt> and see the examples below.
+
+==Usage
+Let's start with a tiny example. Of course you need to define your routes first, e.g:
+
+ ActionController::Routing::Routes.draw do |map|
+ map.connect 'contact', :controller => 'contact', :action => 'index'
+ end
+
+After that, on the same routes.rb file, you can translate the generated route by doing:
+
+ ActionController::Routing::Translator.translate do |t|
+ t['es'] = {
+ 'contact' => 'contacto'
+ }
+ end
+
+This will give you the next routes (check it out by doing 'rake routes'):
+
+ /es/contacto {:lang=>"es", :controller=>"contact", :action=>"index"}
+ /contact {:lang=>"en", :controller=>"contact", :action=>"index"}
+
+As you can see:
+- a +lang+ param has been added to your routes, with the value of the used language (*)
+- +en+ is the default language (*)
+- the URLs associated with a language are always prefixed with the language code that you provided on the translation.
+- the default language URLs have no language prefix (*)
+(*) You can customize this behaviour, see "Configuration" below.
+
+Let's add some routes and translations to our example:
+
+ ActionController::Routing::Routes.draw do |map|
+ map.connect 'contact', :controller => 'contact', :action => 'index'
+ map.home '', :controller => 'main', :action => 'index'
+ map.resources :people
+ end
+
+ ActionController::Routing::Translator.translate do |t|
+
+ t['es'] = {
+ 'contact' => 'contacto',
+ 'people' => 'gente',
+ 'new' => 'crear',
+ 'edit' =>'editar'
+ }
+
+ t['fr'] = {
+ 'people' => 'personne',
+ 'new' => 'neuf'
+ }
+ end
+
+Again, you can use <tt>rake routes</tt> to see the generated URLs. I'll only talk about some of them:
+
+We didn't give any french translation for +contact+, so the french associated URLs use the untranslated text:
+
+ /fr/contact {:lang=>"fr", :controller=>"contact", :action=>"index"}
+ /es/contacto {:lang=>"es", :controller=>"contact", :action=>"index"}
+ /contact {:lang=>"en", :controller=>"contact", :action=>"index"}
+
+The named routes have generated not only translated URLs but also a helper for each language:
+
+ home_fr /fr {:lang=>"fr", :controller=>"main", :action=>"index"}
+ home_es /es {:lang=>"es", :controller=>"main", :action=>"index"}
+ home_en / {:lang=>"en", :controller=>"main", :action=>"index"}
+
+This means that you can use +home_es_path+ and +home_es_url+ on your controllers and views.
+
+No +home+ named route is shown on the list so it looks like you can't use a simple +home_path+ helper, but relax: you have a +home_path+ helper available for your controllers and views. It looks for the current +lang+ value and redirects to the appropiate helper. This means that if you're rendering the <tt>contact/index</tt> view when visiting <tt>/es/contacto</tt>, the +home_path+ helper will call to +home_es_path+ and return its result. The same applies to +home_url+, obviously.
+
+We can see that resource controllers and actions are translated as well:
+
+ new_person_fr GET /fr/personne/neuf {:lang=>"fr", :controller=>"people", :action=>"new"}
+ new_person_es GET /es/gente/crear {:lang=>"es", :controller=>"people", :action=>"new"}
+ new_person GET /people/new {:lang=>"en", :controller=>"people", :action=>"new"}
+
+We can get rid of that verbose translation hashes by using yaml files. Create a file inside your <tt>/config</tt> directory, called <tt>routes_es.yml</tt> and fill it with your desired translations, e.g:
+
+ # /config/routes_es.yml
+ person: persona
+
+and replace all the
+
+ ActionController::Routing::Translator.translate do
+ ...
+ end
+
+stuff on <tt>routes.rb</tt> with this simple line:
+
+ ActionController::Routing::Translator.translate_from_files
+
+== Integration
+You can find a sample Rails application on the translate_routes repository, designed to show how easy is to setup
+
+== Configuration
+You can customize some features by adding some lines before your translation code:
+
+- You can change the language param key (<tt>:lang</tt> by default). To change this feature use:
+
+ ActionController::Routing::Translator.lang_param_key = :foo
+
+This key should have the same name that the instance variable which keeps the language code on your controllers and views.
+
+- You can change the default language of your application with:
+
+ ActionController::Routing::Translator.default_lang = 'es'
+
+Of course, you can also translate your default language. If, as I do, all your controllers and actions have english names, you can have an english version on your site for free by doing:
+
+ ActionController::Routing::Translator.default_lang = 'es'
+ ActionController::Routing::Translator.translate do |t|
+ t['en'] = {}
+ t['es'] = { # spanish translation here }
+ end
+
+or adding the equivalent <tt>/config/routes_es.yml</tt> and an empty <tt>/config/routes_en.yml</tt>
+
+- You can add a prefix also on your default language routes by doing:
+
+ ActionController::Routing::Translator.prefix_on_default_lang = true
+
+<b>WARNING!</b> this way you'll disable your root -empty- route: if english is your default language, your empty route will be translated to <tt>/en</tt> so you must manually take care of it.
+
+== Suggestions, bug reports, questions
+Feedback and comments will be always welcome at raul@murciano.net
+
+
+== Credits
+- Raul Murciano [http://raul.murciano.net] - code
+- Domestika INTERNET S.L [http://domestika.org] - incredible support, really nice people to work with!
+
+
+== Rails routing resources
+- David Black's 'Rails Routing' ebook rocks! - 'Ruby for Rails' too, BTW.
+- Obie Fernandez's 'The Rails Way' - the definitive RoR reference, great work Obie!
+
+== License
+Copyright (c) 2007
+Raul Murciano [http://raul.murciano.net]
+Domestika INTERNET S.L. [http://domestika.org], released under the MIT license (see MIT-LICENSE)
@@ -0,0 +1,22 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the translate_routes plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the translate_routes plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'TranslateRoutes'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
Oops, something went wrong. Retry.

0 comments on commit ba1fb1d

Please sign in to comment.