Package: nombres-vers-lettres
nombres_vers_lettresA Python package to write numbers in French, with a simple script. The reason I made this package is the complexity of this simple task that often lead the implementation of such a tool to produce erroneous results (seethis issue).InstallationYou can easily install this package usingpip.python-mpipinstallnombres_vers_lettresOr for the development version:python-mpipinstallgit+https://github.com/Vincent-Stragier/nombres_vers_lettres.gitExampleIt is better to have your number in strings, this avoids conversion error betweenintorfloatand strings (seefloating point precisionfor more details).importnombres_vers_lettresasnvlfromnombres_vers_lettresimportconstants# List available languagesprint(f"{constants.AVAILABLE_LANGUAGES= }")# List available currenciesprint(f"{constants.CURRENCY_FORMS_FR_CODES= }")# Print the number 42 in French (cardinal mode, new orthographe)# Default language is fr_BEcardinal_42=nvl.make_letters(42,language="fr_FR",post_1990_orthographe=True)print(f"{cardinal_42= }")# Print 42e in French (cardinal mode, new orthographe)ordinal_nominal_42=nvl.make_letters(42,language="fr_FR",mode="ordinal_nominal",post_1990_orthographe=True)print(f"{ordinal_nominal_42= }")# Print €420,69 in French (new orthographe)currency_420_69=nvl.make_letters("420,69",language="fr_FR",mode="EUR",post_1990_orthographe=True,# By default, non-breaking spaces are useduse_non_breaking_spaces=False,)print(f"{currency_420_69= }")# Write 1st feminine pluralordinal_nominal_1st_f_p=nvl.make_letters("1",language="fr_FR",mode="ordinal_nominal",gender="feminine",plural=True,post_1990_orthographe=True,)print(f"{ordinal_nominal_1st_f_p= }")Script usageAfter installing this package, Python gives you access to two entry points:nombres_vers_lettresornvl.$nvl-h
usage:nvl[-h][--modeMODE|--cardinal|--ordinal|--ordinal_nominal][--genderGENDER|--masculine|--feminine][--plural][--post_1990_orthographe][--languageLANGUAGE]number

positionalarguments:numberThenumberasastringtoconverttoletters(inFrench)options:-h,--helpshowthishelpmessageandexit--modeMODEThemodetousefortheconversion(nominal,cardinalorordinal)--cardinal,-cConvertthenumbertocardinalnumbersinletters(e.g.,'un chat','deux ânes','quatre-vingts chats','deux-centsbilles',etc.)--ordinal,-oConvertthenumbertoordinalnumbersinletters(e.g.,'la page un','la page quatre-vingt','la page deux-cent',etc.)--ordinal_nominal,-onConvertthenumbertoordinalnominalnumbersinletters(e.g.,'la quatre-vingtième page','la deux-centième page',etc.)--genderGENDER,-gGENDERThegendertousefortheconversion(feminine,féminin,feminin,formasculine,masculin,m),defaultismasculine(onlyhasaneffectoncardinalandordinal_nominalmodes)--masculine,-mConvertthenumbertomasculineletters(e.g.'un'->'un')--feminine,-fConvertthenumbertofeminineletters(e.g.'un'->'une')--plural,-pConvertthenumbertopluralletters(e.g.'un'->'uns'),onlyhasaneffectoncardinalandordinal_nominalmodes--post_1990_orthographe,-tUsethetiretcharactereverywhere(e.g.'vingt-et-un')--languageLANGUAGE,-lLANGUAGEThelanguagecodetousefortheconversion(e.g.fr_BE,fr_CD,fr_FR,fr_CA,fr_CH,fr_IT)How to contributeIf you spotted an error, you canopen an issue in this repository. Moreover, you can help to fixnum2words.And you can also open Pull Request for this repository.After locally cloning your fork of this repository, you can install all the tools needed to check the code:python-mpipinstall-rrequirements-dev.txt# Ideally, also install the pre-commit hooks,# which will be executed before each commitprecommitinstallPre-commitIf you cannot manage to commit your code due to the pre-commit hooks, simply uninstall them (precommit uninstall).You can still manually run them usingprecommit run -a -vto see where the issues are.CoverageSome tests have been implemented to check if you broke the current code. Ideally, you should add new test before changing the codebase to check if it indeed solves the issue, etc. Those tests are run by the pre-commit hooks.Run the testscoveragerun-mpytestGet some simple coverage informationcoveragereportGenerate an HTML report of the test coveragecoveragehtmlSome referencesImportant references are in italic.Writing numbers in letters according to Le FigaroWriting numbers in euros according to Le FigaroHow to write numbers in French according to BescherelleHow to write numbers in Canadian pteFrench according to BescherelleHow to write numbers in French according to Wikipedia←How to write big numbers in French according to Wikipedia←How to write ordinal numbers according to Lingolia←How to write cardinal numbers according to Lingolia