commit 73f2fc180533c37c7205b21422e8452fe44295b9
Author: Marc Dequènes (Duck) <Duck@DuckCorp.org>
Date:   Tue Mar 24 01:29:44 2009 +0100

    [evol] language can be forced in the user admin page (closes #6) (no user interface yet)

diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
index 7781959..d1b4d74 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -2,4 +2,9 @@ class Admin::UsersController < Admin::AdminController
   simple_rest_support
 
   before_filter :admin_required
+  after_filter :set_language, :only => [:update]
+
+  def set_language
+    @config.switch_locale(@user.prefered_language) if @user == @current_user
+  end
 end
diff --git a/app/controllers/application.rb b/app/controllers/application.rb
index 234ff5a..8a8c4c6 100644
--- a/app/controllers/application.rb
+++ b/app/controllers/application.rb
@@ -22,6 +22,8 @@ class ApplicationController < ActionController::Base
 
   init_gettext MyCyma::Info::app_name
 
+  before_init_gettext :ensure_prefered_language
+
   def initialize
     super
 
@@ -62,4 +64,8 @@ class ApplicationController < ActionController::Base
       redirect_to :controller => 'welcome', :action => 'index'
     end
   end
+
+  def ensure_prefered_language
+    @config.switch_locale(current_user.prefered_language) if current_user
+  end
 end
diff --git a/app/views/admin/users/_form.rhtml b/app/views/admin/users/_form.rhtml
index 47f1a0f..486479f 100644
--- a/app/views/admin/users/_form.rhtml
+++ b/app/views/admin/users/_form.rhtml
@@ -1,8 +1,6 @@
 <p>
 <%
-selected_artwork_set_id = (@artwork ? @artwork.artwork_set_id : nil)
-selected_artwork_group_id = (@artwork ? @artwork.artwork_group_id : nil)
-selected_artwork_size_id = (@artwork ? @artwork.artwork_size_id : nil)
+language_list = @config.available_languages.collect{|id, name| [name, id] }
 
 form_for_resource do |f|
 %>
@@ -11,6 +9,7 @@ stacking_form(f) do |table|
   table.field :login, _("Login"), :text_field
   table.field :real_name, _("Real Name"), :text_field
   table.field :email, _("eMail"), :text_field
+  table.field :prefered_language, _("Prefered language"), :select, language_list
   table.field :admin, _("Administrator?"), :check_box
   table.field :password, _("Password"), :password_field
   table.field :password_confirmation, _("Password (confirmation)"), :password_field
diff --git a/app/views/admin/users/show.rhtml b/app/views/admin/users/show.rhtml
index 68c55f4..a265819 100644
--- a/app/views/admin/users/show.rhtml
+++ b/app/views/admin/users/show.rhtml
@@ -6,6 +6,7 @@ stacking_table do |table|
   table.content [_("Login:"), @user.login]
   table.content [_("Real Name:"), @user.real_name]
   table.content [_("Email:"), @user.email]
+  table.content [_("Prefered language:"), @user.prefered_langage]
   table.content [_("Administrator?"), display_boolean(@user.admin)]
   table.category _("Entry Status") do |cat|
     cat.content [_("First Created:"), "#{display_timestamp(@user.created_at)}"]
diff --git a/lib/mycyma.rb b/lib/mycyma.rb
index f698310..666346d 100644
--- a/lib/mycyma.rb
+++ b/lib/mycyma.rb
@@ -3,11 +3,13 @@ require 'mycyma/info'
 
 require 'ostruct'
 require 'singleton'
+require 'gettext'
 
 module MyCyma
 
   class Config < OpenStruct
     include Singleton
+    include GetText
 
     def initialize
       str = File.read(File.join(RAILS_ROOT, "config", "settings.yml"))
@@ -24,7 +26,27 @@ module MyCyma
       list
     end
 
-  end
+    # should be guessed
+    def available_languages
+      {
+        ''      => _("Browser preference"),
+        'en'    => _("English"),
+        'fr'    => _("French")
+      }
+    end
 
+    def switch_locale(locale = nil)
+      # if unspecified, use browser prefered langage
+      if locale.nil?
+        cgi = nil
+        if defined? request.cgi
+          cgi = request.cgi
+        end
+        set_cgi(cgi)
+      else
+        set_locale(locale)
+      end
+    end
+  end
 end
 
diff --git a/locale/fr/LC_MESSAGES/MyCyma.mo b/locale/fr/LC_MESSAGES/MyCyma.mo
index ec86b59..ff80bec 100644
Binary files a/locale/fr/LC_MESSAGES/MyCyma.mo and b/locale/fr/LC_MESSAGES/MyCyma.mo differ
diff --git a/po/MyCyma.pot b/po/MyCyma.pot
index 84b989a..e13445b 100644
--- a/po/MyCyma.pot
+++ b/po/MyCyma.pot
@@ -7,7 +7,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: MyCyma 0.1.0\n"
-"POT-Creation-Date: 2009-03-18 14:26+0100\n"
+"POT-Creation-Date: 2009-03-24 01:14+0100\n"
 "PO-Revision-Date: 2008-07-28 02:17+0200\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -168,6 +168,10 @@ msgstr ""
 msgid "User|Admin"
 msgstr ""
 
+#: app/models/user.rb:-
+msgid "User|Prefered language"
+msgstr ""
+
 #: app/models/user.rb:11
 msgid "Invalid email"
 msgstr ""
@@ -352,7 +356,7 @@ msgstr ""
 msgid "Updated at:"
 msgstr ""
 
-#: app/controllers/application.rb:39
+#: app/controllers/application.rb:42
 msgid "Please login to continue"
 msgstr ""
 
@@ -520,12 +524,12 @@ msgid "Artwork Step Status"
 msgstr ""
 
 #: app/views/admin/artwork_step_images/show.rhtml:27
-#: app/views/admin/artworks/show.rhtml:42
+#: app/views/admin/artworks/show.rhtml:44
 msgid "Entry First Created:"
 msgstr ""
 
 #: app/views/admin/artwork_step_images/show.rhtml:28
-#: app/views/admin/artworks/show.rhtml:43
+#: app/views/admin/artworks/show.rhtml:45
 msgid "Entry Last Updated:"
 msgstr ""
 
@@ -534,7 +538,7 @@ msgid "Display all steps"
 msgstr ""
 
 #: app/views/admin/artwork_step_images/_form.rhtml:7
-#: app/views/admin/artworks/show.rhtml:37
+#: app/views/admin/artworks/show.rhtml:39
 #: app/views/admin/artworks/_form.rhtml:37
 msgid "Date:"
 msgstr ""
@@ -555,15 +559,15 @@ msgstr ""
 msgid "List of users"
 msgstr ""
 
-#: app/views/admin/users/index.rhtml:6 app/views/admin/users/_form.rhtml:11
+#: app/views/admin/users/index.rhtml:6 app/views/admin/users/_form.rhtml:9
 msgid "Login"
 msgstr ""
 
-#: app/views/admin/users/index.rhtml:7 app/views/admin/users/_form.rhtml:12
+#: app/views/admin/users/index.rhtml:7 app/views/admin/users/_form.rhtml:10
 msgid "Real Name"
 msgstr ""
 
-#: app/views/admin/users/index.rhtml:8 app/views/admin/users/_form.rhtml:13
+#: app/views/admin/users/index.rhtml:8 app/views/admin/users/_form.rhtml:11
 msgid "eMail"
 msgstr ""
 
@@ -583,31 +587,39 @@ msgstr ""
 msgid "Email:"
 msgstr ""
 
-#: app/views/admin/users/show.rhtml:9 app/views/admin/users/_form.rhtml:14
+#: app/views/admin/users/show.rhtml:9
+msgid "Prefered language:"
+msgstr ""
+
+#: app/views/admin/users/show.rhtml:10 app/views/admin/users/_form.rhtml:13
 msgid "Administrator?"
 msgstr ""
 
-#: app/views/admin/users/show.rhtml:10
+#: app/views/admin/users/show.rhtml:11
 msgid "Entry Status"
 msgstr ""
 
-#: app/views/admin/users/show.rhtml:11
+#: app/views/admin/users/show.rhtml:12
 msgid "First Created:"
 msgstr ""
 
-#: app/views/admin/users/show.rhtml:12
+#: app/views/admin/users/show.rhtml:13
 msgid "Last Updated:"
 msgstr ""
 
-#: app/views/admin/users/show.rhtml:18
+#: app/views/admin/users/show.rhtml:19
 msgid "Display all users"
 msgstr ""
 
-#: app/views/admin/users/_form.rhtml:15
+#: app/views/admin/users/_form.rhtml:12
+msgid "Prefered language"
+msgstr ""
+
+#: app/views/admin/users/_form.rhtml:14
 msgid "Password"
 msgstr ""
 
-#: app/views/admin/users/_form.rhtml:16
+#: app/views/admin/users/_form.rhtml:15
 msgid "Password (confirmation)"
 msgstr ""
 
@@ -746,7 +758,7 @@ msgid "Artwork Set #%u"
 msgstr ""
 
 #: app/views/admin/artwork_sets/show.rhtml:13
-#: app/views/admin/artworks/show.rhtml:50
+#: app/views/admin/artworks/show.rhtml:52
 msgid "Display all sets"
 msgstr ""
 
@@ -831,7 +843,7 @@ msgid "Steps"
 msgstr ""
 
 #: app/views/admin/artworks/index.rhtml:24
-#: app/views/admin/artworks/show.rhtml:49
+#: app/views/admin/artworks/show.rhtml:51
 msgid "View Steps"
 msgstr ""
 
@@ -839,59 +851,59 @@ msgstr ""
 msgid "Artwork '%s'"
 msgstr ""
 
-#: app/views/admin/artworks/show.rhtml:12
+#: app/views/admin/artworks/show.rhtml:14
 #: app/views/admin/artworks/_form.rhtml:11
 msgid "General"
 msgstr ""
 
-#: app/views/admin/artworks/show.rhtml:27
+#: app/views/admin/artworks/show.rhtml:29
 msgid "Set / Group:"
 msgstr ""
 
-#: app/views/admin/artworks/show.rhtml:28
+#: app/views/admin/artworks/show.rhtml:30
 #: app/views/admin/artworks/_form.rhtml:26
 msgid "Size:"
 msgstr ""
 
-#: app/views/admin/artworks/show.rhtml:29
+#: app/views/admin/artworks/show.rhtml:31
 #: app/views/admin/artworks/_form.rhtml:28
 msgid "Materials:"
 msgstr ""
 
-#: app/views/admin/artworks/show.rhtml:30
+#: app/views/admin/artworks/show.rhtml:32
 msgid "Supports:"
 msgstr ""
 
-#: app/views/admin/artworks/show.rhtml:32
+#: app/views/admin/artworks/show.rhtml:34
 #: app/views/admin/artworks/_form.rhtml:31
 msgid "Result"
 msgstr ""
 
-#: app/views/admin/artworks/show.rhtml:33
+#: app/views/admin/artworks/show.rhtml:35
 #: app/views/admin/artworks/_form.rhtml:32
 msgid "Condition:"
 msgstr ""
 
-#: app/views/admin/artworks/show.rhtml:34
+#: app/views/admin/artworks/show.rhtml:36
 #: app/views/admin/artworks/_form.rhtml:33
 msgid "Placement"
 msgstr ""
 
-#: app/views/admin/artworks/show.rhtml:35
+#: app/views/admin/artworks/show.rhtml:37
 #: app/views/admin/artworks/_form.rhtml:34
 msgid "Reason:"
 msgstr ""
 
-#: app/views/admin/artworks/show.rhtml:36
+#: app/views/admin/artworks/show.rhtml:38
 #: app/views/admin/artworks/_form.rhtml:36
 msgid "Location:"
 msgstr ""
 
-#: app/views/admin/artworks/show.rhtml:40
+#: app/views/admin/artworks/show.rhtml:42
 msgid "Artwork Status"
 msgstr ""
 
-#: app/views/admin/artworks/show.rhtml:49
+#: app/views/admin/artworks/show.rhtml:51
 msgid "View all Steps"
 msgstr ""
 
@@ -946,3 +958,15 @@ msgstr ""
 #: app/views/admin/artwork_groups/edit.rhtml:1
 msgid "Modify Artwork Group"
 msgstr ""
+
+#: lib/mycyma.rb:32
+msgid "Browser preference"
+msgstr ""
+
+#: lib/mycyma.rb:33
+msgid "English"
+msgstr ""
+
+#: lib/mycyma.rb:34
+msgid "French"
+msgstr ""
diff --git a/po/fr/MyCyma.po b/po/fr/MyCyma.po
index 8b7057b..0da4574 100644
--- a/po/fr/MyCyma.po
+++ b/po/fr/MyCyma.po
@@ -7,7 +7,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: MyCyma 0.1.0\n"
-"POT-Creation-Date: 2009-03-18 14:26+0100\n"
+"POT-Creation-Date: 2009-03-24 01:14+0100\n"
 "PO-Revision-Date: 2008-07-28 02:17+0200\n"
 "Last-Translator: Marc Dequènes (Duck) <Duck@DuckCorp.org>\n"
 "MIME-Version: 1.0\n"
@@ -167,6 +167,10 @@ msgstr "Utilisateur|Mis à jour le :"
 msgid "User|Admin"
 msgstr "Utilisateur|Admin"
 
+#: app/models/user.rb:-
+msgid "User|Prefered language"
+msgstr "Utilisateur|Langage préféré"
+
 #: app/models/user.rb:11
 msgid "Invalid email"
 msgstr "Email invalide"
@@ -351,7 +355,7 @@ msgstr "Créé(e) le :"
 msgid "Updated at:"
 msgstr "Mis(e) à jour le :"
 
-#: app/controllers/application.rb:39
+#: app/controllers/application.rb:42
 msgid "Please login to continue"
 msgstr "Veuillez vous identifier pour continuer"
 
@@ -522,12 +526,12 @@ msgid "Artwork Step Status"
 msgstr "État de l'Étape"
 
 #: app/views/admin/artwork_step_images/show.rhtml:27
-#: app/views/admin/artworks/show.rhtml:42
+#: app/views/admin/artworks/show.rhtml:44
 msgid "Entry First Created:"
 msgstr "Entrée Initialement Créée :"
 
 #: app/views/admin/artwork_step_images/show.rhtml:28
-#: app/views/admin/artworks/show.rhtml:43
+#: app/views/admin/artworks/show.rhtml:45
 msgid "Entry Last Updated:"
 msgstr "Entrée Dernièrement Mise à jour :"
 
@@ -536,7 +540,7 @@ msgid "Display all steps"
 msgstr "Afficher toutes les étapes"
 
 #: app/views/admin/artwork_step_images/_form.rhtml:7
-#: app/views/admin/artworks/show.rhtml:37
+#: app/views/admin/artworks/show.rhtml:39
 #: app/views/admin/artworks/_form.rhtml:37
 msgid "Date:"
 msgstr "Date "
@@ -557,15 +561,15 @@ msgstr "Nouvel Utilisateur"
 msgid "List of users"
 msgstr "Liste des utilisateurs"
 
-#: app/views/admin/users/index.rhtml:6 app/views/admin/users/_form.rhtml:11
+#: app/views/admin/users/index.rhtml:6 app/views/admin/users/_form.rhtml:9
 msgid "Login"
 msgstr "Identifiant"
 
-#: app/views/admin/users/index.rhtml:7 app/views/admin/users/_form.rhtml:12
+#: app/views/admin/users/index.rhtml:7 app/views/admin/users/_form.rhtml:10
 msgid "Real Name"
 msgstr "Nom"
 
-#: app/views/admin/users/index.rhtml:8 app/views/admin/users/_form.rhtml:13
+#: app/views/admin/users/index.rhtml:8 app/views/admin/users/_form.rhtml:11
 msgid "eMail"
 msgstr "eMail"
 
@@ -585,31 +589,40 @@ msgstr "Nom :"
 msgid "Email:"
 msgstr "Email :"
 
-#: app/views/admin/users/show.rhtml:9 app/views/admin/users/_form.rhtml:14
+#: app/views/admin/users/show.rhtml:9
+#, fuzzy
+msgid "Prefered language:"
+msgstr "Utilisateur|Langage préféré"
+
+#: app/views/admin/users/show.rhtml:10 app/views/admin/users/_form.rhtml:13
 msgid "Administrator?"
 msgstr "Administrateur ?"
 
-#: app/views/admin/users/show.rhtml:10
+#: app/views/admin/users/show.rhtml:11
 msgid "Entry Status"
 msgstr "État de l'entrée"
 
-#: app/views/admin/users/show.rhtml:11
+#: app/views/admin/users/show.rhtml:12
 msgid "First Created:"
 msgstr "Entrée Initialement Créée :"
 
-#: app/views/admin/users/show.rhtml:12
+#: app/views/admin/users/show.rhtml:13
 msgid "Last Updated:"
 msgstr "Entrée Dernièrement Mise à jour :"
 
-#: app/views/admin/users/show.rhtml:18
+#: app/views/admin/users/show.rhtml:19
 msgid "Display all users"
 msgstr "Afficher tous les utilisateurs"
 
-#: app/views/admin/users/_form.rhtml:15
+#: app/views/admin/users/_form.rhtml:12
+msgid "Prefered language"
+msgstr "Langage préféré"
+
+#: app/views/admin/users/_form.rhtml:14
 msgid "Password"
 msgstr "Mot de passe"
 
-#: app/views/admin/users/_form.rhtml:16
+#: app/views/admin/users/_form.rhtml:15
 msgid "Password (confirmation)"
 msgstr "Mot de passe (confirmation)"
 
@@ -748,7 +761,7 @@ msgid "Artwork Set #%u"
 msgstr "Série n°%u"
 
 #: app/views/admin/artwork_sets/show.rhtml:13
-#: app/views/admin/artworks/show.rhtml:50
+#: app/views/admin/artworks/show.rhtml:52
 msgid "Display all sets"
 msgstr "Afficher toutes les Séries"
 
@@ -833,7 +846,7 @@ msgid "Steps"
 msgstr "Étapes"
 
 #: app/views/admin/artworks/index.rhtml:24
-#: app/views/admin/artworks/show.rhtml:49
+#: app/views/admin/artworks/show.rhtml:51
 msgid "View Steps"
 msgstr "Voir les Étapes"
 
@@ -841,59 +854,59 @@ msgstr "Voir les Étapes"
 msgid "Artwork '%s'"
 msgstr "Œuvre '%s'"
 
-#: app/views/admin/artworks/show.rhtml:12
+#: app/views/admin/artworks/show.rhtml:14
 #: app/views/admin/artworks/_form.rhtml:11
 msgid "General"
 msgstr "Général"
 
-#: app/views/admin/artworks/show.rhtml:27
+#: app/views/admin/artworks/show.rhtml:29
 msgid "Set / Group:"
 msgstr "Série / Ensemble :"
 
-#: app/views/admin/artworks/show.rhtml:28
+#: app/views/admin/artworks/show.rhtml:30
 #: app/views/admin/artworks/_form.rhtml:26
 msgid "Size:"
 msgstr "Dimensions :"
 
-#: app/views/admin/artworks/show.rhtml:29
+#: app/views/admin/artworks/show.rhtml:31
 #: app/views/admin/artworks/_form.rhtml:28
 msgid "Materials:"
 msgstr "Matériaux :"
 
-#: app/views/admin/artworks/show.rhtml:30
+#: app/views/admin/artworks/show.rhtml:32
 msgid "Supports:"
 msgstr "Supports :"
 
-#: app/views/admin/artworks/show.rhtml:32
+#: app/views/admin/artworks/show.rhtml:34
 #: app/views/admin/artworks/_form.rhtml:31
 msgid "Result"
 msgstr "Résultat"
 
-#: app/views/admin/artworks/show.rhtml:33
+#: app/views/admin/artworks/show.rhtml:35
 #: app/views/admin/artworks/_form.rhtml:32
 msgid "Condition:"
 msgstr "État :"
 
-#: app/views/admin/artworks/show.rhtml:34
+#: app/views/admin/artworks/show.rhtml:36
 #: app/views/admin/artworks/_form.rhtml:33
 msgid "Placement"
 msgstr "Placement"
 
-#: app/views/admin/artworks/show.rhtml:35
+#: app/views/admin/artworks/show.rhtml:37
 #: app/views/admin/artworks/_form.rhtml:34
 msgid "Reason:"
 msgstr "Raison :"
 
-#: app/views/admin/artworks/show.rhtml:36
+#: app/views/admin/artworks/show.rhtml:38
 #: app/views/admin/artworks/_form.rhtml:36
 msgid "Location:"
 msgstr "Lieu :"
 
-#: app/views/admin/artworks/show.rhtml:40
+#: app/views/admin/artworks/show.rhtml:42
 msgid "Artwork Status"
 msgstr "État de l'Œuvre"
 
-#: app/views/admin/artworks/show.rhtml:49
+#: app/views/admin/artworks/show.rhtml:51
 msgid "View all Steps"
 msgstr "Voir toutes les Étapes"
 
@@ -949,3 +962,14 @@ msgstr "Voir tous les ensembles"
 msgid "Modify Artwork Group"
 msgstr "Modifier l'Ensemble"
 
+#: lib/mycyma.rb:32
+msgid "Browser preference"
+msgstr "Préférence du navigateur"
+
+#: lib/mycyma.rb:33
+msgid "English"
+msgstr "Anglais"
+
+#: lib/mycyma.rb:34
+msgid "French"
+msgstr "Français"
