Module GibberishRails::Helper
In: lib/gibberish/gibberish_rails.rb

Methods

Public Instance methods

Gets the "best guess" locale, a parameter is the first prioirity, then the HTTP_ACCEPT_LANGUAGE, finally the default. If some one has a very specific locale, like es-mx, use it if we have it. Otherwise, if we don‘t have es-mx, check for es before giving up…

[Source]

    # File lib/gibberish/gibberish_rails.rb, line 10
10:     def best_guess_locale(locale, accept_header)
11: 
12:       # first try es-mx
13:       return locale if locale && Gibberish.supported?(locale)
14: 
15:       # now try es
16:       locale = locale[/[^-]+/] if locale
17:       return locale if locale && Gibberish.supported?(locale)
18: 
19:       found_locale = nil
20: 
21:       accept_header.split(',').each do |locale|
22:         locale = locale[/[^,;]+/]
23:         if ( Gibberish.supported?(locale) ) # First try es-mx
24:           found_locale = locale.to_sym
25:           break
26:         end
27:         locale = locale[/[^-]+/]
28:         if ( Gibberish.supported?(locale) ) # Then try es
29:           found_locale = locale.to_sym
30:           break
31:         end
32:       end
33:       if ( ! found_locale )
34:         found_locale = Gibberish.languages.first
35:       end
36:       found_locale
37:     end

[Validate]