1616
1717import colorama
1818
19- from .verbs import aux , etre_aux , both_aux
19+ from .verbs import aux , etre_aux , both_aux , patterns
2020from .blank import blank_verb
2121
2222# Version string used by the what(1) and ident(1) commands:
23- ID = "@(#) $Id: conjuguer - conjugaison des verbes Français v0.3 .0 (September 24 , 2021) by Hubert Tournier $"
23+ ID = "@(#) $Id: conjuguer - conjugaison des verbes Français v0.4 .0 (October 2 , 2021) by Hubert Tournier $"
2424
2525# Default parameters. Can be overcome by environment variables, then command line options
2626parameters = {
@@ -57,20 +57,21 @@ def initialize_debugging(program_name):
5757
5858
5959################################################################################
60- def initialize_internationalization (program_name ):
60+ def initialize_internationalization (program_name , lang = locale . getdefaultlocale ()[ 0 ][: 2 ] ):
6161 """Internationalization set up"""
62- lang = locale .getdefaultlocale ()[0 ][:2 ]
6362 locale_dirs = []
6463
6564 if os .name == "posix" :
66- if os .path .isdir ("/usr/share/locale" ):
67- locale_dirs .append ("/usr/share/locale" )
68- if os .path .isdir ("/usr/local/share/locale" ):
69- locale_dirs .append ("/usr/local/share/locale" )
65+ # local packages override system packages:
7066 if "HOME" in os .environ .keys ():
7167 home = os .environ ["HOME" ]
7268 if os .path .isdir (home + os .sep + ".local/share/locale" ):
7369 locale_dirs .append (home + os .sep + ".local/share/locale" )
70+
71+ if os .path .isdir ("/usr/share/locale" ):
72+ locale_dirs .append ("/usr/share/locale" )
73+ if os .path .isdir ("/usr/local/share/locale" ):
74+ locale_dirs .append ("/usr/local/share/locale" )
7475 elif os .name == "nt" :
7576 appdata_path = os .sep + "appdata" + os .sep + "roaming"
7677 locale_suffix = os .sep + "python" + os .sep + "share" + os .sep + "locale"
@@ -99,7 +100,7 @@ def initialize_internationalization(program_name):
99100################################################################################
100101def display_help ():
101102 """Displays usage and help"""
102- print (_ ("usage: conjuguer [--debug] [--help|-?] [--version]" ), file = sys .stderr )
103+ print (_ ("usage: conjuguer [--debug] [--help|-?] [--locale LANG] [-- version]" ), file = sys .stderr )
103104 print (
104105 " "
105106 + _ ("[-c|--columns NUMBER] [-d|--dictionary PATH] [-n|--nocolor]" ),
@@ -121,6 +122,10 @@ def display_help():
121122 " " + _ ("--help|-? Print usage and this help message and exit" ),
122123 file = sys .stderr
123124 )
125+ print (
126+ " " + _ ("--locale LANG Override environment to select another language" ),
127+ file = sys .stderr
128+ )
124129 print (" " + _ ("--version Print version and exit" ), file = sys .stderr )
125130 print (" " + _ ("-- Options processing terminator" ), file = sys .stderr )
126131 print (file = sys .stderr )
@@ -183,7 +188,7 @@ def process_environment_variables():
183188 if os .path .isdir (pnu_dictpath ):
184189 parameters ["DictPath" ].append (pnu_dictpath )
185190
186- pnu_dictpath2 = sys .executable . replace ( "python.exe" , "share" + os .sep + "dict" )
191+ pnu_dictpath2 = sys .base_prefix + os . sep + "share" + os .sep + "dict"
187192 if os .path .isdir (pnu_dictpath2 ):
188193 parameters ["DictPath" ].append (pnu_dictpath2 )
189194
@@ -218,7 +223,7 @@ def process_environment_variables():
218223
219224
220225################################################################################
221- def process_command_line ():
226+ def process_command_line (program_name ):
222227 """Process command line options"""
223228 # pylint: disable=C0103
224229 global parameters
@@ -232,6 +237,7 @@ def process_command_line():
232237 "debug" ,
233238 "dictionary=" ,
234239 "help" ,
240+ "locale=" ,
235241 "nocolor" ,
236242 "version" ,
237243 ]
@@ -277,6 +283,9 @@ def process_command_line():
277283 display_help ()
278284 sys .exit (0 )
279285
286+ elif option == "--locale" :
287+ initialize_internationalization (program_name , argument )
288+
280289 elif option in ("-n" , "--nocolor" ):
281290 parameters ["Color display" ] = False
282291
@@ -605,9 +614,37 @@ def conjuguer(verb, conjugations, auxiliary):
605614 return conjugated_verb
606615
607616
617+ ################################################################################
618+ def analyze_verb (verb ):
619+ """Return a verb pattern, group and conjugation model"""
620+ group = None
621+ group_text = ""
622+ model = ""
623+
624+ for key in patterns .keys ():
625+ if verb .endswith (key ):
626+ group = patterns [key ][0 ]
627+ model = patterns [key ][1 ]
628+ break
629+
630+ if group == 0 :
631+ group_text = _ ("auxiliary" )
632+ elif group == 1 :
633+ group_text = _ ("1st group" )
634+ elif group == 2 :
635+ group_text = _ ("2nd group" )
636+ elif group == 3 :
637+ group_text = _ ("3rd group" )
638+ else :
639+ group_text = _ ("unknown group" )
640+
641+ return key , group_text , model
642+
643+
608644################################################################################
609645def print_verb (verb ):
610646 """Return lines describing the conjugated verb"""
647+ pattern , group , model = analyze_verb (verb )
611648 lines = []
612649 if parameters ["Color display" ]:
613650 lines .append (
@@ -619,6 +656,12 @@ def print_verb(verb):
619656 )
620657 else :
621658 lines .append (_ ("Conjugation tables for" ) + " " + verb )
659+
660+ if verb == model :
661+ lines .append (group + ", " + _ ("model for verbs like" ) + " *" + pattern )
662+ else :
663+ lines .append (group + ", " + _ ("conjugated like" ) + " " + model )
664+
622665 lines .append ("" )
623666
624667 return lines
@@ -926,18 +969,19 @@ def main():
926969 initialize_debugging (program_name )
927970 initialize_internationalization (program_name )
928971 process_environment_variables ()
929- arguments = process_command_line ()
930-
931- if parameters ["Dictionary type" ] not in ("ABU" , "DELA" ):
932- logging .debug (_ ("Unknown inflected dictionary format" ))
933- sys .exit (1 )
934- verbs = load_all_verbs_from_dictionary ()
972+ arguments = process_command_line (program_name )
935973
936974 if not arguments :
937975 logging .critical (_ ("conjuguer expects at least one argument" ))
938976 display_help ()
939977 sys .exit (1 )
940978
979+ if parameters ["Dictionary type" ] not in ("ABU" , "DELA" ):
980+ logging .debug (_ ("Unknown inflected dictionary format" ))
981+ sys .exit (1 )
982+
983+ verbs = load_all_verbs_from_dictionary ()
984+
941985 exit_status = 0
942986 for argument in arguments :
943987 conjugations = select_verb_from_verbs (argument , verbs )
@@ -955,6 +999,16 @@ def main():
955999 print_verb_conjugation (verb )
9561000 else :
9571001 logging .error ("%s " + _ ("is not in the dictionary used" ), argument )
1002+ pattern , group , model = analyze_verb (argument )
1003+ print (
1004+ _ ("If it really exists, it would be" )
1005+ + " "
1006+ + group
1007+ + ", "
1008+ + _ ("conjugated like" )
1009+ + " "
1010+ + model
1011+ )
9581012 exit_status = 1
9591013
9601014 sys .exit (exit_status )
0 commit comments