I’d like to translate the OpenIdAuthentication plugin into another language but I’d like not to change the plugin directly.
Here’s the basic structure of the messages I want to translate:
module OpenIdAuthentication class Result ERROR_MESSAGES = { :missing => 'Sorry, the OpenID server couldn't be found', :invalid => 'Sorry, but this does not appear to be a valid OpenID', :canceled => 'OpenID verification was canceled', :failed => 'OpenID verification failed', :setup_needed => 'OpenID verification needs setup' } end end
It is something possible to translate them without changing the plugin directly?
Thanks!
You can simply overwrite
OpenIdAuthentication::Result::ERROR_MESSAGESby redefining it at any time after the plugin loads.You may do so through a different plugin (that loads after
OpenIdAuthentication), or from a file required after the plugin loads (e.g.require lib/open_id_authentication_suppl.rbinenvironment.rb):The code will essentially be a copy-paste job, as follows:
To integrate this with I18N-rails (built into Rails 2.2.2, available as a gem/plugin in previous versions), do:
Then define and load your I18n yml file for
openidauthentication.errors.messages‘s various locales on Rails startup, and don’t forget to set yourI18n.localeevery time you start processing a controller action based on the logged-in user’s locale.