class RailsTranslateRoutes

This class knows nothing about Rails.root or Rails.application.routes, and therefore is easier to test without a Rails app.

Constants

LOCALE_PARAM_KEY
ROUTE_HELPER_CONTAINER
TRANSLATABLE_SEGMENT

Attributes

dictionary[RW]

Attributes

Public Class Methods

init_from_file(file_path) click to toggle source

Creates a RailsTranslateRoutes instance and reads the translations from a specified file

# File lib/rails-translate-routes.rb, line 94
def init_from_file file_path
  new.tap do |t|
    t.load_dictionary_from_file file_path
  end
end
init_with_i18n(*wanted_locales) click to toggle source

Creates a RailsTranslateRoutes instance, using I18n dictionaries of your app

# File lib/rails-translate-routes.rb, line 78
def init_with_i18n *wanted_locales
  new.tap do |t|
    t.init_i18n_dictionary *wanted_locales
  end
end
init_with_yield(&block) click to toggle source

Creates a RailsTranslateRoutes instance and evaluates given block with an empty dictionary

# File lib/rails-translate-routes.rb, line 86
def init_with_yield &block
  new.tap do |t|
    t.yield_dictionary &block
  end
end
locale_suffix(locale) click to toggle source

Default locale suffix generator

# File lib/rails-translate-routes.rb, line 72
def locale_suffix locale
  locale.to_s.underscore
end

Public Instance Methods

available_locales() click to toggle source
# File lib/rails-translate-routes.rb, line 19
def available_locales
  @available_locales ||= I18n.available_locales.map(&:to_s)
end
available_locales=(locales) click to toggle source
# File lib/rails-translate-routes.rb, line 23
def available_locales= locales
  @available_locales = locales.map(&:to_s)
end
default_locale() click to toggle source
# File lib/rails-translate-routes.rb, line 27
def default_locale
  @default_locale ||= I18n.default_locale.to_s
end
default_locale=(locale) click to toggle source
# File lib/rails-translate-routes.rb, line 31
def default_locale= locale
  @default_locale = locale.to_s
end
default_locale?(locale) click to toggle source
# File lib/rails-translate-routes.rb, line 35
def default_locale? locale
  default_locale == locale.to_s
end
keep_untranslated_routes() click to toggle source

option allowing to keep untranslated routes *Ex:

*resources :users
*translated routes
  en/members
  fr/membres
  /users
# File lib/rails-translate-routes.rb, line 62
def keep_untranslated_routes
  @keep_untranslated_routes ||= false
end
keep_untranslated_routes=(keep_untranslated_routes) click to toggle source
# File lib/rails-translate-routes.rb, line 66
def keep_untranslated_routes= keep_untranslated_routes
  @keep_untranslated_routes = keep_untranslated_routes
end
locale_suffix(locale) click to toggle source
# File lib/rails-translate-routes.rb, line 377
def locale_suffix locale
  self.class.locale_suffix locale
end
no_prefixes() click to toggle source
# File lib/rails-translate-routes.rb, line 47
def no_prefixes
  @no_prefixes ||= false
end
no_prefixes=(no_prefixes) click to toggle source
# File lib/rails-translate-routes.rb, line 51
def no_prefixes= no_prefixes
  @no_prefixes = no_prefixes
end
prefix_on_default_locale() click to toggle source
# File lib/rails-translate-routes.rb, line 39
def prefix_on_default_locale
  @prefix_on_default_locale ||= I18n.default_locale.to_s
end
prefix_on_default_locale=(locale) click to toggle source
# File lib/rails-translate-routes.rb, line 43
def prefix_on_default_locale= locale
  @prefix_on_default_locale = locale.to_s
end