Feature request: custom translation for nested resources
cspeer opened this issue ยท 5 comments
Steps to reproduce*
Expected behavior*
I have defined my route translations like this:
de:
routes:
products: produkte
controllers:
admin:
products: produkte2
and my routes like this:
Rails.application.routes.draw do
localized do
resources :products
namespace :admin do
resources :products
end
end
end
My expectation is that, apart from the english routes, I would get the following ones:
- /de/produkte
- /de/admin/produkte2
Actual behavior*
Instead I get these routes:
- /de/produkte
- /de/admin/produkte
If I leave out the controllers
part in my translation file like this:
de:
routes:
products: produkte
admin:
products: produkte2
The app won't boot anymore and I get this error:
Can't convert Hash into String
System configuration*
Rails version:
Rails 6.1.4.4
Ruby version:
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin20]
Route Translator version:
route_translator (12.1.0)
I18n configuration*
require_relative "boot"
require "rails/all"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module RoutingI18n
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 6.1
# Configuration for the application, engines, and railties goes here.
#
# These settings can be overridden in specific environments using the files
# in config/environments, which are processed later.
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")
I18n.available_locales = [:en, :de]
I18n.default_locale = :en
end
end
Route Translator initializier
Source of: config/initializers/route_translator.rb
# RouteTranslator.config do |config|
# end
Source code of routes.rb*
See above
Locale .yml
files*
Source of config/locales/de.yml
See above
Output of rails routes
*
Repository demostrating the issue
Hi,
thanks for the thorough description of the issue and apologies for the late reply.
I'm surprised too of this behavior, and I've silently tried to investigate and fix this issue just after it has been reported
I do not have much time to invest on route translator, and I'm not using this gem in production environments for at least 3/4 years, so any help and a PR with tests are welcomed.
I'm going to consider this a feature request
At the moment route_translator allows to translate an individual route inside a namespaced controller as described in the readme: https://github.com/enriclluelles/route_translator#translations-for-similar-routes-with-different-namespaces
A new feature to support custom translations of namespaced resources must not use controllers:
namespace, because otherwise it will break the existing functionality
### Nope
routes:
controllers:
namespace:
resource: translation # This will break the existing functionality to translate namespaced routes
It is also not possible to use
### Nope
routes:
namespace:
resource: translation # This will break an existing functionality to translate namespaces themselves
Because otherwise it will not be possible to translate the namespace
itself
Probably we can use something ร -la ActiveModel like namespace/resource
: https://api.rubyonrails.org/classes/ActiveModel/Naming.html
I completely unterstand @tagliala
I'd chip in here but I'm also rather strapped for time right now.
Actually this is already supported and, in retrospect, it was trivial enough ๐
I've added a readme entry and a test case to help
Solution:
de:
routes:
products: produkte
controllers:
admin:
products:
products: produkte2