Skip to content


added 'url_segments' namespace in yaml input translations file #8

wants to merge 1 commit into from

4 participants


Old way:

  products: productos
  contact: contacto

New way (now wrapped into a namespace):

    products: productos
    contact: contacto

I had to introduce a namespace because I had a I18n translation in my app which collided with one of my url segment translations.

On another topic, I'm willing to write a few tests, but right now I have errors when I try to run ruby test/test_rails-translate-routes.rb :(


Hey, seems ok to me. Thanks! I'll try to add and documentate it this week.

I'll be quite busy making it work with rails 3.2, I just started but still have to see how the new engine works. After I have a new version for it next step will be to add some testing. ;)


I'm curious, when do you think you'll have a Rails 3.2 compatible version?


Hey Martin,

I spend some hours this week trying to make it work and pulling my hair out XD I got how to retrieve the regular, named & engine routes from Journey but still have to figure out how to remove routes and add them.


Just ran into the same collision problem as @cawel, so found this issue. Is this going to be merged soon?


francesc: I have recently upgraded a personal project from Rails < 3.2 to Rails 3.2.3 and I found no problem with that commit (which I put on top of your latest master branch) which allows us to introduce a namespace into our url segment translations.

Any plans to integrate it into the main repo?


Same problem.

My workaround:
Put routes translations in: config/routes.yml
and in router.rb:



Hey. Sorry for the delay, I'll release a new version today to fix this and other small improvements. It will use a :routes namespace on the yaml.

# you can leave empty locales, for example the default one, don't forget the routes namespace
products: productos
contact: contacto

@francesc francesc closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 23, 2012
Showing with 5 additions and 4 deletions.
  1. +5 −4 lib/rails-translate-routes.rb
9 lib/rails-translate-routes.rb
@@ -5,6 +5,7 @@
class RailsTranslateRoutes
TRANSLATABLE_SEGMENT = /^([\w-]+)(\()?/.freeze
LOCALE_PARAM_KEY = :locale.freeze
+ URL_SEGMENTS_NAMESPACE = "url_segments"
@@ -116,9 +117,9 @@ def load_dictionary_from_file file_path
# Add translations from another file to the dictionary.
def add_dictionary_from_file file_path
yaml = YAML.load_file(file_path)
- yaml.each_pair do |locale, translations|
- merge_translations locale, translations
- end
+ locale = yaml.keys.first
+ translations = yaml[locale][URL_SEGMENTS_NAMESPACE]
+ merge_translations locale, translations
@@ -139,7 +140,7 @@ def init_i18n_dictionary *wanted_locales
wanted_locales.each do |locale|
@dictionary[locale] = do |hsh, key|
- hsh[key] = I18n.translate key, :locale => locale #DISCUSS: caching or no caching (store key and translation in dictionary?)
+ hsh[key] = I18n.translate(URL_SEGMENTS_NAMESPACE + "." + key, :locale => locale) #DISCUSS: caching or no caching (store key and translation in dictionary?)
@available_locales = &:to_s
Something went wrong with that request. Please try again.