@@ -5,7 +5,6 @@ use std::{
5
5
env:: args,
6
6
fs:: { create_dir_all, read_to_string} ,
7
7
path:: { Path , PathBuf } ,
8
- process:: exit,
9
8
time:: Instant ,
10
9
} ;
11
10
use sys_locale:: get_locale;
@@ -19,7 +18,6 @@ use write::*;
19
18
mod shuffle;
20
19
use shuffle:: shuffle_words;
21
20
22
- #[ derive( Debug , Clone , Copy ) ]
23
21
enum Language {
24
22
English ,
25
23
Russian ,
@@ -145,8 +143,6 @@ impl<'a> ProgramLocalization<'a> {
145
143
}
146
144
}
147
145
148
- static ALLOWED_LANGUAGES : [ & str ; 2 ] = [ "ru" , "en" ] ;
149
-
150
146
fn get_game_type ( system_file_path : & Path ) -> & str {
151
147
let system_obj: Value = from_str ( & read_to_string ( system_file_path) . unwrap ( ) ) . unwrap ( ) ;
152
148
let game_title: String = system_obj[ "gameTitle" ] . as_str ( ) . unwrap ( ) . to_lowercase ( ) ;
@@ -164,13 +160,15 @@ fn determine_language() -> Language {
164
160
let args_vec: Vec < String > = args ( ) . collect ( ) ;
165
161
166
162
for ( i, arg) in args_vec. iter ( ) . enumerate ( ) {
167
- if ( arg == "-l" || arg == "--language" )
168
- && ALLOWED_LANGUAGES . contains ( & args_vec[ i + 1 ] . as_str ( ) )
169
- {
163
+ if arg == "-l" || arg == "--language" {
170
164
locale = args_vec[ i + 1 ] . to_string ( ) ;
171
165
}
172
166
}
173
167
168
+ if let Some ( ( first, _) ) = locale. split_once ( '_' ) {
169
+ locale = first. to_string ( )
170
+ }
171
+
174
172
match locale. as_str ( ) {
175
173
"ru" | "uk" | "be" => Language :: Russian ,
176
174
_ => Language :: English ,
@@ -222,20 +220,18 @@ fn main() {
222
220
. hide_default_value ( true )
223
221
. display_order ( 2 ) ;
224
222
225
- const ALLOWED_DISABLE_PROCESSING_VALUES : [ & str ; 4 ] = [ "maps" , "other" , "system" , "plugins" ] ;
226
223
let disable_processing_arg: Arg = Arg :: new ( "disable-processing" )
227
224
. long ( "disable-processing" )
228
225
. value_delimiter ( ',' )
229
226
. value_name ( localization. disable_processing_arg_type )
230
227
. help ( cformat ! (
231
- "{}\n {} --disable-processing=maps,other,system.<bold>\n [{} {} ]</bold>" ,
228
+ "{}\n {} --disable-processing=maps,other,system.<bold>\n [{} maps, other, system, plugins ]</bold>" ,
232
229
localization. disable_processing_arg_desc,
233
230
localization. example,
234
231
localization. possible_values,
235
- ALLOWED_DISABLE_PROCESSING_VALUES . join( ", " )
236
232
) )
237
233
. global ( true )
238
- . value_parser ( ALLOWED_DISABLE_PROCESSING_VALUES )
234
+ . value_parser ( [ "maps" , "other" , "system" , "plugins" ] )
239
235
. display_order ( 2 ) ;
240
236
241
237
let disable_custom_parsing_flag: Arg = Arg :: new ( "disable-custom-parsing" )
@@ -251,13 +247,12 @@ fn main() {
251
247
. value_name ( localization. language_arg_type )
252
248
. global ( true )
253
249
. help ( cformat ! (
254
- "{}\n {} --language en.<bold>\n [{} {} ]</bold>" ,
250
+ "{}\n {} --language en.<bold>\n [{} en, ru ]</bold>" ,
255
251
localization. language_arg_desc,
256
252
localization. example,
257
253
localization. possible_values,
258
- ALLOWED_LANGUAGES . join( ", " )
259
254
) )
260
- . value_parser ( ALLOWED_LANGUAGES )
255
+ . value_parser ( [ "en" , "ru" ] )
261
256
. display_order ( 98 ) ;
262
257
263
258
let log_flag: Arg = Arg :: new ( "log" )
@@ -308,7 +303,7 @@ fn main() {
308
303
. hide_possible_values ( true ) ;
309
304
310
305
let matches: ArgMatches = cli. get_matches ( ) ;
311
- let command: & str = matches. subcommand_name ( ) . unwrap_or_else ( || exit ( 1 ) ) ;
306
+ let command: & str = matches. subcommand_name ( ) . unwrap ( ) ;
312
307
313
308
let (
314
309
disable_maps_processing,
@@ -370,10 +365,6 @@ fn main() {
370
365
)
371
366
} ;
372
367
373
- if !maps_path. exists ( ) || !other_path. exists ( ) {
374
- panic ! ( "{}" , localization. translation_dirs_missing) ;
375
- }
376
-
377
368
let system_file_path: PathBuf = original_path. join ( "System.json" ) ;
378
369
379
370
let game_type: & str = if disable_custom_parsing {
@@ -421,11 +412,9 @@ fn main() {
421
412
start_time. elapsed( ) . as_secs_f64( )
422
413
) ;
423
414
} else {
424
- let shuffle_level: u8 = * matches
425
- . subcommand_matches ( command)
426
- . unwrap ( )
427
- . get_one :: < u8 > ( "shuffle_level" )
428
- . unwrap ( ) ;
415
+ if !maps_path. exists ( ) || !other_path. exists ( ) {
416
+ panic ! ( "{}" , localization. translation_dirs_missing) ;
417
+ }
429
418
430
419
let plugins_path: PathBuf = input_dir. join ( "translation/plugins" ) ;
431
420
@@ -438,6 +427,12 @@ fn main() {
438
427
create_dir_all ( & output_path) . unwrap ( ) ;
439
428
create_dir_all ( & plugins_output_path) . unwrap ( ) ;
440
429
430
+ let shuffle_level: u8 = * matches
431
+ . subcommand_matches ( command)
432
+ . unwrap ( )
433
+ . get_one :: < u8 > ( "shuffle_level" )
434
+ . unwrap ( ) ;
435
+
441
436
if !disable_maps_processing {
442
437
write_maps (
443
438
& maps_path,
0 commit comments