Skip to content

Commit

Permalink
Update to v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HubTou authored Oct 2, 2021
1 parent bf433d6 commit d4d3bbe
Show file tree
Hide file tree
Showing 8 changed files with 357 additions and 32 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Options | Use
-n\|--nocolor|Disable color output
--debug|Enable debug mode
--help\|-?|Print usage and a short help message and exit
--locale LANG|Override environment to select another language
--version|Print version and exit
--|Options processing terminator

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

Though the software is probably mostly correct, I will consider it as Beta quality
till I get a better idea of the quality of the source data and offer a way to improve it...

The *--lang* command line option does not always work correctly when selecting en(glish).

9 changes: 8 additions & 1 deletion man/conjuguer.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.Dd September 24, 2021
.Dd October 2, 2021
.Dt CONJUGUER 1
.Os
.Sh NAME
Expand Down Expand Up @@ -51,6 +51,9 @@ Enable debug mode
.Op Fl -help|-?
Print usage and this help message and exit
.Pp
.Op Fl -locale Ar LANG
Override environment to select another language
.Pp
.Op Fl -version
Print version and exit
.Pp
Expand Down Expand Up @@ -115,3 +118,7 @@ the verbs conjugated with the "etre" auxiliary when used with a pronoun for exam
.Pp
Though the software is probably mostly correct, I will consider it as Beta quality till I get
a better idea of the quality of the source data and offer a way to improve it...
.Pp
The
.Fl -lang
command line option does not always work correctly when selecting en(glish).
12 changes: 11 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = pnu_conjuguer
description = conjugaison des verbes Français
long_description = file: README.md
long_description_content_type = text/markdown
version = 0.3.0
version = 0.4.0
license = BSD 3-Clause License
license_files = License
author = Hubert Tournier
Expand All @@ -25,6 +25,16 @@ classifiers =
Operating System :: Microsoft :: Windows
Programming Language :: Python :: 3
Programming Language :: Python :: 3.0
Programming Language :: Python :: 3.1
Programming Language :: Python :: 3.2
Programming Language :: Python :: 3.3
Programming Language :: Python :: 3.4
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Topic :: Education
Topic :: Education :: Computer Aided Instruction (CAI)
Topic :: Text Processing :: Linguistic
Expand Down
10 changes: 9 additions & 1 deletion src/conjuguer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ format: /usr/local/bin/black
${NAME}.${SECTION}.gz: ../../man/${NAME}.${SECTION}
@gzip -k9c ../../man/${NAME}.${SECTION} > ${NAME}.${SECTION}.gz

po/fr/${NAME}.mo:
po/${NAME}.pot:
@mkdir po
@xgettext --language=Python -o po/${NAME}.pot *.py

po/fr/${NAME}.po: po/${NAME}.pot
@mkdir -p po/fr
@msginit --locale=fr --input=po/${NAME}.pot --output=po/fr/${NAME}.po

po/fr/${NAME}.mo: po/fr/${NAME}.po
@msgfmt --output-file=po/fr/${NAME}.mo po/fr/${NAME}.po

install: ${NAME}.${SECTION}.gz po/fr/${NAME}.mo
Expand Down
88 changes: 71 additions & 17 deletions src/conjuguer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

import colorama

from .verbs import aux, etre_aux, both_aux
from .verbs import aux, etre_aux, both_aux, patterns
from .blank import blank_verb

# Version string used by the what(1) and ident(1) commands:
ID = "@(#) $Id: conjuguer - conjugaison des verbes Français v0.3.0 (September 24, 2021) by Hubert Tournier $"
ID = "@(#) $Id: conjuguer - conjugaison des verbes Français v0.4.0 (October 2, 2021) by Hubert Tournier $"

# Default parameters. Can be overcome by environment variables, then command line options
parameters = {
Expand Down Expand Up @@ -57,20 +57,21 @@ def initialize_debugging(program_name):


################################################################################
def initialize_internationalization(program_name):
def initialize_internationalization(program_name, lang=locale.getdefaultlocale()[0][:2]):
"""Internationalization set up"""
lang = locale.getdefaultlocale()[0][:2]
locale_dirs = []

if os.name == "posix":
if os.path.isdir("/usr/share/locale"):
locale_dirs.append("/usr/share/locale")
if os.path.isdir("/usr/local/share/locale"):
locale_dirs.append("/usr/local/share/locale")
# local packages override system packages:
if "HOME" in os.environ.keys():
home = os.environ["HOME"]
if os.path.isdir(home + os.sep + ".local/share/locale"):
locale_dirs.append(home + os.sep + ".local/share/locale")

if os.path.isdir("/usr/share/locale"):
locale_dirs.append("/usr/share/locale")
if os.path.isdir("/usr/local/share/locale"):
locale_dirs.append("/usr/local/share/locale")
elif os.name == "nt":
appdata_path = os.sep + "appdata" + os.sep + "roaming"
locale_suffix = os.sep + "python" + os.sep + "share" + os.sep + "locale"
Expand Down Expand Up @@ -99,7 +100,7 @@ def initialize_internationalization(program_name):
################################################################################
def display_help():
"""Displays usage and help"""
print(_("usage: conjuguer [--debug] [--help|-?] [--version]"), file=sys.stderr)
print(_("usage: conjuguer [--debug] [--help|-?] [--locale LANG] [--version]"), file=sys.stderr)
print(
" "
+ _("[-c|--columns NUMBER] [-d|--dictionary PATH] [-n|--nocolor]"),
Expand All @@ -121,6 +122,10 @@ def display_help():
" " + _("--help|-? Print usage and this help message and exit"),
file=sys.stderr
)
print(
" " + _("--locale LANG Override environment to select another language"),
file=sys.stderr
)
print(" " + _("--version Print version and exit"), file=sys.stderr)
print(" " + _("-- Options processing terminator"), file=sys.stderr)
print(file=sys.stderr)
Expand Down Expand Up @@ -183,7 +188,7 @@ def process_environment_variables():
if os.path.isdir(pnu_dictpath):
parameters["DictPath"].append(pnu_dictpath)

pnu_dictpath2=sys.executable.replace("python.exe", "share" + os.sep + "dict")
pnu_dictpath2 = sys.base_prefix + os.sep + "share" + os.sep + "dict"
if os.path.isdir(pnu_dictpath2):
parameters["DictPath"].append(pnu_dictpath2)

Expand Down Expand Up @@ -218,7 +223,7 @@ def process_environment_variables():


################################################################################
def process_command_line():
def process_command_line(program_name):
"""Process command line options"""
# pylint: disable=C0103
global parameters
Expand All @@ -232,6 +237,7 @@ def process_command_line():
"debug",
"dictionary=",
"help",
"locale=",
"nocolor",
"version",
]
Expand Down Expand Up @@ -277,6 +283,9 @@ def process_command_line():
display_help()
sys.exit(0)

