Skip to content

Commit d4d3bbe

Browse files
authored
Update to v0.4.0
1 parent bf433d6 commit d4d3bbe

File tree

8 files changed

+357
-32
lines changed

8 files changed

+357
-32
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Options | Use
3838
-n\|--nocolor|Disable color output
3939
--debug|Enable debug mode
4040
--help\|-?|Print usage and a short help message and exit
41+
--locale LANG|Override environment to select another language
4142
--version|Print version and exit
4243
--|Options processing terminator
4344

@@ -92,3 +93,6 @@ the verbs conjugated with the "être" auxiliary when used with a pronoun for exa
9293

9394
Though the software is probably mostly correct, I will consider it as Beta quality
9495
till I get a better idea of the quality of the source data and offer a way to improve it...
96+
97+
The *--lang* command line option does not always work correctly when selecting en(glish).
98+

man/conjuguer.1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.Dd September 24, 2021
1+
.Dd October 2, 2021
22
.Dt CONJUGUER 1
33
.Os
44
.Sh NAME
@@ -51,6 +51,9 @@ Enable debug mode
5151
.Op Fl -help|-?
5252
Print usage and this help message and exit
5353
.Pp
54+
.Op Fl -locale Ar LANG
55+
Override environment to select another language
56+
.Pp
5457
.Op Fl -version
5558
Print version and exit
5659
.Pp
@@ -115,3 +118,7 @@ the verbs conjugated with the "etre" auxiliary when used with a pronoun for exam
115118
.Pp
116119
Though the software is probably mostly correct, I will consider it as Beta quality till I get
117120
a better idea of the quality of the source data and offer a way to improve it...
121+
.Pp
122+
The
123+
.Fl -lang
124+
command line option does not always work correctly when selecting en(glish).

setup.cfg

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = pnu_conjuguer
33
description = conjugaison des verbes Français
44
long_description = file: README.md
55
long_description_content_type = text/markdown
6-
version = 0.3.0
6+
version = 0.4.0
77
license = BSD 3-Clause License
88
license_files = License
99
author = Hubert Tournier
@@ -25,6 +25,16 @@ classifiers =
2525
Operating System :: Microsoft :: Windows
2626
Programming Language :: Python :: 3
2727
Programming Language :: Python :: 3.0
28+
Programming Language :: Python :: 3.1
29+
Programming Language :: Python :: 3.2
30+
Programming Language :: Python :: 3.3
31+
Programming Language :: Python :: 3.4
32+
Programming Language :: Python :: 3.5
33+
Programming Language :: Python :: 3.6
34+
Programming Language :: Python :: 3.7
35+
Programming Language :: Python :: 3.8
36+
Programming Language :: Python :: 3.9
37+
Programming Language :: Python :: 3.10
2838
Topic :: Education
2939
Topic :: Education :: Computer Aided Instruction (CAI)
3040
Topic :: Text Processing :: Linguistic

src/conjuguer/Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,15 @@ format: /usr/local/bin/black
4646
${NAME}.${SECTION}.gz: ../../man/${NAME}.${SECTION}
4747
@gzip -k9c ../../man/${NAME}.${SECTION} > ${NAME}.${SECTION}.gz
4848

49-
po/fr/${NAME}.mo:
49+
po/${NAME}.pot:
50+
@mkdir po
51+
@xgettext --language=Python -o po/${NAME}.pot *.py
52+
53+
po/fr/${NAME}.po: po/${NAME}.pot
54+
@mkdir -p po/fr
55+
@msginit --locale=fr --input=po/${NAME}.pot --output=po/fr/${NAME}.po
56+
57+
po/fr/${NAME}.mo: po/fr/${NAME}.po
5058
@msgfmt --output-file=po/fr/${NAME}.mo po/fr/${NAME}.po
5159

5260
install: ${NAME}.${SECTION}.gz po/fr/${NAME}.mo

src/conjuguer/main.py

Lines changed: 71 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
import colorama
1818

19-
from .verbs import aux, etre_aux, both_aux
19+
from .verbs import aux, etre_aux, both_aux, patterns
2020
from .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
2626
parameters = {
@@ -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
################################################################################
100101
def 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
################################################################################
609645
def 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)

src/conjuguer/po/conjuguer.pot

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
#, fuzzy
88
msgid ""
99
msgstr ""
10-
"Project-Id-Version: conjuguer 0.3.0\n"
10+
"Project-Id-Version: conjuguer 0.4.0\n"
1111
"Report-Msgid-Bugs-To: hubert.tournier@gmail.com\n"
12-
"POT-Creation-Date: 2021-09-19 10:30:+0100\n"
13-
"PO-Revision-Date: \n"
12+
"POT-Creation-Date: 2021-09-19 10:30:+0200\n"
13+
"PO-Revision-Date: 2021-10-02 15:26:+0200\n"
1414
"Last-Translator: Hubert Tournier <hubert.tournier@gmail.com>\n"
1515
"Language-Team: \n"
1616
"Language: en\n"
@@ -21,7 +21,7 @@ msgstr ""
2121
#: main.py
2222
#, python-format
2323

24-
msgid "usage: conjuguer [--debug] [--help|-?] [--version]"
24+
msgid "usage: conjuguer [--debug] [--help|-?] [--locale LANG] [--version]"
2525
msgstr ""
2626

2727
msgid "[-c|--columns NUMBER] [-d|--dictionary PATH] [-n|--nocolor]"
@@ -48,6 +48,9 @@ msgstr ""
4848
msgid "--help|-? Print usage and this help message and exit"
4949
msgstr ""
5050

51+
msgid "--locale LANG Override environment to select another language"
52+
msgstr ""
53+
5154
msgid "--version Print version and exit"
5255
msgstr ""
5356

@@ -105,6 +108,27 @@ msgstr ""
105108
msgid "Infinitif passé not found for"
106109
msgstr ""
107110

111+
msgid "auxiliary"
112+
msgstr ""
113+
114+
msgid "1st group"
115+
msgstr ""
116+
117+
msgid "2nd group"
118+
msgstr ""
119+
120+
msgid "3rd group"
121+
msgstr ""
122+
123+
msgid "unknown group"
124+
msgstr ""
125+
126+
msgid "model for verbs like"
127+
msgstr ""
128+
129+
msgid "conjugated like"
130+
msgstr ""
131+
108132
msgid "Conjugation tables for"
109133
msgstr ""
110134

@@ -117,3 +141,6 @@ msgstr ""
117141
msgid "is not in the dictionary used"
118142
msgstr ""
119143

144+
msgid "If it really exists, it would be"
145+
msgstr ""
146+

0 commit comments

Comments
 (0)