Topic: login and localization

Hi,

In my app I need to handle user login and localization to support multiple languages. At a first glance Tobias Luetkes SaltedHashLoginGenerator with it's localization dependency seemed like a good candidate. I have it all set up and I've played around with it for a while. To me this seems quite ok, but I haven't really anything to compare with, since I haven't done anything like this before.

I've seen some people on different forums complaining about setting up the SHLG. But once it's up and running are there any other performance issues that I should think about?

The localization gem stores the different language strings in yaml files, I've seen other localization plugins that uses databases, is that a better choice? And how do I handle different dates and times? Are there any other performance related things to take into consideration when to choose localization technique?

   Thanks in advance,
   P

Re: login and localization

I'm using the SHLG for one of my projects together with the localization gem.

I imagine a call to a static yaml file would be faster than database calls. Also its simplicity allows me to have non-technical people edit it directly. On the downside I do have to restart mongrel every time I update the translation yaml file.

As for the SHLG itself, I use the generator it supplies as a 'scaffold' of the login system and then remove and add the little features and views I need or don't need for my project. The generated code looks very clean and it's quite easy to maintain.

I don't think the Localization generator handles dates and such, but it'd be easy enough to build a simple helper. Maybe something like this:

# In application_helper.rb

# First define formats for each region
DATE_FORMATS = [
  { :country_code => 'us', :dateformat => '%m/%d/%Y' },
  { :country_code => 'eu', :dateformat => '%d-%m-%Y' },
].freeze

# Return a formatted date string from a time object and a region code string
def fmt_date( time, region )
  # Find the format hash that belongs to the requested region code
  df = DATE_FORMATS.find{ |x| x[:country_code] == region }
  # If it wasn't found return the localized "invalid_region" string
  if( df.nil? )
    l(:invalid_region)
  else
    # Otherwise format the date according to the format in our hash
    time.strftime( df[:dateformat] )
  end
end


# In your views:

<%= fmt_date(Time.new, "eu") %>


edit: typos >_<

Last edited by marsvin (2006-11-27 13:42:30)

Re: login and localization

Thanks for the answer, think I'll stick to this configuration then. I also liked the idea of having the different translations in separate files, so that ohter than me could do the actual translation.

Thank you for the code as well, I'll try to incorporate that soon!
/P