@@ -60,7 +60,36 @@ def localized_add_route(action, controller, options, _path, to, via, formatted,
6060 # @set.add_route(mapping, as)
6161
6262 # Our override
63- @set . add_localized_route ( @scope , ast , controller , default_action , to , via , formatted , options_constraints , anchor , options , mapping , as , path , @engine )
63+ _add_localized_route ( @scope , @set , ast , controller , default_action , to , via , formatted , options_constraints , anchor , options , mapping , as , path , @engine )
64+ end
65+
66+
67+ def _add_localized_route ( scope , set , ast , controller , default_action , to , via , formatted , options_constraints , anchor , options , mapping , name , path , engine )
68+ route = RouteTranslator ::Route . new ( set , path , name , options_constraints , options , mapping )
69+ translator = RouteTranslator . translator_for ( engine )
70+
71+ raise RouteTranslator ::TranslatorNotFound , "RouteTranslator is not configured for current engine : #{ engine } " if translator . nil?
72+
73+ translator . translations_for ( route ) do |locale , translated_name , translated_path , translated_options_constraints , translated_options |
74+ translated_path_ast = ::ActionDispatch ::Journey ::Parser . parse ( translated_path )
75+ translated_mapping = _translate_mapping ( locale , set , translated_options , translated_path_ast , scope , controller , default_action , to , formatted , via , translated_options_constraints , anchor )
76+
77+ # call original method
78+ set . add_route translated_mapping , translated_name
79+ end
80+ end
81+
82+
83+ def _translate_mapping ( locale , route_set , translated_options , translated_path_ast , scope , controller , default_action , to , formatted , via , translated_options_constraints , anchor )
84+ scope_params = {
85+ blocks : scope [ :blocks ] || [ ] ,
86+ constraints : scope [ :constraints ] || { } ,
87+ defaults : ( scope [ :defaults ] || { } ) . dup ,
88+ module : scope [ :module ] ,
89+ options : scope [ :options ] ? scope [ :options ] . merge ( translated_options ) : translated_options
90+ }
91+
92+ ::ActionDispatch ::Routing ::Mapper ::Mapping . build scope_params , route_set , translated_path_ast , controller , default_action , to , via , formatted , translated_options_constraints , anchor , translated_options
6493 end
6594
6695 end
0 commit comments