module Padrino::Localization::Urls::ClassMethods

Public Instance Methods

url_with_locale(*args) click to toggle source

Generates an URL with a current locale, for a resource, inside of application.

Example:

url_for_with_locale(:users) # /ru/users

url_for_with_locale('/') # /ru/

url_for_with_locale(:posts, :new, :locale => 'se') # /se/posts/new
# File lib/padrino-localization.rb, line 31
def url_with_locale *args
  opts = args.extract_options!
  locale_scope = opts.delete(:locale) || ::I18n.locale
  locale_scope = ::I18n.locale unless Padrino::Localization::Middleware.languages.include?(locale_scope.to_s)
  args << opts
  link = url_without_locale *args
  link.insert(0,"/#{locale_scope}") if (locale_scope.to_s != ::I18n.default_locale.to_s)
  link
end