elif option == "--locale":
initialize_internationalization(program_name, argument)

elif option in ("-n", "--nocolor"):
parameters["Color display"] = False

Expand Down Expand Up @@ -605,9 +614,37 @@ def conjuguer(verb, conjugations, auxiliary):
return conjugated_verb


################################################################################
def analyze_verb(verb):
"""Return a verb pattern, group and conjugation model"""
group = None
group_text = ""
model = ""

for key in patterns.keys():
if verb.endswith(key):
group = patterns[key][0]
model = patterns[key][1]
break

if group == 0:
group_text = _("auxiliary")
elif group == 1:
group_text = _("1st group")
elif group == 2:
group_text = _("2nd group")
elif group == 3:
group_text = _("3rd group")
else:
group_text = _("unknown group")

return key, group_text, model


################################################################################
def print_verb(verb):
"""Return lines describing the conjugated verb"""
pattern, group, model = analyze_verb(verb)
lines = []
if parameters["Color display"]:
lines.append(
Expand All @@ -619,6 +656,12 @@ def print_verb(verb):
)
else:
lines.append(_("Conjugation tables for") + " " + verb)

if verb == model:
lines.append(group + ", " + _("model for verbs like") + " *" + pattern)
else:
lines.append(group + ", " + _("conjugated like") + " " + model)

lines.append("")

return lines
Expand Down Expand Up @@ -926,18 +969,19 @@ def main():
initialize_debugging(program_name)
initialize_internationalization(program_name)
process_environment_variables()
arguments = process_command_line()

if parameters["Dictionary type"] not in ("ABU", "DELA"):
logging.debug(_("Unknown inflected dictionary format"))
sys.exit(1)
verbs = load_all_verbs_from_dictionary()
arguments = process_command_line(program_name)

if not arguments:
logging.critical(_("conjuguer expects at least one argument"))
display_help()
sys.exit(1)

if parameters["Dictionary type"] not in ("ABU", "DELA"):
logging.debug(_("Unknown inflected dictionary format"))
sys.exit(1)

verbs = load_all_verbs_from_dictionary()

exit_status = 0
for argument in arguments:
conjugations = select_verb_from_verbs(argument, verbs)
Expand All @@ -955,6 +999,16 @@ def main():
print_verb_conjugation(verb)
else:
logging.error("%s " + _("is not in the dictionary used"), argument)
pattern, group, model = analyze_verb(argument)
print(
_("If it really exists, it would be")
+ " "
+ group
+ ", "
+ _("conjugated like")
+ " "
+ model
)
exit_status = 1

sys.exit(exit_status)
Expand Down
35 changes: 31 additions & 4 deletions src/conjuguer/po/conjuguer.pot
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: conjuguer 0.3.0\n"
"Project-Id-Version: conjuguer 0.4.0\n"
"Report-Msgid-Bugs-To: hubert.tournier@gmail.com\n"
"POT-Creation-Date: 2021-09-19 10:30:+0100\n"
"PO-Revision-Date: \n"
"POT-Creation-Date: 2021-09-19 10:30:+0200\n"
"PO-Revision-Date: 2021-10-02 15:26:+0200\n"
"Last-Translator: Hubert Tournier <hubert.tournier@gmail.com>\n"
"Language-Team: \n"
"Language: en\n"
Expand All @@ -21,7 +21,7 @@ msgstr ""
#: main.py
#, python-format

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

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

msgid "--locale LANG Override environment to select another language"
msgstr ""

msgid "--version Print version and exit"
msgstr ""

Expand Down Expand Up @@ -105,6 +108,27 @@ msgstr ""
msgid "Infinitif passé not found for"
msgstr ""

msgid "auxiliary"
msgstr ""

msgid "1st group"
msgstr ""

msgid "2nd group"
msgstr ""

msgid "3rd group"
msgstr ""

msgid "unknown group"
msgstr ""

msgid "model for verbs like"
msgstr ""

msgid "conjugated like"
msgstr ""

msgid "Conjugation tables for"
msgstr ""

Expand All @@ -117,3 +141,6 @@ msgstr ""
msgid "is not in the dictionary used"
msgstr ""

msgid "If it really exists, it would be"
msgstr ""

Loading

0 comments on commit d4d3bbe

Please sign in to comment.