@@ -42,7 +42,8 @@ use std::path::{Path, PathBuf};
42
42
use rand:: seq:: SliceRandom ;
43
43
44
44
use rocket:: {
45
- http:: Status ,
45
+ http:: { RawStr , Status } ,
46
+ request:: { FromParam , Request } ,
46
47
response:: { NamedFile , Redirect } ,
47
48
} ;
48
49
use rocket_contrib:: templates:: Template ;
@@ -89,7 +90,12 @@ fn get_title(page_name: &str) -> String {
89
90
90
91
#[ get( "/components/<_file..>" , rank = 1 ) ]
91
92
fn components ( _file : PathBuf ) -> Template {
92
- not_found ( )
93
+ not_found_locale ( ENGLISH . into ( ) )
94
+ }
95
+
96
+ #[ get( "/<locale>/components/<_file..>" , rank = 11 ) ]
97
+ fn components_locale ( locale : SupportedLocale , _file : PathBuf ) -> Template {
98
+ not_found_locale ( locale. 0 )
93
99
}
94
100
95
101
#[ get( "/logos/<file..>" , rank = 1 ) ]
@@ -204,7 +210,21 @@ fn redirect_locale(_locale: redirect::Locale, dest: redirect::Destination) -> Re
204
210
}
205
211
206
212
#[ catch( 404 ) ]
207
- fn not_found ( ) -> Template {
213
+ fn not_found ( req : & Request ) -> Template {
214
+ let lang = if let Some ( next) = req. uri ( ) . segments ( ) . next ( ) {
215
+ if let Ok ( lang) = SupportedLocale :: from_param ( RawStr :: from_str ( next) ) {
216
+ lang. 0
217
+ } else {
218
+ ENGLISH . into ( )
219
+ }
220
+ } else {
221
+ ENGLISH . into ( )
222
+ } ;
223
+
224
+ not_found_locale ( lang)
225
+ }
226
+
227
+ fn not_found_locale ( lang : String ) -> Template {
208
228
let page = "404" ;
209
229
let title = format ! ( "{} - Rust programming language" , page) . to_string ( ) ;
210
230
let context = Context {
@@ -213,7 +233,7 @@ fn not_found() -> Template {
213
233
parent : LAYOUT . to_string ( ) ,
214
234
is_landing : false ,
215
235
data : ( ) ,
216
- lang : ENGLISH . to_string ( ) ,
236
+ lang,
217
237
baseurl : String :: new ( ) ,
218
238
pontoon_enabled : pontoon_enabled ( ) ,
219
239
} ;
@@ -222,7 +242,7 @@ fn not_found() -> Template {
222
242
223
243
#[ catch( 500 ) ]
224
244
fn catch_error ( ) -> Template {
225
- not_found ( )
245
+ not_found_locale ( ENGLISH . into ( ) )
226
246
}
227
247
228
248
fn compile_sass ( filename : & str ) {
@@ -420,6 +440,7 @@ fn main() {
420
440
team_locale,
421
441
production_locale,
422
442
subject_locale,
443
+ components_locale,
423
444
redirect,
424
445
redirect_pdfs,
425
446
redirect_bare_en_us,
0 commit comments