I use The Bootstrap Flash Message Gem and jruby 1.7.0 and have a problem with foreign characters and umlaut in the Flash Message.
Everything works fine when I use a 'normal' ruby like ruby-1.9.3. flash_messages.inspect outputs:
" Felix Meier a été inscrit au sous-groupe 'Administrators'."
but with jruby-1.7.0 the exacltly same Code produces:
" Felix Meier a \xC3\xA9t\xC3\xA9 enlev\xC3\xA9 du sous-groupe 'Administrators'." and I get an Error
ActionView::Template::Error (incompatible character encodings: UTF-8 and ASCII-8BIT):
So the question is: Am I doing something wrong, is jruby doing something wrong or the Bootstrap Flash Message Gem the problem?
I tried some stuff on the console but could't reproduce the problem (indication that Flash Message ist the problem?):
jruby-1.7.0 :005 > q="Felix Meier a été inscrit au sous-groupe 'Administrators'"
=> "Felix Meier a été inscrit au sous-groupe 'Administrators'"
jruby-1.7.0 :006 > CGI.unescape(q)
=> "Felix Meier a été inscrit au sous-groupe 'Administrators'"
jruby-1.7.0 :007 > CGI.unescape(q).encoding.name
=> "UTF-8"
jruby-1.7.0 :008 > CGI.unescape(q).valid_encoding?
=> true
jruby-1.7.0 :009 > r="Felix Meier a \xC3\xA9t\xC3\xA9 enlev\xC3\xA9 du sous-groupe 'Administrators'"
=> "Felix Meier a été enlevé du sous-groupe 'Administrators'"
jruby-1.7.0 :010 > CGI.unescape(r)
=> "Felix Meier a été enlevé du sous-groupe 'Administrators'"
jruby-1.7.0 :011 > CGI.unescape(r).encoding.name
=> "UTF-8"
Related
I18n cant find the translation even if the translation is present in my YML,
translation missing: fr.activerecord.errors.models.user.attributes.email.not_found
errors:
messages:
already_confirmed: a déjà été confirmé(e)
confirmation_period_expired: doit être confirmé(e) en %{period}, veuillez en demander un(e) autre
expired: est expiré, veuillez en demander un autre
not_found: n’a pas été trouvé(e)
not_locked: n’était pas verrouillé(e)
not_saved:
one: 'une erreur a empêché ce (cet ou cette) %{resource} d’être enregistré(e) :'
other: "%{count} erreurs ont empêché ce (cet ou cette) %{resource} d’être enregistré(e) :"
It must follows correctly the "pattern", the locale is the root, in this case fr:
fr:
activerecord:
errors:
models:
user:
attributes:
email:
not_found: Email not found
I need to modify the error messages of devise. I want to change the message "is Invalid" to "Es inválido" . The problem is that I have to go to change these messages in the gem. Can I overwrite these messages in the model User
Rails console
1.9.3-p547 :014 > user.save
=> false
1.9.3-p547 :015 > user.errors
=> {:email=>["is invalid"], :password=>["is too short (minimum is 6 characters)"]}
1.9.3-p547 :016 >
User model
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, :lockable and :timeoutable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
end
Devise Generates a devise.en.yml file in config/locales/
If you need your error messages to be in another language such as Spanish, replace your devise.en.yml with this file:
devise.es.yml
es:
errors:
messages:
expired: "ha expirado, por favor pide una nueva"
not_found: "no encontrado"
already_confirmed: "ya fue confirmada. Intenta ingresar."
not_locked: "no ha sido bloqueada"
not_saved:
one: "Ha habido 1 error:"
other: "Han habido %{count} errores:"
devise:
failure:
already_authenticated: 'Ya iniciaste sesión.'
unauthenticated: 'Tienes que registrarte o iniciar sesión antes de continuar.'
unconfirmed: 'Tienes que confirmar tu cuenta antes de continuar.'
locked: 'Tu cuente está bloqueada.'
invalid: 'Email o contraseña inválidos.'
invalid_token: 'Token de autentificación inválido.'
timeout: 'Tu sesión ha expirado. Inicia sesión nuevamente.'
inactive: 'Tu cuenta aun no ha sido activada.'
sessions:
signed_in: 'Iniciaste sesión correctamente.'
signed_out: 'Cerraste sesión correctamente.'
passwords:
send_instructions: 'Recibirás un email con instrucciones para reiniciar tu contraseña en unos minutos.'
updated: 'Tu contraseña fue cambiada correctamente. Has iniciado sesión.'
updated_not_active: 'Tu contraseña fue cambiada correctamente.'
send_paranoid_instructions: "Si tu email existe en el sistema, recibirás instrucciones para recuperar tu contraseña en él"
confirmations:
send_instructions: 'Recibirás instrucciones para confirmar tu cuenta en tu email en unos minutos.'
send_paranoid_instructions: 'Si tu email existe en el sistema, recibirás instrucciones para confirmar tu cuenta en tu email en unos minutos.'
confirmed: 'Tu cuenta fue confirmada. Has iniciado sesión.'
registrations:
signed_up: 'Bienvenido! Te has registrado correctamente.'
signed_up_but_unconfirmed: 'Te hemos enviado un email con instrucciones para que confirmes tu cuenta.'
signed_up_but_inactive: 'Te has registrado correctamente, pero tu cuenta aun no ha sido activada.'
signed_up_but_locked: 'Te has registrado correctamente, pero tu cuenta está bloqueada.'
updated: 'Actualizaste tu cuenta correctamente.'
update_needs_confirmation: "Actualizaste tu cuenta correctamente, pero tenemos que revalidar tu email. Revisa tu correo para confirmar la dirección."
destroyed: 'Adiós, tu cuenta ha sido eliminada. Esperamos verte de vuelta pronto!'
unlocks:
send_instructions: 'Recibirás un email con instrucciones para desbloquear tu cuenta en unos minutos'
unlocked: 'Tu cuenta ha sido desbloqueada. Inicia sesión para continuar.'
send_paranoid_instructions: 'Si tu cuenta existe, recibirás instrucciones para desbloquear tu cuenta en unos minutos'
omniauth_callbacks:
success: 'Te autentificaste correctamente con tu cuenta de %{kind}.'
failure: 'No pudimos autentificar tu cuenta de %{kind} por la siguiente razón: %{reason}.'
mailer:
confirmation_instructions:
subject: 'Instrucciones de confirmación'
reset_password_instructions:
subject: 'Instrucciones de cambio de contraseña'
unlock_instructions:
subject: 'Instrucciones de desbloqueo'
UPDATE
es:
activerecord:
errors:
models:
user:
attributes:
email:
blank: "El email no puede estar vacio"
This isn't Devise-specific. You can localize any of your ActiveRecord error messages in your config/locales/*.yml files.
In this case, you could, in config/local/es.yml, add something like the following:
es:
activerecord:
errors
models
user
attributes:
email:
invalid: "Es inválido"
Rails' localization is extremely configurable. There is a lot more information in the guides.
You can do the devise specific translations using the
devise.es.yml in your config/locales folder
List of all the different translations is given here in official devise wiki
1.9.3p385 :010 > "Dell Inspiron 14R Laptop".titleize
=> "Dell Inspiron 14 R Laptop"
Did you see that?, A space is added between 14 and R which interferes with my search. Any solution you could think of?
1.9.3p385 :015 > "dell inspiron 14r laptop".titleize
=> "Dell Inspiron 14r Laptop"
1.9.3p385 :016 > "dell inspiron 14R laptop".titleize
=> "Dell Inspiron 14 R Laptop"
1.9.3p385 :017 > "dell inspiron 14R laptop".downcase.titleize
=> "Dell Inspiron 14r Laptop"
The alpha numeric whose alpha part is downcased are not treated as titles. So, doing a downcase and titleizing it saves your day.
I'm trying to translate the steps definitions of cucumber to spanish but I'm getting this error:
Ambiguous match of "que estoy en la página "inicio de sesión""
features/step_definitions/web_steps.rb:3:in `/^que estoy en la página "([^"]*)"$/'
features/step_definitions/web_steps.rb:7:in `/^visito la pa|ágina "([^"]*)"$/'
Here's my web_steps.rb
# encoding: utf-8
Dado /^que estoy en la página "([^"]*)"$/ do |page|
visit(path_to page)
end
Cuando /^visito la página "([^"]*)"$/ do |page|
visit(path_to page)
end
How can that be ambiguos if I got the ^ and the $ in the regexp?
It looks like it's seeing a | in the latter step definition. Look closely at the second line of the error:
features/step_definitions/web_steps.rb:3:in `/^que estoy en la página "([^"]*)"$/'
features/step_definitions/web_steps.rb:7:in `/^visito la pa|ágina "([^"]*)"$/'
It's seeing /^visito la pa|ágina "([^"]*)"$/, which it interprets as an OR, i.e. /^visito la pa OR ágina "([^"]*)"$/. With that interpretation, the match does indeed become ambiguous.
Now why it is reading it that way is a mystery to me, perhaps some UTF-8 garbling?
I am using devise for the user registration... and i want to translate it in French, I get the file traduction :
fr:
errors:
messages:
not_found: "n'a pas été trouvé(e)"
already_confirmed: "a déjà été confirmé(e)"
not_locked: "n'était pas verrouillé(e)"
not_saved:
one: "1 erreur a empéché ce %{resource} d'être sauvegardé:"
other: "%{count} erreurs ont empéché ce %{resource} d'être sauvegardé:"
devise:
shared:
sign_in: "Se connecter"
sign_up: "S'enregistrer"
forgot_password: "Mot de passe oublié ?"
didnt_receive_confirmation_instructions?: "Vous n'avez pas reçu de courriel de confirmation ?"
didnt_receive_unlock_instructions?: "Vous n'avez pas reçu de courriel de déverrouillage de votre compte ?"
sign_in_with_omniauth: "Se connecter avec %{provider}"
.....
.....
And i write this on my config/application.rb :
config.i18n.default_locale = :fr
I have reboot apache but nothing to do, i don't have any traduction on messages as "Sign In Successfull..."
Any idea?
Thank you
My solution was to add
I18n.locale = :fr
If you have a problem with the production environnement, you can use :
config.before_configuration do
I18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}').to_s]
I18n.locale = :fr
I18n.default_locale = :fr
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}').to_s]
config.i18n.locale = :fr
# bypasses rails bug with i18n in production\
I18n.reload!
config.i18n.reload!
end
config.i18n.locale = :fr
config.i18n.default_locale = :fr
In config/application.rb
This is what I just did and it works:
copy devise.fr.yml to config/locales
add "config.i18n.default_locale = :fr" to config/application.rb
reboot mongrel