pax_global_header00006660000000000000000000000064132053506220014510gustar00rootroot0000000000000052 comment=8ffdc5e49d3c75ef83fd18bb13f18372ca473a91 num2words-0.5.6/000077500000000000000000000000001320535062200134605ustar00rootroot00000000000000num2words-0.5.6/.gitignore000066400000000000000000000000421320535062200154440ustar00rootroot00000000000000*.pyc build dist *.egg-info /.tox num2words-0.5.6/.travis.yml000066400000000000000000000001711320535062200155700ustar00rootroot00000000000000sudo: false language: python python: - "2.7" - "3.4" - "3.5" - "3.6" install: pip install tox-travis script: tox num2words-0.5.6/CHANGES.rst000066400000000000000000000033741320535062200152710ustar00rootroot00000000000000Changelog ========= Version 0.5.6 -- 2017/11/22 --------------------------- * Refactor to_currency (#135) * Allow the use of other convertes to_currency, to_year (#95) * Fix code to respect PEP8 (#98, #105) * Add Slovene localization (#97) * Add Ukrainian localization (#93) * Add Dutch localization (#91) * Add Algeria-French localization (#86) * Add Turkish localization (#85) Version 0.5.5 -- 2017/07/02 --------------------------- * Add Arabic localization (#72) * Add Spanish-Colombian and Spanish-Venezuelan localization (#67) * Add VietNam localization (#61) * Add Italian localization (#56, #59) * Improve Russian localization (#62) * Improve Polish localization (#58) Version 0.5.4 -- 2016/10/18 --------------------------- * Tons of new languages! * Add Polish localization. (#23) * Add Swiss-French localization. (#38) * Add Russian localization. (#28, #46, #48) * Add Indonesian localization. (#29) * Add Norwegian localization. (#33) * Add Danish localization. (#40) * Add Brazilian localization. (#37, #47) * Improve German localization. (#25, #27, #49) * Improve Lithuanian localization. (#52) * Improve floating point spelling. (#24) Version 0.5.3 -- 2015/06/09 --------------------------- * Fix packaging issues. (#21, #22) Version 0.5.2 -- 2015/01/23 --------------------------- * Added Latvian localization. (#9) * Improved Spanish localization. (#10, #13, #14) * Improved Lithuanian localization. (#12) Version 0.5.1 -- 2014/03/14 --------------------------- * Added Python 3 support with 2to3. (#3) * Fixed big numbers in spanish. (#2) * Fixed bugs in tanslation from 30 to 40 in spanish. (#4) * Fixed word joining in english. (#8) Version 0.5.0 -- 2013/05/28 --------------------------- * Created ``num2words`` based on the old ``pynum2word`` project. num2words-0.5.6/CODE_OF_CONDUCT.md000066400000000000000000000062311320535062200162610ustar00rootroot00000000000000# Contributor Covenant Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. ## Our Standards Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at support@savoirfairelinux.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] [homepage]: http://contributor-covenant.org [version]: http://contributor-covenant.org/version/1/4/ num2words-0.5.6/CONTRIBUTING.md000066400000000000000000000033531320535062200157150ustar00rootroot00000000000000## How can I contribute ? ### Code contribution #### Issues If you are unsure where to begin contribution to Num2Words, you can start by looking through the issues page. Numerous issues are created and waiting for your love on the [issue board](https://github.com/savoirfairelinux/num2words/issues). #### Pull Requests Contributions will be accepted through the creation of Pull Requests. Here is the workflow: * Fork the repository into yours and work from there * Commit and push your changes into your fork * When you are done, create a [Pull Request](https://github.com/savoirfairelinux/num2words/compare) on the **master** branch A template is provided to create your Pull Request. Try to fill the information at the best of your knowledge. #### Pull request checklist For your pull request to be merged, the answer to the following questions must be 'yes': ##### General * Can the branch be merged automatically? ##### Testing * Do the unit tests pass? ##### Adding new code * Is the code PEP8 compliant? * Is the code covered by tests? [TravisCI](https://travis-ci.org/) is configured to run those checks on every Pull-Request. It is recommanded you configure your fork to do the same. ### Reporting bugs Bugs are tracked as [GitHub issues](https://guides.github.com/features/issues/). #### How to submit a good bug report Please include as many details as possible. An issue template is automatically loaded when you create an issue. * Use a clear and comprehensive title for the issue * Describe the expected behaviour in as many details as possible * Describe the actual behaviour in as many details as possible ### Testing the application Our development process is based on Continuous Integration. We love to have a nice code coverage! num2words-0.5.6/COPYING000066400000000000000000000566731320535062200145340ustar00rootroot00000000000000GNU Lesser General Public License Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS num2words-0.5.6/ISSUE_TEMPLATE.md000066400000000000000000000001761320535062200161710ustar00rootroot00000000000000### Expected Behaviour Fill me in ... ### Actual Behaviour Fill me in ... ### Steps to reproduce * step 1 * step 2 * ... num2words-0.5.6/MANIFEST.in000066400000000000000000000000641320535062200152160ustar00rootroot00000000000000include CHANGES.rst include COPYING include tests/* num2words-0.5.6/PULL_REQUEST_TEMPLATE.md000066400000000000000000000005151320535062200172620ustar00rootroot00000000000000## Fixes # by... ### Changes proposed in this pull request: * ... * ... ### Status - [ ] READY - [ ] HOLD - [X] WIP (Work-In-Progress) ### How to verify this change *Fill out this section so that a reviewer can know how to verify your change.* ### Additional notes *If applicable, explain the rationale behind your change.* num2words-0.5.6/README.rst000066400000000000000000000060311320535062200151470ustar00rootroot00000000000000num2words - Convert numbers to words in multiple languages ========================================================== .. image:: https://travis-ci.org/savoirfairelinux/num2words.svg?branch=master :target: https://travis-ci.org/savoirfairelinux/num2words .. image:: https://coveralls.io/repos/github/savoirfairelinux/num2words/badge.svg?branch=master :target: https://coveralls.io/github/savoirfairelinux/num2words?branch=master ``num2words`` is a library that converts numbers like ``42`` to words like ``forty-two``. It supports multiple languages (see the list below for full list of languages) and can even generate ordinal numbers like ``forty-second`` (although this last feature is a bit buggy for some languages at the moment). The project is hosted on https://github.com/savoirfairelinux/num2words Installation ------------ The easiest way to install ``num2words`` is to use pip:: pip install num2words Otherwise, you can download the source package and then execute:: python setup.py install The test suite in this library new, so it's rather thin, but it can be ran with:: python setup.py test Usage ----- There's only one function to use:: >>> from num2words import num2words >>> num2words(42) forty-two >>> num2words(42, to='cardinal') forty-second >>> num2words(42, lang='fr') quarante-deux Besides the numerical argument, there's two optional arguments. **to:** The converter to use. Supperted values are: * ``cardinal`` (default) * ``ordinal`` * ``ordinal_num`` * ``year`` * ``currency`` **lang:** The language in which to convert the number. Supported values are: * ``en`` (English, default) * ``ar`` (Arabic) * ``de`` (German) * ``dk`` (Danish) * ``en_GB`` (English - Great Britain) * ``en_IN`` (English - India) * ``es`` (Spanish) * ``es_CO`` (Spanish - Colombia) * ``es_VE`` (Spanish - Venezuela) * ``eu`` (EURO) * ``fr`` (French) * ``fr_CH`` (French - Switzerland) * ``fr_DZ`` (French - Algeria) * ``he`` (Hebrew) * ``id`` (Indonesian) * ``it`` (Italian) * ``lt`` (Lithuanian) * ``lv`` (Latvian) * ``no`` (Norwegian) * ``pl`` (Polish) * ``pt_BR`` (Brazilian Portuguese) * ``sl`` (Slovene) * ``ru`` (Russian) * ``tr`` (Turkish) * ``vn`` (Vietnamese) * ``nl`` (Dutch) * ``uk`` (Ukrainian) You can supply values like ``fr_FR``, the code will be correctly interpreted. If you supply an unsupported language, ``NotImplementedError`` is raised. Therefore, if you want to call ``num2words`` with a fallback, you can do:: try: return num2words(42, lang=mylang) except NotImplementedError: return num2words(42, lang='en') History ------- ``num2words`` is based on an old library, ``pynum2word`` created by Taro Ogawa in 2003. Unfortunately, the library stopped being maintained and the author can't be reached. There was another developer, Marius Grigaitis, who in 2011 added Lithuanian support, but didn't take over maintenance of the project. I am thus basing myself on Marius Grigaitis' improvements and re-publishing ``pynum2word`` as ``num2words``. Virgil Dupras, Savoir-faire Linux num2words-0.5.6/num2words/000077500000000000000000000000001320535062200154205ustar00rootroot00000000000000num2words-0.5.6/num2words/__init__.py000066400000000000000000000057031320535062200175360ustar00rootroot00000000000000# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from . import lang_AR from . import lang_EN from . import lang_EN_IN from . import lang_FR from . import lang_FR_CH from . import lang_FR_DZ from . import lang_DE from . import lang_ES from . import lang_LT from . import lang_LV from . import lang_PL from . import lang_RU from . import lang_ID from . import lang_NO from . import lang_DK from . import lang_PT_BR from . import lang_HE from . import lang_IT from . import lang_ES_VE from . import lang_ES_CO from . import lang_VN from . import lang_TR from . import lang_NL from . import lang_UK from . import lang_SL CONVERTER_CLASSES = { 'ar': lang_AR.Num2Word_AR(), 'en': lang_EN.Num2Word_EN(), 'en_IN': lang_EN_IN.Num2Word_EN_IN(), 'fr': lang_FR.Num2Word_FR(), 'fr_CH': lang_FR_CH.Num2Word_FR_CH(), 'fr_DZ': lang_FR_DZ.Num2Word_FR_DZ(), 'de': lang_DE.Num2Word_DE(), 'es': lang_ES.Num2Word_ES(), 'es_CO': lang_ES_CO.Num2Word_ES_CO(), 'es_VE': lang_ES_VE.Num2Word_ES_VE(), 'id': lang_ID.Num2Word_ID(), 'lt': lang_LT.Num2Word_LT(), 'lv': lang_LV.Num2Word_LV(), 'pl': lang_PL.Num2Word_PL(), 'ru': lang_RU.Num2Word_RU(), 'sl': lang_SL.Num2Word_SL(), 'no': lang_NO.Num2Word_NO(), 'dk': lang_DK.Num2Word_DK(), 'pt_BR': lang_PT_BR.Num2Word_PT_BR(), 'he': lang_HE.Num2Word_HE(), 'it': lang_IT.Num2Word_IT(), 'vi_VN': lang_VN.Num2Word_VN(), 'tr': lang_TR.Num2Word_TR(), 'nl': lang_NL.Num2Word_NL(), 'uk': lang_UK.Num2Word_UK() } CONVERTES_TYPES = ['cardinal', 'ordinal', 'ordinal_num', 'year', 'currency'] def num2words(number, ordinal=False, lang='en', to='cardinal', **kwargs): # We try the full language first if lang not in CONVERTER_CLASSES: # ... and then try only the first 2 letters lang = lang[:2] if lang not in CONVERTER_CLASSES: raise NotImplementedError() converter = CONVERTER_CLASSES[lang] # backwards compatible if ordinal: return converter.to_ordinal(number) if to not in CONVERTES_TYPES: raise NotImplementedError() return getattr(converter, 'to_{}'.format(to))(number, **kwargs) num2words-0.5.6/num2words/base.py000066400000000000000000000233721320535062200167130ustar00rootroot00000000000000# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals import math from collections import OrderedDict from decimal import Decimal from .compat import to_s from .currency import parse_currency_parts, prefix_currency class Num2Word_Base(object): CURRENCY_FORMS = {} CURRENCY_ADJECTIVES = {} def __init__(self): self.cards = OrderedDict() self.is_title = False self.precision = 2 self.exclude_title = [] self.negword = "(-) " self.pointword = "(.)" self.errmsg_nonnum = "type(%s) not in [long, int, float]" self.errmsg_floatord = "Cannot treat float %s as ordinal." self.errmsg_negord = "Cannot treat negative num %s as ordinal." self.errmsg_toobig = "abs(%s) must be less than %s." self.base_setup() self.setup() self.set_numwords() self.MAXVAL = 1000 * list(self.cards.keys())[0] def set_numwords(self): self.set_high_numwords(self.high_numwords) self.set_mid_numwords(self.mid_numwords) self.set_low_numwords(self.low_numwords) def gen_high_numwords(self, units, tens, lows): out = [u + t for t in tens for u in units] out.reverse() return out + lows def set_mid_numwords(self, mid): for key, val in mid: self.cards[key] = val def set_low_numwords(self, numwords): for word, n in zip(numwords, range(len(numwords) - 1, -1, -1)): self.cards[n] = word def splitnum(self, value): for elem in self.cards: if elem > value: continue out = [] if value == 0: div, mod = 1, 0 else: div, mod = divmod(value, elem) if div == 1: out.append((self.cards[1], 1)) else: if div == value: # The system tallies, eg Roman Numerals return [(div * self.cards[elem], div*elem)] out.append(self.splitnum(div)) out.append((self.cards[elem], elem)) if mod: out.append(self.splitnum(mod)) return out def to_cardinal(self, value): try: assert int(value) == value except (ValueError, TypeError, AssertionError): return self.to_cardinal_float(value) self.verify_num(value) out = "" if value < 0: value = abs(value) out = self.negword if value >= self.MAXVAL: raise OverflowError(self.errmsg_toobig % (value, self.MAXVAL)) val = self.splitnum(value) words, num = self.clean(val) return self.title(out + words) def float2tuple(self, value): pre = int(value) # Simple way of finding decimal places to update the precision self.precision = abs(Decimal(str(value)).as_tuple().exponent) post = abs(value - pre) * 10**self.precision if abs(round(post) - post) < 0.01: # We generally floor all values beyond our precision (rather than # rounding), but in cases where we have something like 1.239999999, # which is probably due to python's handling of floats, we actually # want to consider it as 1.24 instead of 1.23 post = int(round(post)) else: post = int(math.floor(post)) return pre, post def to_cardinal_float(self, value): try: float(value) == value except (ValueError, TypeError, AssertionError): raise TypeError(self.errmsg_nonnum % value) pre, post = self.float2tuple(float(value)) post = str(post) post = '0' * (self.precision - len(post)) + post out = [self.to_cardinal(pre)] if self.precision: out.append(self.title(self.pointword)) for i in range(self.precision): curr = int(post[i]) out.append(to_s(self.to_cardinal(curr))) return " ".join(out) def merge(self, curr, next): raise NotImplementedError def clean(self, val): out = val while len(val) != 1: out = [] left, right = val[:2] if isinstance(left, tuple) and isinstance(right, tuple): out.append(self.merge(left, right)) if val[2:]: out.append(val[2:]) else: for elem in val: if isinstance(elem, list): if len(elem) == 1: out.append(elem[0]) else: out.append(self.clean(elem)) else: out.append(elem) val = out return out[0] def title(self, value): if self.is_title: out = [] value = value.split() for word in value: if word in self.exclude_title: out.append(word) else: out.append(word[0].upper() + word[1:]) value = " ".join(out) return value def verify_ordinal(self, value): if not value == int(value): raise TypeError(self.errmsg_floatord % value) if not abs(value) == value: raise TypeError(self.errmsg_negord % value) def verify_num(self, value): return 1 def set_wordnums(self): pass def to_ordinal(self, value): return self.to_cardinal(value) def to_ordinal_num(self, value): return value # Trivial version def inflect(self, value, text): text = text.split("/") if value == 1: return text[0] return "".join(text) # //CHECK: generalise? Any others like pounds/shillings/pence? def to_splitnum(self, val, hightxt="", lowtxt="", jointxt="", divisor=100, longval=True, cents=True): out = [] if isinstance(val, float): high, low = self.float2tuple(val) else: try: high, low = val except TypeError: high, low = divmod(val, divisor) if high: hightxt = self.title(self.inflect(high, hightxt)) out.append(self.to_cardinal(high)) if low: if longval: if hightxt: out.append(hightxt) if jointxt: out.append(self.title(jointxt)) elif hightxt: out.append(hightxt) if low: if cents: out.append(self.to_cardinal(low)) else: out.append("%02d" % low) if lowtxt and longval: out.append(self.title(self.inflect(low, lowtxt))) return " ".join(out) def to_year(self, value, **kwargs): return self.to_cardinal(value) def pluralize(self, n, forms): """ Should resolve gettext form: http://docs.translatehouse.org/projects/localization-guide/en/latest/l10n/pluralforms.html """ raise NotImplementedError def _cents_verbose(self, number, currency): return self.to_cardinal(number) def to_currency(self, val, currency='EUR', cents=True, seperator=',', adjective=False): """ Args: val: Numeric value currency (str): Currency code cents (bool): Verbose cents seperator (str): Cent seperator adjective (bool): Prefix currency name with adjective Returns: str: Formatted string """ left, right, is_negative = parse_currency_parts(val) try: cr1, cr2 = self.CURRENCY_FORMS[currency] except KeyError: raise NotImplementedError( 'Currency code "%s" not implemented for "%s"' % (currency, self.__class__.__name__)) if adjective and currency in self.CURRENCY_ADJECTIVES: cr1 = prefix_currency(self.CURRENCY_ADJECTIVES[currency], cr1) minus_str = "%s " % self.negword if is_negative else "" cents_str = self._cents_verbose(right, currency) \ if cents else "%02d" % right return u'%s%s %s%s %s %s' % ( minus_str, self.to_cardinal(left), self.pluralize(left, cr1), seperator, cents_str, self.pluralize(right, cr2) ) def base_setup(self): pass def setup(self): pass def test(self, value): try: _card = self.to_cardinal(value) except Exception: _card = "invalid" try: _ord = self.to_ordinal(value) except Exception: _ord = "invalid" try: _ordnum = self.to_ordinal_num(value) except Exception: _ordnum = "invalid" print("For %s, card is %s;\n\tord is %s; and\n\tordnum is %s." % (value, _card, _ord, _ordnum)) num2words-0.5.6/num2words/compat.py000066400000000000000000000016641320535062200172640ustar00rootroot00000000000000# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2016, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA def to_s(val): try: return unicode(val) except NameError: return str(val) num2words-0.5.6/num2words/currency.py000066400000000000000000000020731320535062200176260ustar00rootroot00000000000000from __future__ import division from decimal import Decimal def parse_currency_parts(value): if isinstance(value, int): # assume cents if value is integer negative = value < 0 value = abs(value) integer, cents = divmod(value, 100) elif isinstance(value, Decimal): negative = value < 0 value = abs(value) integer, fraction = divmod(value, 1) integer = int(integer) cents = int(fraction * 100) else: # @TODO consider using something (babel) that does locale aware parsing value = str(value).replace(',', '.') negative = value.startswith('-') if negative: value = value.lstrip('-') if '.' in value: integer, fraction = value.rsplit('.', 1) fraction = fraction.ljust(2, "0") else: integer, fraction = value, 0 integer = int(integer) cents = int(fraction) return integer, cents, negative def prefix_currency(prefix, base): return tuple("%s %s" % (prefix, i) for i in base) num2words-0.5.6/num2words/lang_AR.py000066400000000000000000000120051320535062200172730ustar00rootroot00000000000000# -*- coding: utf-8 -*- # Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import division, print_function, unicode_literals from . import lang_EU class Num2Word_AR(lang_EU.Num2Word_EU): def set_high_numwords(self, high): max = 3 + 3 * len(high) for word, n in zip(high, range(max, 3, -3)): self.cards[10 ** n] = word + "illion" def setup(self): self.negword = "سالب " self.pointword = "فاصلة" self.errmsg_nornum = "Only numbers may be converted to words." self.exclude_title = ["و", "فاصلة", "سالب"] self.mid_numwords = [(1000000, "مليون"), (1000, "ألف"), (100, "مئة"), (90, "تسعين"), (80, "ثمانين"), (70, "سبعين"), (60, "ستين"), (50, "خمسين"), (40, "أربعين"), (30, "ثلاثين")] self.low_numwords = ["عشرين", "تسعة عشر", "ثمانية عشر", "سبعة عشر", "ستة عشر", "خمسة عشر", "أربعة عشر", "ثلاثة عشر", "اثناعشر", "أحد عشر", "عشرة", "تسعة", "ثمانية", "سبعة", "ستة", "خمسة", "أربعة", "ثلاثة", "اثنين", "واحد", "صفر"] self.ords = {"واحد": "أول", "اثنين": "ثاني", "ثلاثة": "ثالث", "أربعة": "رابع", "خمسة": "خامس", "ثمانية": "ثامن", "تسعة": "تاسع", "اثناعشر": "ثاني عشر"} def merge(self, lpair, rpair): ltext, lnum = lpair rtext, rnum = rpair if lnum == 1 and rnum < 100: return (rtext, rnum) elif 100 > lnum > rnum: return ("%s و%s" % (rtext, ltext), rnum + lnum) elif lnum >= 100 > rnum: return ("%s و %s" % (ltext, rtext), lnum + rnum) elif rnum > lnum: if lnum == 1 and rnum in [100, 1000, 1000000]: return ("%s" % (rtext), rnum * lnum) if lnum == 2 and rnum == 100: return ("مئتين", rnum * lnum) if lnum == 2 and rnum in [100, 1000]: return ("%sين" % (rtext), rnum * lnum) return ("%s %s" % (ltext, rtext), lnum * rnum) return ("%s، %s" % (ltext, rtext), lnum + rnum) def to_ordinal(self, value): self.verify_ordinal(value) outwords = self.to_cardinal(value).split(" ") lastwords = outwords[-1].split("-") lastword = lastwords[-1].lower() try: lastword = self.ords[lastword] except KeyError: lastword += "" lastwords[-1] = self.title(lastword) outwords[-1] = "،".join(lastwords) return " ".join(outwords) def to_ordinal_num(self, value): self.verify_ordinal(value) return "%s%s" % (value, self.to_ordinal(value)[-2:]) def to_year(self, val, longval=True): if not (val // 100) % 10: return self.to_cardinal(val) return self.to_splitnum(val, hightxt="مئة", jointxt="و", longval=longval) def to_currency(self, val, longval=True): return self.to_splitnum(val, hightxt="ريال", lowtxt="هللة", jointxt="و", longval=longval, cents=True) n2w = Num2Word_AR() to_card = n2w.to_cardinal to_ord = n2w.to_ordinal to_ordnum = n2w.to_ordinal_num to_year = n2w.to_year def main(): for val in [1, 11, 12, 21, 31, 33, 71, 80, 81, 91, 99, 100, 101, 102, 155, 180, 300, 308, 832, 1000, 1001, 1061, 1100, 1500, 1701, 3000, 8280, 8291, 150000, 500000, 1000000, 2000000, 2000001, -21212121211221211111, -2.121212, -1.0000100]: n2w.test(val) n2w.test(13253254360678768017687001076010010122121321432104732075403270573) for val in [1, 120, 1000, 1120, 1800, 1976, 2000, 2010, 2099, 2171]: print(val, "is", n2w.to_currency(val)) print(val, "is", n2w.to_year(val)) if __name__ == "__main__": main() num2words-0.5.6/num2words/lang_DE.py000066400000000000000000000136411320535062200172700ustar00rootroot00000000000000# -*- coding: utf-8 -*- # Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import print_function, unicode_literals from .lang_EU import Num2Word_EU class Num2Word_DE(Num2Word_EU): def set_high_numwords(self, high): max = 3 + 6 * len(high) for word, n in zip(high, range(max, 3, -6)): self.cards[10 ** n] = word + "illiarde" self.cards[10 ** (n - 3)] = word + "illion" def setup(self): self.negword = "minus " self.pointword = "Komma" # "Cannot treat float %s as ordinal." self.errmsg_floatord = ( "Die Gleitkommazahl %s kann nicht in eine Ordnungszahl " + "konvertiert werden." ) # "type(((type(%s)) ) not in [long, int, float]" self.errmsg_nonnum = ( "Nur Zahlen (type(%s)) können in Wörter konvertiert werden." ) # "Cannot treat negative num %s as ordinal." self.errmsg_negord = ( "Die negative Zahl %s kann nicht in eine Ordnungszahl " + "konvertiert werden." ) # "abs(%s) must be less than %s." self.errmsg_toobig = "Die Zahl %s muss kleiner als %s sein." self.exclude_title = [] lows = ["non", "okt", "sept", "sext", "quint", "quadr", "tr", "b", "m"] units = ["", "un", "duo", "tre", "quattuor", "quin", "sex", "sept", "okto", "novem"] tens = ["dez", "vigint", "trigint", "quadragint", "quinquagint", "sexagint", "septuagint", "oktogint", "nonagint"] self.high_numwords = ( ["zent"] + self.gen_high_numwords(units, tens, lows) ) self.mid_numwords = [(1000, "tausend"), (100, "hundert"), (90, "neunzig"), (80, "achtzig"), (70, "siebzig"), (60, "sechzig"), (50, "f\xFCnfzig"), (40, "vierzig"), (30, "drei\xDFig")] self.low_numwords = ["zwanzig", "neunzehn", "achtzehn", "siebzehn", "sechzehn", "f\xFCnfzehn", "vierzehn", "dreizehn", "zw\xF6lf", "elf", "zehn", "neun", "acht", "sieben", "sechs", "f\xFCnf", "vier", "drei", "zwei", "eins", "null"] self.ords = {"eins": "ers", "drei": "drit", "acht": "ach", "sieben": "sieb", "ig": "igs", "ert": "erts", "end": "ends", "ion": "ions", "nen": "nens", "rde": "rdes", "rden": "rdens"} def merge(self, curr, next): ctext, cnum, ntext, nnum = curr + next if cnum == 1: if nnum < 10 ** 6: return next ctext = "eine" if nnum > cnum: if nnum >= 10 ** 6: if cnum > 1: if ntext.endswith("e"): ntext += "n" else: ntext += "en" ctext += " " val = cnum * nnum else: if nnum < 10 < cnum < 100: if nnum == 1: ntext = "ein" ntext, ctext = ctext, ntext + "und" elif cnum >= 10 ** 6: ctext += " " val = cnum + nnum word = ctext + ntext return (word, val) def to_ordinal(self, value): self.verify_ordinal(value) outword = self.to_cardinal(value) for key in self.ords: if outword.endswith(key): outword = outword[:len(outword) - len(key)] + self.ords[key] break return outword + "te" def to_ordinal_num(self, value): self.verify_ordinal(value) return str(value) + "." def to_currency(self, val, longval=True, old=False): if old: return self.to_splitnum(val, hightxt="mark/s", lowtxt="pfennig/e", jointxt="und", longval=longval) return super(Num2Word_DE, self).to_currency(val, jointxt="und", longval=longval) def to_year(self, val, longval=True): if not (val // 100) % 10: return self.to_cardinal(val) return self.to_splitnum(val, hightxt="hundert", longval=longval) n2w = Num2Word_DE() to_card = n2w.to_cardinal to_ord = n2w.to_ordinal to_ordnum = n2w.to_ordinal_num def main(): for val in [1, 7, 8, 12, 17, 81, 91, 99, 100, 101, 102, 155, 180, 300, 308, 832, 1000, 1001, 1061, 1100, 1500, 1701, 3000, 8280, 8291, 150000, 500000, 3000000, 1000000, 2000001, 1000000000, 2000000000, -21212121211221211111, -2.121212, -1.0000100]: n2w.test(val) n2w.test(13253254360678768017687001076010010122121321432104732075403270570) n2w.test(3000000) n2w.test(3000000000001) n2w.test(3000000324566) print(n2w.to_currency(112121)) print(n2w.to_year(2000)) print(n2w.to_year(1820)) print(n2w.to_year(2001)) if __name__ == "__main__": main() num2words-0.5.6/num2words/lang_DK.py000066400000000000000000000136011320535062200172720ustar00rootroot00000000000000# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import division, print_function, unicode_literals from . import lang_EU class Num2Word_DK(lang_EU.Num2Word_EU): def set_high_numwords(self, high): max = 3 + 6 * len(high) for word, n in zip(high, range(max, 3, -6)): self.cards[10 ** n] = word + "illarder" self.cards[10 ** (n - 3)] = word + "illioner" def setup(self): self.negword = "minus " self.pointword = "komma" self.errmsg_nornum = "Kun tal kan blive konverteret til ord." self.exclude_title = ["og", "komma", "minus"] self.mid_numwords = [(1000, "tusind"), (100, "hundrede"), (90, "halvfems"), (80, "firs"), (70, "halvfjerds"), (60, "treds"), (50, "halvtreds"), (40, "fyrre"), (30, "tredive")] self.low_numwords = ["tyve", "nitten", "atten", "sytten", "seksten", "femten", "fjorten", "tretten", "tolv", "elleve", "ti", "ni", "otte", "syv", "seks", "fem", "fire", "tre", "to", "et", "nul"] self.ords = {"nul": "nul", "et": "f\xf8rste", "to": "anden", "tre": "tredje", "fire": "fjerde", "fem": "femte", "seks": "sjette", "syv": "syvende", "otte": "ottende", "ni": "niende", "ti": "tiende", "elleve": "ellevte", "tolv": "tolvte", "tretten": "trett", "fjorten": "fjort", "femten": "femt", "seksten": "sekst", "sytten": "sytt", "atten": "att", "nitten": "nitt", "tyve": "tyv"} def merge(self, curr, next): ctext, cnum, ntext, nnum = curr + next if next[1] == 100 or next[1] == 1000: lst = list(next) lst[0] = 'et' + lst[0] next = tuple(lst) if cnum == 1: if nnum < 10 ** 6 or self.ordflag: return next ctext = "en" if nnum > cnum: if nnum >= 10 ** 6: ctext += " " val = cnum * nnum else: if cnum >= 100 and cnum < 1000: ctext += " og " elif cnum >= 1000 and cnum <= 100000: ctext += "e og " if nnum < 10 < cnum < 100: if nnum == 1: ntext = "en" ntext, ctext = ctext, ntext + "og" elif cnum >= 10 ** 6: ctext += " " val = cnum + nnum word = ctext + ntext return (word, val) def to_ordinal(self, value): self.verify_ordinal(value) self.ordflag = True outword = self.to_cardinal(value) self.ordflag = False for key in self.ords: if outword.endswith(key): outword = outword[:len(outword) - len(key)] + self.ords[key] break if value % 100 >= 30 and value % 100 <= 39 or value % 100 == 0: outword += "te" elif value % 100 > 12 or value % 100 == 0: outword += "ende" return outword def to_ordinal_num(self, value): self.verify_ordinal(value) vaerdte = (0, 1, 5, 6, 11, 12) if value % 100 >= 30 and value % 100 <= 39 or value % 100 in vaerdte: return str(value) + "te" elif value % 100 == 2: return str(value) + "en" return str(value) + "ende" def to_currency(self, val, longval=True): if val // 100 == 1 or val == 1: ret = self.to_splitnum(val, hightxt="kr", lowtxt="\xf8re", jointxt="og", longval=longval) return "en " + ret[3:] return self.to_splitnum(val, hightxt="kr", lowtxt="\xf8re", jointxt="og", longval=longval) def to_year(self, val, longval=True): if val == 1: return 'en' if not (val // 100) % 10: return self.to_cardinal(val) return self.to_splitnum(val, hightxt="hundrede", longval=longval) n2w = Num2Word_DK() to_card = n2w.to_cardinal to_ord = n2w.to_ordinal to_ordnum = n2w.to_ordinal_num to_year = n2w.to_year def main(): for val in [1, 11, 12, 21, 31, 33, 71, 80, 81, 91, 99, 100, 101, 102, 155, 180, 300, 308, 832, 1000, 1001, 1061, 1100, 1500, 1701, 3000, 8280, 8291, 150000, 500000, 1000000, 2000000, 2000001, -21212121211221211111, -2.121212, -1.0000100]: n2w.test(val) n2w.test(13253254360678768017687001076010010122121321432104732075403270573) for val in [1, 120, 160, 1000, 1120, 1800, 1976, 2000, 2010, 2099, 2171]: print(val, "er", n2w.to_currency(val)) print(val, "er", n2w.to_year(val)) n2w.test(65132) if __name__ == "__main__": main() num2words-0.5.6/num2words/lang_EN.py000066400000000000000000000071351320535062200173030ustar00rootroot00000000000000# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import division, print_function, unicode_literals from . import lang_EU class Num2Word_EN(lang_EU.Num2Word_EU): def set_high_numwords(self, high): max = 3 + 3 * len(high) for word, n in zip(high, range(max, 3, -3)): self.cards[10 ** n] = word + "illion" def setup(self): super(Num2Word_EN, self).setup() self.negword = "minus " self.pointword = "point" self.errmsg_nornum = "Only numbers may be converted to words." self.exclude_title = ["and", "point", "minus"] self.mid_numwords = [(1000, "thousand"), (100, "hundred"), (90, "ninety"), (80, "eighty"), (70, "seventy"), (60, "sixty"), (50, "fifty"), (40, "forty"), (30, "thirty")] self.low_numwords = ["twenty", "nineteen", "eighteen", "seventeen", "sixteen", "fifteen", "fourteen", "thirteen", "twelve", "eleven", "ten", "nine", "eight", "seven", "six", "five", "four", "three", "two", "one", "zero"] self.ords = {"one": "first", "two": "second", "three": "third", "five": "fifth", "eight": "eighth", "nine": "ninth", "twelve": "twelfth"} def merge(self, lpair, rpair): ltext, lnum = lpair rtext, rnum = rpair if lnum == 1 and rnum < 100: return (rtext, rnum) elif 100 > lnum > rnum: return ("%s-%s" % (ltext, rtext), lnum + rnum) elif lnum >= 100 > rnum: return ("%s and %s" % (ltext, rtext), lnum + rnum) elif rnum > lnum: return ("%s %s" % (ltext, rtext), lnum * rnum) return ("%s, %s" % (ltext, rtext), lnum + rnum) def to_ordinal(self, value): self.verify_ordinal(value) outwords = self.to_cardinal(value).split(" ") lastwords = outwords[-1].split("-") lastword = lastwords[-1].lower() try: lastword = self.ords[lastword] except KeyError: if lastword[-1] == "y": lastword = lastword[:-1] + "ie" lastword += "th" lastwords[-1] = self.title(lastword) outwords[-1] = "-".join(lastwords) return " ".join(outwords) def to_ordinal_num(self, value): self.verify_ordinal(value) return "%s%s" % (value, self.to_ordinal(value)[-2:]) def to_year(self, val, longval=True): if not (val // 100) % 10: return self.to_cardinal(val) return self.to_splitnum(val, hightxt="hundred", jointxt="and", longval=longval) num2words-0.5.6/num2words/lang_EN_IN.py000066400000000000000000000026651320535062200176740ustar00rootroot00000000000000# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from .lang_EN import Num2Word_EN class Num2Word_EN_IN(Num2Word_EN): def set_high_numwords(self, high): self.cards[10 ** 7] = "crore" self.cards[10 ** 5] = "lakh" n2w = Num2Word_EN_IN() to_card = n2w.to_cardinal to_ord = n2w.to_ordinal to_ordnum = n2w.to_ordinal_num def main(): for val in (15000, 15 * 10 ** 5, 15 * 10 ** 6, 15 * 10 ** 7, 15 * 10 ** 8, 15 * 10 ** 9, 15 * 10 ** 10): n2w.test(val) if __name__ == "__main__": main() num2words-0.5.6/num2words/lang_ES.py000066400000000000000000000156021320535062200173060ustar00rootroot00000000000000# encoding: UTF-8 # Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import print_function, unicode_literals from .lang_EU import Num2Word_EU class Num2Word_ES(Num2Word_EU): # //CHECK: Is this sufficient?? def set_high_numwords(self, high): max = 3 + 6 * len(high) for word, n in zip(high, range(max, 3, -6)): self.cards[10 ** (n - 3)] = word + "illón" def setup(self): lows = ["cuatr", "tr", "b", "m"] self.high_numwords = self.gen_high_numwords([], [], lows) self.negword = "menos " self.pointword = "punto" self.errmsg_nonnum = "Solo números pueden ser convertidos a palabras." self.errmsg_toobig = ( "Numero muy grande para ser convertido a palabras." ) self.gender_stem = "o" self.exclude_title = ["y", "menos", "punto"] self.mid_numwords = [(1000, "mil"), (100, "cien"), (90, "noventa"), (80, "ochenta"), (70, "setenta"), (60, "sesenta"), (50, "cincuenta"), (40, "cuarenta"), (30, "treinta")] self.low_numwords = ["veintinueve", "veintiocho", "veintisiete", "veintiséis", "veinticinco", "veinticuatro", "veintitrés", "veintidós", "veintiuno", "veinte", "diecinueve", "dieciocho", "diecisiete", "dieciseis", "quince", "catorce", "trece", "doce", "once", "diez", "nueve", "ocho", "siete", "seis", "cinco", "cuatro", "tres", "dos", "uno", "cero"] self.ords = {1: "primer", 2: "segund", 3: "tercer", 4: "cuart", 5: "quint", 6: "sext", 7: "séptim", 8: "octav", 9: "noven", 10: "décim", 20: "vigésim", 30: "trigésim", 40: "quadragésim", 50: "quincuagésim", 60: "sexagésim", 70: "septuagésim", 80: "octogésim", 90: "nonagésim", 100: "centésim", 200: "ducentésim", 300: "tricentésim", 400: "cuadrigentésim", 500: "quingentésim", 600: "sexcentésim", 700: "septigentésim", 800: "octigentésim", 900: "noningentésim", 1e3: "milésim", 1e6: "millonésim", 1e9: "billonésim", 1e12: "trillonésim", 1e15: "cuadrillonésim"} def merge(self, curr, next): ctext, cnum, ntext, nnum = curr + next if cnum == 1: if nnum < 1000000: return next ctext = "un" elif cnum == 100 and not nnum % 1000 == 0: ctext += "t" + self.gender_stem if nnum < cnum: if cnum < 100: return "%s y %s" % (ctext, ntext), cnum + nnum return "%s %s" % (ctext, ntext), cnum + nnum elif (not nnum % 1000000) and cnum > 1: ntext = ntext[:-3] + "lones" if nnum == 100: if cnum == 5: ctext = "quinien" ntext = "" elif cnum == 7: ctext = "sete" elif cnum == 9: ctext = "nove" ntext += "t" + self.gender_stem + "s" else: ntext = " " + ntext return (ctext + ntext, cnum * nnum) def to_ordinal(self, value): self.verify_ordinal(value) try: if value == 0: text = "" elif value <= 10: text = "%s%s" % (self.ords[value], self.gender_stem) elif value <= 12: text = ( "%s%s%s" % (self.ords[10], self.gender_stem, self.to_ordinal(value - 10)) ) elif value <= 100: dec = (value // 10) * 10 text = ( "%s%s %s" % (self.ords[dec], self.gender_stem, self.to_ordinal(value - dec)) ) elif value <= 1e3: cen = (value // 100) * 100 text = ( "%s%s %s" % (self.ords[cen], self.gender_stem, self.to_ordinal(value - cen)) ) elif value < 1e18: # dec contains the following: # [ 1e3, 1e6): 1e3 # [ 1e6, 1e9): 1e6 # [ 1e9, 1e12): 1e9 # [1e12, 1e15): 1e12 # [1e15, 1e18): 1e15 dec = 10 ** ((((len(str(int(value))) - 1) / 3 - 1) + 1) * 3) part = int(float(value / dec) * dec) cardinal = ( self.to_cardinal(part / dec) if part / dec != 1 else "" ) text = ( "%s%s%s %s" % (cardinal, self.ords[dec], self.gender_stem, self.to_ordinal(value - part)) ) else: text = self.to_cardinal(value) except KeyError: text = self.to_cardinal(value) return text.strip() def to_ordinal_num(self, value): self.verify_ordinal(value) return "%s%s" % (value, "º" if self.gender_stem == 'o' else "ª") def to_currency(self, val, longval=True, old=False): hightxt, lowtxt = "euro/s", "centavo/s" if old: hightxt, lowtxt = "peso/s", "peseta/s" result = self.to_splitnum(val, hightxt=hightxt, lowtxt=lowtxt, divisor=1, jointxt="y", longval=longval) # Handle exception, in spanish is "un euro" and not "uno euro" return result.replace("uno", "un") num2words-0.5.6/num2words/lang_ES_CO.py000066400000000000000000000024471320535062200176720ustar00rootroot00000000000000# encoding: UTF-8 # Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import print_function, unicode_literals from .lang_ES import Num2Word_ES class Num2Word_ES_CO(Num2Word_ES): def to_currency(self, val, longval=True, old=False): result = self.to_splitnum(val, hightxt="peso/s", lowtxt="centavo/s", divisor=1, jointxt="y", longval=longval) # Handle exception, in spanish is "un euro" and not "uno euro" return result.replace("uno", "un") num2words-0.5.6/num2words/lang_ES_VE.py000066400000000000000000000025511320535062200176770ustar00rootroot00000000000000# encoding: UTF-8 # Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import print_function, unicode_literals from .lang_ES import Num2Word_ES class Num2Word_ES_VE(Num2Word_ES): def to_currency(self, val, longval=True, old=False): hightxt = "bolívar/es" if old else "bolívar/es fuerte/s" result = self.to_splitnum( val, hightxt=hightxt, lowtxt="centavo/s", divisor=1, jointxt="y", longval=longval ) # Handle exception, in spanish is "un euro" and not "uno euro" return result.replace("uno", "un") num2words-0.5.6/num2words/lang_EU.py000066400000000000000000000054661320535062200173170ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from .base import Num2Word_Base GENERIC_DOLLARS = ('dollar', 'dollars') GENERIC_CENTS = ('cent', 'cents') class Num2Word_EU(Num2Word_Base): CURRENCY_FORMS = { 'AUD': (GENERIC_DOLLARS, GENERIC_CENTS), 'CAD': (GENERIC_DOLLARS, GENERIC_CENTS), # repalced by EUR 'EEK': (('kroon', 'kroons'), ('sent', 'senti')), 'EUR': (('euro', 'euro'), GENERIC_CENTS), 'GBP': (('pound sterling', 'pounds sterling'), ('penny', 'pence')), # replaced by EUR 'LTL': (('litas', 'litas'), GENERIC_CENTS), # replaced by EUR 'LVL': (('lat', 'lats'), ('santim', 'santims')), 'USD': (GENERIC_DOLLARS, GENERIC_CENTS), 'RUB': (('rouble', 'roubles'), ('kopek', 'kopeks')), 'SEK': (('krona', 'kronor'), ('öre', 'öre')), 'NOK': (('krone', 'kroner'), ('øre', 'øre')), 'PLN': (('zloty', 'zlotys', 'zlotu'), ('grosz', 'groszy')), } CURRENCY_ADJECTIVES = { 'AUD': 'Australian', 'CAD': 'Canadian', 'EEK': 'Estonian', 'USD': 'US', 'RUB': 'Russian', 'NOK': 'Norwegian', } def set_high_numwords(self, high): max = 3 + 6 * len(high) for word, n in zip(high, range(max, 3, -6)): self.cards[10 ** n] = word + "illiard" self.cards[10 ** (n - 3)] = word + "illion" def pluralize(self, n, forms): form = 0 if n == 1 else 1 return forms[form] def base_setup(self): lows = ["non", "oct", "sept", "sext", "quint", "quadr", "tr", "b", "m"] units = ["", "un", "duo", "tre", "quattuor", "quin", "sex", "sept", "octo", "novem"] tens = ["dec", "vigint", "trigint", "quadragint", "quinquagint", "sexagint", "septuagint", "octogint", "nonagint"] self.high_numwords = ["cent"] + self.gen_high_numwords(units, tens, lows) num2words-0.5.6/num2words/lang_FR.py000066400000000000000000000073071320535062200173110ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import print_function, unicode_literals from .lang_EU import Num2Word_EU class Num2Word_FR(Num2Word_EU): def setup(self): Num2Word_EU.setup(self) self.negword = "moins " self.pointword = "virgule" self.errmsg_nonnum = ( u"Seulement des nombres peuvent être convertis en mots." ) self.errmsg_toobig = u"Nombre trop grand pour être converti en mots." self.exclude_title = ["et", "virgule", "moins"] self.mid_numwords = [(1000, "mille"), (100, "cent"), (80, "quatre-vingts"), (60, "soixante"), (50, "cinquante"), (40, "quarante"), (30, "trente")] self.low_numwords = ["vingt", "dix-neuf", "dix-huit", "dix-sept", "seize", "quinze", "quatorze", "treize", "douze", "onze", "dix", "neuf", "huit", "sept", "six", "cinq", "quatre", "trois", "deux", "un", "zéro"] self.ords = { "cinq": "cinquième", "neuf": "neuvième", } def merge(self, curr, next): ctext, cnum, ntext, nnum = curr + next if cnum == 1: if nnum < 1000000: return next else: if (not (cnum - 80) % 100 or not cnum % 100) and ctext[-1] == "s": ctext = ctext[:-1] if cnum < 1000 and nnum != 1000 and \ ntext[-1] != "s" and not nnum % 100: ntext += "s" if nnum < cnum < 100: if nnum % 10 == 1 and cnum != 80: return ("%s et %s" % (ctext, ntext), cnum + nnum) return ("%s-%s" % (ctext, ntext), cnum + nnum) if nnum > cnum: return ("%s %s" % (ctext, ntext), cnum * nnum) return ("%s %s" % (ctext, ntext), cnum + nnum) # Is this right for such things as 1001 - "mille unième" instead of # "mille premier"?? "millième"?? def to_ordinal(self, value): self.verify_ordinal(value) if value == 1: return "premier" word = self.to_cardinal(value) for src, repl in self.ords.items(): if word.endswith(src): word = word[:-len(src)] + repl break else: if word[-1] == "e": word = word[:-1] word = word + "ième" return word def to_ordinal_num(self, value): self.verify_ordinal(value) out = str(value) out += {"1": "er"}.get(out[-1], "me") return out def to_currency(self, val, longval=True, old=False): hightxt = "euro/s" if old: hightxt = "franc/s" return self.to_splitnum(val, hightxt=hightxt, lowtxt="centime/s", divisor=1, jointxt="et", longval=longval) num2words-0.5.6/num2words/lang_FR_CH.py000066400000000000000000000036241320535062200176610ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import print_function, unicode_literals from .lang_FR import Num2Word_FR class Num2Word_FR_CH(Num2Word_FR): def setup(self): Num2Word_FR.setup(self) self.mid_numwords = [(1000, "mille"), (100, "cent"), (90, "nonante"), (80, "huitante"), (70, "septante"), (60, "soixante"), (50, "cinquante"), (40, "quarante"), (30, "trente")] def merge(self, curr, next): ctext, cnum, ntext, nnum = curr + next if cnum == 1: if nnum < 1000000: return next if cnum < 1000 and nnum != 1000 and\ ntext[-1] != "s" and not nnum % 100: ntext += "s" if nnum < cnum < 100: if nnum % 10 == 1: return ("%s et %s" % (ctext, ntext), cnum + nnum) return ("%s-%s" % (ctext, ntext), cnum + nnum) if nnum > cnum: return ("%s %s" % (ctext, ntext), cnum * nnum) return ("%s %s" % (ctext, ntext), cnum + nnum) num2words-0.5.6/num2words/lang_FR_DZ.py000066400000000000000000000022661320535062200177050ustar00rootroot00000000000000# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from .lang_FR import Num2Word_FR class Num2Word_FR_DZ(Num2Word_FR): def to_currency(self, val, longval=True, cents=True, jointxt="virgule"): return self.to_splitnum( val, hightxt="dinard/s", lowtxt="centime/s", divisor=1, jointxt=jointxt, longval=longval, cents=cents ) num2words-0.5.6/num2words/lang_HE.py000066400000000000000000000070131320535062200172700ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import print_function, unicode_literals from .utils import get_digits, splitby3 ZERO = (u'אפס',) ONES = { 1: (u'אחד',), 2: (u'שנים',), 3: (u'שלש',), 4: (u'ארבע',), 5: (u'חמש',), 6: (u'שש',), 7: (u'שבע',), 8: (u'שמנה',), 9: (u'תשע',), } TENS = { 0: (u'עשר',), 1: (u'אחד עשרה',), 2: (u'שנים עשרה',), 3: (u'שלש עשרה',), 4: (u'ארבע עשרה',), 5: (u'חמש עשרה',), 6: (u'שש עשרה',), 7: (u'שבע עשרה',), 8: (u'שמנה עשרה',), 9: (u'תשע עשרה',), } TWENTIES = { 2: (u'עשרים',), 3: (u'שלשים',), 4: (u'ארבעים',), 5: (u'חמישים',), 6: (u'ששים',), 7: (u'שבעים',), 8: (u'שמנים',), 9: (u'תשעים',), } HUNDRED = { 1: (u'מאה',), 2: (u'מאתיים',), 3: (u'מאות',) } THOUSANDS = { 1: (u'אלף',), 2: (u'אלפיים',), } AND = u'ו' def pluralize(n, forms): # gettext implementation: # (n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2) form = 0 if (n % 10 == 1 and n % 100 != 11) else 1 if n != 0 else 2 return forms[form] def int2word(n): if n > 9999: # doesn't yet work for numbers this big raise NotImplementedError() if n == 0: return ZERO[0] words = [] chunks = list(splitby3(str(n))) i = len(chunks) for x in chunks: i -= 1 n1, n2, n3 = get_digits(x) # print str(n3) + str(n2) + str(n1) if n3 > 0: if n3 <= 2: words.append(HUNDRED[n3][0]) else: words.append(ONES[n3][0]) words.append(HUNDRED[3][0]) if n2 > 1: words.append(TWENTIES[n2][0]) if n2 == 1: words.append(TENS[n1][0]) elif n1 > 0 and not (i > 0 and x == 1): words.append(ONES[n1][0]) if i > 0: if i <= 2: words.append(THOUSANDS[i][0]) else: words.append(ONES[i][0]) words.append(THOUSANDS[1][0]) if len(words) > 1: words[-1] = AND + words[-1] return ' '.join(words) def n2w(n): return int2word(int(n)) def to_currency(n, currency='EUR', cents=True, seperator=','): raise NotImplementedError() class Num2Word_HE(object): def to_cardinal(self, number): return n2w(number) def to_ordinal(self, number): raise NotImplementedError() if __name__ == '__main__': yo = Num2Word_HE() nums = [1, 11, 21, 24, 99, 100, 101, 200, 211, 345, 1000, 1011] for num in nums: print(num, yo.to_cardinal(num)) num2words-0.5.6/num2words/lang_ID.py000066400000000000000000000143341320535062200172740ustar00rootroot00000000000000# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import print_function, unicode_literals class Num2Word_ID(): BASE = {0: [], 1: ["satu"], 2: ["dua"], 3: ["tiga"], 4: ["empat"], 5: ["lima"], 6: ["enam"], 7: ["tujuh"], 8: ["delapan"], 9: ["sembilan"]} TENS_TO = {3: "ribu", 6: "juta", 9: "miliar", 12: "triliun", 15: "kuadriliun", 18: "kuantiliun", 21: "sekstiliun", 24: "septiliun", 27: "oktiliun", 30: "noniliun", 33: "desiliun"} errmsg_floatord = "Cannot treat float number as ordinal" errmsg_negord = "Cannot treat negative number as ordinal" errmsg_toobig = "Too large" max_num = 10 ** 36 def split_by_koma(self, number): return str(number).split('.') def split_by_3(self, number): """ starting here, it groups the number by three from the tail '1234567' -> (('1',),('234',),('567',)) :param number:str :rtype:tuple """ blocks = () length = len(number) if length < 3: blocks += ((number,),) else: len_of_first_block = length % 3 if len_of_first_block > 0: first_block = number[0:len_of_first_block], blocks += first_block, for i in range(len_of_first_block, length, 3): next_block = (number[i:i + 3],), blocks += next_block return blocks def spell(self, blocks): """ it adds the list of spelling to the blocks ( ('1',),('034',)) -> (('1',['satu']),('234',['tiga', 'puluh', 'empat']) ) :param blocks: tuple :rtype: tuple """ word_blocks = () first_block = blocks[0] if len(first_block[0]) == 1: if first_block[0] == '0': spelling = ['nol'] else: spelling = self.BASE[int(first_block[0])] elif len(first_block[0]) == 2: spelling = self.puluh(first_block[0]) else: spelling = ( self.ratus(first_block[0][0]) + self.puluh(first_block[0][1:3]) ) word_blocks += (first_block[0], spelling), for block in blocks[1:]: spelling = self.ratus(block[0][0]) + self.puluh(block[0][1:3]) block += spelling, word_blocks += block, return word_blocks def ratus(self, number): # it is used to spell if number == '1': return ['seratus'] elif number == '0': return [] else: return self.BASE[int(number)] + ['ratus'] def puluh(self, number): # it is used to spell if number[0] == '1': if number[1] == '0': return ['sepuluh'] elif number[1] == '1': return ['sebelas'] else: return self.BASE[int(number[1])] + ['belas'] elif number[0] == '0': return self.BASE[int(number[1])] else: return ( self.BASE[int(number[0])] + ['puluh'] + self.BASE[int(number[1])] ) def spell_float(self, float_part): # spell the float number word_list = [] for n in float_part: if n == '0': word_list += ['nol'] continue word_list += self.BASE[int(n)] return ' '.join(['', 'koma'] + word_list) def join(self, word_blocks, float_part): """ join the words by first join lists in the tuple :param word_blocks: tuple :rtype: str """ word_list = [] length = len(word_blocks) - 1 first_block = word_blocks[0], start = 0 if length == 1 and first_block[0][0] == '1': word_list += ['seribu'] start = 1 for i in range(start, length + 1, 1): word_list += word_blocks[i][1] if not word_blocks[i][1]: continue if i == length: break word_list += [self.TENS_TO[(length - i) * 3]] return ' '.join(word_list) + float_part def to_cardinal(self, number): if number >= self.max_num: raise OverflowError(self.errmsg_toobig % (number, self.max_num)) minus = '' if number < 0: minus = 'min ' float_word = '' n = self.split_by_koma(abs(number)) if len(n) == 2: float_word = self.spell_float(n[1]) return minus + self.join(self.spell(self.split_by_3(n[0])), float_word) def to_ordinal(self, number): self.verify_ordinal(number) out_word = self.to_cardinal(number) if out_word == "satu": return "pertama" return "ke" + out_word def to_ordinal_num(self, number): self.verify_ordinal(number) return "ke-" + str(number) def to_currency(self, value): return self.to_cardinal(value) + " rupiah" def to_year(self, value): return self.to_cardinal(value) def verify_ordinal(self, value): if not value == int(value): raise TypeError(self.errmsg_floatord % value) if not abs(value) == value: raise TypeError(self.errmsg_negord % value) num2words-0.5.6/num2words/lang_IT.py000066400000000000000000000164421320535062200173160ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals # Globals # ------- ZERO = "zero" CARDINAL_WORDS = [ ZERO, "uno", "due", "tre", "quattro", "cinque", "sei", "sette", "otto", "nove", "dieci", "undici", "dodici", "tredici", "quattordici", "quindici", "sedici", "diciassette", "diciotto", "diciannove" ] ORDINAL_WORDS = [ ZERO, "primo", "secondo", "terzo", "quarto", "quinto", "sesto", "settimo", "ottavo", "nono", "decimo", "undicesimo", "dodicesimo", "tredicesimo", "quattordicesimo", "quindicesimo", "sedicesimo", "diciassettesimo", "diciottesimo", "diciannovesimo" ] # The script can extrapolate the missing numbers from the base forms. STR_TENS = {2: "venti", 3: "trenta", 4: "quaranta", 6: "sessanta"} # These prefixes are used for extremely big numbers. EXPONENT_PREFIXES = [ ZERO, "m", "b", "tr", "quadr", "quint", "sest", "sett", "ott", "nov", "dec" ] # Utils # ===== def phonetic_contraction(string): return (string .replace("oo", "o") # ex. "centootto" .replace("ao", "o") # ex. "settantaotto" .replace("io", "o") # ex. "ventiotto" .replace("au", "u") # ex. "trentauno" ) def exponent_length_to_string(exponent_length): # We always assume `exponent` to be a multiple of 3. If it's not true, then # Num2Word_IT.big_number_to_cardinal did something wrong. prefix = EXPONENT_PREFIXES[exponent_length // 6] if exponent_length % 6 == 0: return prefix + "ilione" else: return prefix + "iliardo" def accentuate(string): # This is inefficient: it may do several rewritings when deleting # half-sentence accents. However, it is the easiest method and speed is # not crucial (duh), so... return " ".join( # Deletes half-sentence accents and accentuates the last "tre" [w.replace("tré", "tre")[:-3] + "tré" # We shouldn't accentuate a single "tre": is has to be a composite # word. ~~~~~~~~~~ if w[-3:] == "tre" and len(w) > 3 # Deletes half-sentence accents anyway # ~~~~~~~~~~~~~~~~~~~~~~ else w.replace("tré", "tre") for w in string.split() ]) def omitt_if_zero(number_to_string): return "" if number_to_string == ZERO else number_to_string # Main class # ========== class Num2Word_IT: MINUS_PREFIX_WORD = "meno " FLOAT_INFIX_WORD = " virgola " def __init__(self): pass def float_to_words(self, float_number, ordinal=False): if ordinal: prefix = self.to_ordinal(int(float_number)) else: prefix = self.to_cardinal(int(float_number)) float_part = str(float_number).split('.')[1] postfix = " ".join( # Drops the trailing zero and comma [self.to_cardinal(int(c)) for c in float_part] ) return prefix + Num2Word_IT.FLOAT_INFIX_WORD + postfix def tens_to_cardinal(self, number): tens = number // 10 units = number % 10 if tens in STR_TENS: prefix = STR_TENS[tens] else: prefix = CARDINAL_WORDS[tens][:-1] + "anta" postfix = omitt_if_zero(CARDINAL_WORDS[units]) return phonetic_contraction(prefix + postfix) def hundreds_to_cardinal(self, number): hundreds = number // 100 prefix = "cento" if hundreds != 1: prefix = CARDINAL_WORDS[hundreds] + prefix postfix = omitt_if_zero(self.to_cardinal(number % 100)) return phonetic_contraction(prefix + postfix) def thousands_to_cardinal(self, number): thousands = number // 1000 if thousands == 1: prefix = "mille" else: prefix = self.to_cardinal(thousands) + "mila" postfix = omitt_if_zero(self.to_cardinal(number % 1000)) # "mille" and "mila" don't need any phonetic contractions return prefix + postfix def big_number_to_cardinal(self, number): digits = [c for c in str(number)] length = len(digits) if length >= 66: raise NotImplementedError("The given number is too large.") # This is how many digits come before the "illion" term. # cento miliardi => 3 # dieci milioni => 2 # un miliardo => 1 predigits = length % 3 or 3 multiplier = digits[:predigits] exponent = digits[predigits:] # Default infix string: "milione", "biliardo", "sestilione", ecc. infix = exponent_length_to_string(len(exponent)) if multiplier == ["1"]: prefix = "un " else: prefix = self.to_cardinal(int("".join(multiplier))) # Plural form ~~~~~~~~~~~ infix = " " + infix[:-1] + "i" # Read as: Does the value of exponent equal 0? if set(exponent) != set("0"): postfix = self.to_cardinal(int("".join(exponent))) if " e " in postfix: infix += ", " else: infix += " e " else: postfix = "" return prefix + infix + postfix def to_cardinal(self, number): if number < 0: string = Num2Word_IT.MINUS_PREFIX_WORD + self.to_cardinal(-number) elif number % 1 != 0: string = self.float_to_words(number) elif number < 20: string = CARDINAL_WORDS[number] elif number < 100: string = self.tens_to_cardinal(number) elif number < 1000: string = self.hundreds_to_cardinal(number) elif number < 1000000: string = self.thousands_to_cardinal(number) else: string = self.big_number_to_cardinal(number) return accentuate(string) def to_ordinal(self, number): tens = number % 100 # Italian grammar is poorly defined here ¯\_(ツ)_/¯: # centodecimo VS centodieciesimo VS centesimo decimo? is_outside_teens = not 10 < tens < 20 if number < 0: return Num2Word_IT.MINUS_PREFIX_WORD + self.to_ordinal(-number) elif number % 1 != 0: return self.float_to_words(number, ordinal=True) elif number < 20: return ORDINAL_WORDS[number] elif is_outside_teens and tens % 10 == 3: # Gets ride of the accent ~~~~~~~~~~ return self.to_cardinal(number)[:-1] + "eesimo" elif is_outside_teens and tens % 10 == 6: return self.to_cardinal(number) + "esimo" else: string = self.to_cardinal(number)[:-1] if string[-3:] == "mil": string += "l" return string + "esimo" num2words-0.5.6/num2words/lang_LT.py000066400000000000000000000100201320535062200173030ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from .base import Num2Word_Base from .utils import get_digits, splitby3 ZERO = ('nulis',) ONES = { 1: ('vienas',), 2: ('du',), 3: ('trys',), 4: ('keturi',), 5: ('penki',), 6: ('šeši',), 7: ('septyni',), 8: ('aštuoni',), 9: ('devyni',), } TENS = { 0: ('dešimt',), 1: ('vienuolika',), 2: ('dvylika',), 3: ('trylika',), 4: ('keturiolika',), 5: ('penkiolika',), 6: ('šešiolika',), 7: ('septyniolika',), 8: ('aštuoniolika',), 9: ('devyniolika',), } TWENTIES = { 2: ('dvidešimt',), 3: ('trisdešimt',), 4: ('keturiasdešimt',), 5: ('penkiasdešimt',), 6: ('šešiasdešimt',), 7: ('septyniasdešimt',), 8: ('aštuoniasdešimt',), 9: ('devyniasdešimt',), } HUNDRED = ('šimtas', 'šimtai') THOUSANDS = { 1: ('tūkstantis', 'tūkstančiai', 'tūkstančių'), 2: ('milijonas', 'milijonai', 'milijonų'), 3: ('milijardas', 'milijardai', 'milijardų'), 4: ('trilijonas', 'trilijonai', 'trilijonų'), 5: ('kvadrilijonas', 'kvadrilijonai', 'kvadrilijonų'), 6: ('kvintilijonas', 'kvintilijonai', 'kvintilijonų'), 7: ('sikstilijonas', 'sikstilijonai', 'sikstilijonų'), 8: ('septilijonas', 'septilijonai', 'septilijonų'), 9: ('oktilijonas', 'oktilijonai', 'oktilijonų'), 10: ('naintilijonas', 'naintilijonai', 'naintilijonų'), } class Num2Word_LT(Num2Word_Base): CURRENCY_FORMS = { 'LTL': (('litas', 'litai', 'litų'), ('centas', 'centai', 'centų')), 'EUR': (('euras', 'eurai', 'eurų'), ('centas', 'centai', 'centų')), } def setup(self): self.negword = "minus" self.pointword = "kablelis" def set_numwords(self): # @FIXME self.cards[0] = [] def pluralize(self, n, forms): n1, n2, n3 = get_digits(n) if n2 == 1 or n1 == 0 or n == 0: return forms[2] elif n1 == 1: return forms[0] else: return forms[1] def to_cardinal(self, number): n = str(number).replace(',', '.') if '.' in n: left, right = n.split('.') return '%s %s %s' % ( self._int2word(int(left)), self.pointword, self._int2word(int(right)) ) else: return self._int2word(int(n)) def to_ordinal(self, number): raise NotImplementedError() def _int2word(self, n): if n == 0: return ZERO[0] words = [] chunks = list(splitby3(str(n))) i = len(chunks) for x in chunks: i -= 1 n1, n2, n3 = get_digits(x) if n3 > 0: words.append(ONES[n3][0]) if n3 > 1: words.append(HUNDRED[1]) else: words.append(HUNDRED[0]) if n2 > 1: words.append(TWENTIES[n2][0]) if n2 == 1: words.append(TENS[n1][0]) elif n1 > 0: words.append(ONES[n1][0]) if i > 0: words.append(self.pluralize(x, THOUSANDS[i])) return ' '.join(words) num2words-0.5.6/num2words/lang_LV.py000066400000000000000000000130401320535062200173120ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from .base import Num2Word_Base from .utils import get_digits, splitby3 ZERO = ('nulle',) ONES = { 1: ('viens',), 2: ('divi',), 3: ('trīs',), 4: ('četri',), 5: ('pieci',), 6: ('seši',), 7: ('septiņi',), 8: ('astoņi',), 9: ('deviņi',), } TENS = { 0: ('desmit',), 1: ('vienpadsmit',), 2: ('divpadsmit',), 3: ('trīspadsmit',), 4: ('četrpadsmit',), 5: ('piecpadsmit',), 6: ('sešpadsmit',), 7: ('septiņpadsmit',), 8: ('astoņpadsmit',), 9: ('deviņpadsmit',), } TWENTIES = { 2: ('divdesmit',), 3: ('trīsdesmit',), 4: ('četrdesmit',), 5: ('piecdesmit',), 6: ('sešdesmit',), 7: ('septiņdesmit',), 8: ('astoņdesmit',), 9: ('deviņdesmit',), } HUNDRED = ('simts', 'simti', 'simtu') THOUSANDS = { 1: ('tūkstotis', 'tūkstoši', 'tūkstošu'), 2: ('miljons', 'miljoni', 'miljonu'), 3: ('miljards', 'miljardi', 'miljardu'), 4: ('triljons', 'triljoni', 'triljonu'), 5: ('kvadriljons', 'kvadriljoni', 'kvadriljonu'), 6: ('kvintiljons', 'kvintiljoni', 'kvintiljonu'), 7: ('sikstiljons', 'sikstiljoni', 'sikstiljonu'), 8: ('septiljons', 'septiljoni', 'septiljonu'), 9: ('oktiljons', 'oktiljoni', 'oktiljonu'), 10: ('nontiljons', 'nontiljoni', 'nontiljonu'), } GENERIC_DOLLARS = ('dolārs', 'dolāri', 'dolāru') GENERIC_CENTS = ('cents', 'centi', 'centu') GENERIC_KRONA = ('krona', 'kronas', 'kronu') GENERIC_ERA = ('ēre', 'ēras', 'ēru') class Num2Word_LV(Num2Word_Base): """ Sadly we have a legal form (used in legal and finance documents): http://www.eiro.lv/files/upload/files/Eiro_rakstiba-1.pdf https://likumi.lv/doc.php?id=254741 http://eur-lex.europa.eu/legal-content/LV/TXT/HTML/?uri=CELEX:31998R0974&from=LV Source: http://publications.europa.eu/code/lv/lv-5000500.htm """ CURRENCY_FORMS = { 'AUD': (GENERIC_DOLLARS, GENERIC_CENTS), 'CAD': (GENERIC_DOLLARS, GENERIC_CENTS), # repalced by EUR 'EEK': (GENERIC_KRONA, GENERIC_CENTS), 'EUR': (('eiro', 'eiro', 'eiro'), GENERIC_CENTS), 'EUR_LEGAL': (('euro', 'euro', 'euro'), GENERIC_CENTS), 'GBP': ( ('sterliņu mārciņa', 'sterliņu mārciņas', 'sterliņu mārciņu'), ('penss', 'pensi', 'pensu')), # replaced by EUR 'LTL': (('lits', 'liti', 'litu'), GENERIC_CENTS), # replaced by EUR 'LVL': (('lats', 'lati', 'latu'), ('santīms', 'santīmi', 'santīmu')), 'USD': (GENERIC_DOLLARS, GENERIC_CENTS), 'RUB': (('rublis', 'rubļi', 'rubļu'), ('kapeika', 'kapeikas', 'kapeiku')), 'SEK': (GENERIC_KRONA, GENERIC_ERA), 'NOK': (GENERIC_KRONA, GENERIC_ERA), 'PLN': (('zlots', 'zloti', 'zlotu'), ('grasis', 'graši', 'grašu')), } CURRENCY_ADJECTIVES = { 'AUD': 'Austrālijas', 'CAD': 'Kanādas', 'EEK': 'Igaunijas', 'USD': 'ASV', 'RUB': 'Kreivijas', 'SEK': 'Zviedrijas', 'NOK': 'Norvēģijas', } def setup(self): self.negword = "mīnus" self.pointword = "komats" def set_numwords(self): # @FIXME self.cards[0] = [] def to_cardinal(self, number): n = str(number).replace(',', '.') if '.' in n: left, right = n.split('.') return u'%s %s %s' % ( self._int2word(int(left)), self.pointword, self._int2word(int(right)) ) else: return self._int2word(int(n)) def pluralize(self, n, forms): form = 0 if (n % 10 == 1 and n % 100 != 11) else 1 if n != 0 else 2 return forms[form] def to_ordinal(self, number): raise NotImplementedError() def _int2word(self, n): if n == 0: return ZERO[0] words = [] chunks = list(splitby3(str(n))) i = len(chunks) for x in chunks: i -= 1 n1, n2, n3 = get_digits(x) if n3 > 0: if n3 == 1 and n2 == 0 and n1 > 0: words.append(HUNDRED[2]) elif n3 > 1: words.append(ONES[n3][0]) words.append(HUNDRED[1]) else: words.append(HUNDRED[0]) if n2 > 1: words.append(TWENTIES[n2][0]) if n2 == 1: words.append(TENS[n1][0]) elif n1 > 0 and not (i > 0 and x == 1): words.append(ONES[n1][0]) if i > 0 and x != 0: words.append(self.pluralize(x, THOUSANDS[i])) return ' '.join(words) num2words-0.5.6/num2words/lang_NL.py000066400000000000000000000141061320535062200173060ustar00rootroot00000000000000# -*- coding: utf-8 -*- # Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import print_function, unicode_literals from .lang_EU import Num2Word_EU class Num2Word_NL(Num2Word_EU): def set_high_numwords(self, high): max = 3 + 6 * len(high) for word, n in zip(high, range(max, 3, -6)): self.cards[10 ** n] = word + "iljard" self.cards[10 ** (n - 3)] = word + "iljoen" def setup(self): self.negword = "min " self.pointword = "komma" # "Cannot treat float %s as ordinal." self.errmsg_floatord = ( "Het zwevende puntnummer %s kan niet omgezet worden " + "naar een ordernummer." ) # "type(((type(%s)) ) not in [long, int, float]" self.errmsg_nonnum = ( "Alleen nummers (type (%s)) kunnen naar " + "woorden omgezet worden." ) # "Cannot treat negative num %s as ordinal." self.errmsg_negord = ( "Het negatieve getal %s kan niet omgezet " + "worden naar een ordernummer." ) # "abs(%s) must be less than %s." self.errmsg_toobig = "Het getal %s moet minder zijn dan %s." self.exclude_title = [] lows = ["non", "okt", "sept", "sext", "quint", "quadr", "tr", "b", "m"] units = ["", "un", "duo", "tre", "quattuor", "quin", "sex", "sept", "okto", "novem"] tens = ["dez", "vigint", "trigint", "quadragint", "quinquagint", "sexagint", "septuagint", "oktogint", "nonagint"] self.high_numwords = ( ["zend"] + self.gen_high_numwords(units, tens, lows) ) self.mid_numwords = [(1000, "duizend"), (100, "honderd"), (90, "negentig"), (80, "tachtig"), (70, "zeventig"), (60, "zestig"), (50, "vijftig"), (40, "veertig"), (30, "dertig")] self.low_numwords = ["twintig", "negentien", "achttien", "zeventien", "zestien", "vijftien", "veertien", "dertien", "twaalf", "elf", "tien", "negen", "acht", "zeven", "zes", "vijf", "vier", "drie", "twee", "één", "nul"] self.ords = {"één": "eerst", "twee": "tweed", "drie": "derd", "vier": "vierd", "vijf": "vijfd", "zes": "zesd", "zeven": "zevend", "acht": "achtst", "negen": "negend", "tien": "tiend", "elf": "elfd", "twaalf": "twaalfd", "ig": "igst", "erd": "erdst", "end": "endst", "joen": "joenst", "rd": "rdst"} def merge(self, curr, next): ctext, cnum, ntext, nnum = curr + next if cnum == 1: if nnum < 10 ** 6: return next ctext = "een" if nnum > cnum: if nnum >= 10 ** 6: ctext += " " val = cnum * nnum else: if nnum < 10 < cnum < 100: if nnum == 1: ntext = "een" if ntext.endswith("e"): ntext += "ën" # "n" else: ntext += "en" ntext, ctext = ctext, ntext # + "en" elif cnum >= 10 ** 6: ctext += " " val = cnum + nnum word = ctext + ntext return (word, val) def to_ordinal(self, value): self.verify_ordinal(value) outword = self.to_cardinal(value) for key in self.ords: if outword.endswith(key): outword = outword[:len(outword) - len(key)] + self.ords[key] break return outword + "e" def to_ordinal_num(self, value): self.verify_ordinal(value) return str(value) + "." def to_currency(self, val, longval=True, old=False): if old: return self.to_splitnum(val, hightxt="euro/s", lowtxt="cent/s", jointxt="en", longval=longval) return super(Num2Word_NL, self).to_currency(val, jointxt="en", longval=longval) def to_year(self, val, longval=True): if not (val // 100) % 10: return self.to_cardinal(val) return self.to_splitnum(val, hightxt="honderd", longval=longval) n2w = Num2Word_NL() to_card = n2w.to_cardinal to_ord = n2w.to_ordinal to_ordnum = n2w.to_ordinal_num def main(): for val in [1, 7, 8, 12, 17, 62, 81, 91, 99, 100, 101, 102, 155, 180, 300, 308, 832, 1000, 1001, 1061, 1062, 1100, 1500, 1701, 3000, 8280, 8291, 150000, 500000, 3000000, 1000000, 2000001, 1000000000, 2000000000, -21212121211221211111, -2.121212, -1.0000100]: n2w.test(val) n2w.test(3000000) n2w.test(3000000000001) n2w.test(3000000324566) print(n2w.to_currency(112121)) print(n2w.to_year(2000)) print(n2w.to_year(1820)) print(n2w.to_year(2001)) if __name__ == "__main__": main() num2words-0.5.6/num2words/lang_NO.py000066400000000000000000000113621320535062200173120ustar00rootroot00000000000000# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import division, print_function, unicode_literals from . import lang_EU class Num2Word_NO(lang_EU.Num2Word_EU): def set_high_numwords(self, high): max = 3 + 6 * len(high) for word, n in zip(high, range(max, 3, -6)): self.cards[10 ** n] = word + "illard" self.cards[10 ** (n - 3)] = word + "illion" def setup(self): self.negword = "minus " self.pointword = "komma" self.errmsg_nornum = "Bare tall kan bli konvertert til ord." self.exclude_title = ["og", "komma", "minus"] self.mid_numwords = [(1000, "tusen"), (100, "hundre"), (90, "nitti"), (80, "\xe5tti"), (70, "sytti"), (60, "seksti"), (50, "femti"), (40, "f\xf8rti"), (30, "tretti")] self.low_numwords = ["tjue", "nitten", "atten", "sytten", "seksten", "femten", "fjorten", "tretten", "tolv", "elleve", "ti", "ni", "\xe5tte", "syv", "seks", "fem", "fire", "tre", "to", "en", "null"] self.ords = {"en": "f\xf8rste", "to": "andre", "tre": "tredje", "fire": "fjerde", "fem": "femte", "seks": "sjette", "syv": "syvende", "\xe5tte": "\xe5ttende", "ni": "niende", "ti": "tiende", "elleve": "ellevte", "tolv": "tolvte", "tjue": "tjuende"} def merge(self, lpair, rpair): ltext, lnum = lpair rtext, rnum = rpair if lnum == 1 and rnum < 100: return (rtext, rnum) elif 100 > lnum > rnum: return ("%s-%s" % (ltext, rtext), lnum + rnum) elif lnum >= 100 > rnum: return ("%s og %s" % (ltext, rtext), lnum + rnum) elif rnum > lnum: return ("%s %s" % (ltext, rtext), lnum * rnum) return ("%s, %s" % (ltext, rtext), lnum + rnum) def to_ordinal(self, value): self.verify_ordinal(value) outwords = self.to_cardinal(value).split(" ") lastwords = outwords[-1].split("-") lastword = lastwords[-1].lower() try: lastword = self.ords[lastword] except KeyError: if lastword[-2:] == "ti": lastword = lastword + "ende" else: lastword += "de" lastwords[-1] = self.title(lastword) outwords[-1] = "".join(lastwords) return " ".join(outwords) def to_ordinal_num(self, value): self.verify_ordinal(value) return "%s%s" % (value, self.to_ordinal(value)[-2:]) def to_year(self, val, longval=True): if not (val // 100) % 10: return self.to_cardinal(val) return self.to_splitnum(val, hightxt="hundre", jointxt="og", longval=longval) def to_currency(self, val, longval=True): return self.to_splitnum(val, hightxt="krone/r", lowtxt="\xf8re/r", jointxt="og", longval=longval, cents=True) n2w = Num2Word_NO() to_card = n2w.to_cardinal to_ord = n2w.to_ordinal to_ordnum = n2w.to_ordinal_num to_year = n2w.to_year def main(): for val in [1, 11, 12, 21, 31, 33, 71, 80, 81, 91, 99, 100, 101, 102, 155, 180, 300, 308, 832, 1000, 1001, 1061, 1100, 1500, 1701, 3000, 8280, 8291, 150000, 500000, 1000000, 2000000, 2000001, -21212121211221211111, -2.121212, -1.0000100]: n2w.test(val) n2w.test(13253254360678768017687001076010010122121321432104732075403270573) for val in [1, 120, 1000, 1120, 1800, 1976, 2000, 2010, 2099, 2171]: print(val, "er", n2w.to_currency(val)) print(val, "er", n2w.to_year(val)) if __name__ == "__main__": main() num2words-0.5.6/num2words/lang_PL.py000066400000000000000000000102411320535062200173040ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from .base import Num2Word_Base from .utils import get_digits, splitby3 ZERO = ('zero',) ONES = { 1: ('jeden',), 2: ('dwa',), 3: ('trzy',), 4: ('cztery',), 5: ('pięć',), 6: ('sześć',), 7: ('siedem',), 8: ('osiem',), 9: ('dziewięć',), } TENS = { 0: ('dziesięć',), 1: ('jedenaście',), 2: ('dwanaście',), 3: ('trzynaście',), 4: ('czternaście',), 5: ('piętnaście',), 6: ('szesnaście',), 7: ('siedemnaście',), 8: ('osiemnaście',), 9: ('dziewiętnaście',), } TWENTIES = { 2: ('dwadzieścia',), 3: ('trzydzieści',), 4: ('czterdzieści',), 5: ('pięćdziesiąt',), 6: ('sześćdziesiąt',), 7: ('siedemdziesiąt',), 8: ('osiemdziesiąt',), 9: ('dziewięćdzisiąt',), } HUNDREDS = { 1: ('sto',), 2: ('dwieście',), 3: ('trzysta',), 4: ('czterysta',), 5: ('pięćset',), 6: ('sześćset',), 7: ('siedemset',), 8: ('osiemset',), 9: ('dziewęćset',), } THOUSANDS = { 1: ('tysiąc', 'tysiące', 'tysięcy'), # 10^3 2: ('milion', 'miliony', 'milionów'), # 10^6 3: ('miliard', 'miliardy', 'miliardów'), # 10^9 4: ('bilion', 'biliony', 'bilionów'), # 10^12 5: ('biliard', 'biliardy', 'biliardów'), # 10^15 6: ('trylion', 'tryliony', 'trylionów'), # 10^18 7: ('tryliard', 'tryliardy', 'tryliardów'), # 10^21 8: ('kwadrylion', 'kwadryliony', 'kwadrylionów'), # 10^24 9: ('kwaryliard', 'kwadryliardy', 'kwadryliardów'), # 10^27 10: ('kwintylion', 'kwintyliony', 'kwintylionów'), # 10^30 } class Num2Word_PL(Num2Word_Base): CURRENCY_FORMS = { 'PLN': ( ('złoty', 'złote', 'złotych'), ('grosz', 'grosze', 'groszy') ), 'EUR': ( ('euro', 'euro', 'euro'), ('cent', 'centy', 'centów') ), } def setup(self): self.negword = "minus" self.pointword = "przecinek" def set_numwords(self): # @FIXME self.cards[0] = [] def to_cardinal(self, number): n = str(number).replace(',', '.') if '.' in n: left, right = n.split('.') return u'%s %s %s' % ( self._int2word(int(left)), self.pointword, self._int2word(int(right)) ) else: return self._int2word(int(n)) def pluralize(self, n, forms): if n == 1: form = 0 elif 5 > n % 10 > 1 and (n % 100 < 10 or n % 100 > 20): form = 1 else: form = 2 return forms[form] def to_ordinal(self, number): raise NotImplementedError() def _int2word(self, n): if n == 0: return ZERO[0] words = [] chunks = list(splitby3(str(n))) i = len(chunks) for x in chunks: i -= 1 n1, n2, n3 = get_digits(x) if n3 > 0: words.append(HUNDREDS[n3][0]) if n2 > 1: words.append(TWENTIES[n2][0]) if n2 == 1: words.append(TENS[n1][0]) elif n1 > 0 and not (i > 0 and x == 1): words.append(ONES[n1][0]) if i > 0: words.append(self.pluralize(x, THOUSANDS[i])) return ' '.join(words) num2words-0.5.6/num2words/lang_PT_BR.py000066400000000000000000000153731320535062200177120ustar00rootroot00000000000000# -*- coding: utf-8 -*- # Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import division, unicode_literals import re from . import lang_EU class Num2Word_PT_BR(lang_EU.Num2Word_EU): def set_high_numwords(self, high): max = 3 + 3*len(high) for word, n in zip(high, range(max, 3, -3)): self.cards[10**n] = word + "ilhão" def setup(self): self.negword = "menos " self.pointword = "vírgula" self.errmsg_nornum = "Somente números podem ser convertidos para " \ "palavras" self.exclude_title = ["e", "vírgula", "menos"] self.mid_numwords = [ (1000, "mil"), (100, "cem"), (90, "noventa"), (80, "oitenta"), (70, "setenta"), (60, "sessenta"), (50, "cinquenta"), (40, "quarenta"), (30, "trinta") ] self.low_numwords = [ "vinte", "dezenove", "dezoito", "dezessete", "dezesseis", "quinze", "catorze", "treze", "doze", "onze", "dez", "nove", "oito", "sete", "seis", "cinco", "quatro", "três", "dois", "um", "zero" ] self.ords = [ { 0: "", 1: "primeiro", 2: "segundo", 3: "terceiro", 4: "quarto", 5: "quinto", 6: "sexto", 7: "sétimo", 8: "oitavo", 9: "nono", }, { 0: "", 1: "décimo", 2: "vigésimo", 3: "trigésimo", 4: "quadragésimo", 5: "quinquagésimo", 6: "sexagésimo", 7: "septuagésimo", 8: "octogésimo", 9: "nonagésimo", }, { 0: "", 1: "centésimo", 2: "ducentésimo", 3: "tricentésimo", 4: "quadrigentésimo", 5: "quingentésimo", 6: "seiscentésimo", 7: "septigentésimo", 8: "octigentésimo", 9: "nongentésimo", }, ] self.thousand_separators = { 3: "milésimo", 6: "milionésimo", 9: "bilionésimo", 12: "trilionésimo", 15: "quadrilionésimo" } self.hundreds = { 1: "cento", 2: "duzentos", 3: "trezentos", 4: "quatrocentos", 5: "quinhentos", 6: "seiscentos", 7: "setecentos", 8: "oitocentos", 9: "novecentos", } def merge(self, curr, next): ctext, cnum, ntext, nnum = curr + next if cnum == 1: if nnum < 1000000: return next ctext = "um" elif cnum == 100 and not nnum == 1000: ctext = "cento" if nnum < cnum: if cnum < 100: return ("%s e %s" % (ctext, ntext), cnum + nnum) return ("%s e %s" % (ctext, ntext), cnum + nnum) elif (not nnum % 1000000) and cnum > 1: ntext = ntext[:-4] + "lhões" if nnum == 100: ctext = self.hundreds[cnum] ntext = "" else: ntext = " " + ntext return (ctext + ntext, cnum * nnum) def to_cardinal(self, value): result = super(Num2Word_PT_BR, self).to_cardinal(value) # Transforms "mil E cento e catorze reais" into "mil, cento e catorze # reais" for ext in ( 'mil', 'milhão', 'milhões', 'bilhão', 'bilhões', 'trilhão', 'trilhões', 'quatrilhão', 'quatrilhões'): if re.match('.*{} e \w*ento'.format(ext), result): result = result.replace( '{} e'.format(ext), '{},'.format(ext), 1 ) return result def to_ordinal(self, value): self.verify_ordinal(value) result = [] value = str(value) thousand_separator = '' for idx, char in enumerate(value[::-1]): if idx and idx % 3 == 0: thousand_separator = self.thousand_separators[idx] if char != '0' and thousand_separator: # avoiding "segundo milionésimo milésimo" for 6000000, # for instance result.append(thousand_separator) thousand_separator = '' result.append(self.ords[idx % 3][int(char)]) result = ' '.join(result[::-1]) result = result.strip() result = re.sub('\s+', ' ', result) if result.startswith('primeiro') and value != '1': # avoiding "primeiro milésimo", "primeiro milionésimo" and so on result = result[9:] return result def to_ordinal_num(self, value): self.verify_ordinal(value) return "%sº" % (value) def to_year(self, val, longval=True): if val < 0: return self.to_cardinal(abs(val)) + ' antes de Cristo' return self.to_cardinal(val) def to_currency(self, val, longval=True): integer_part, decimal_part = ('%.2f' % val).split('.') result = self.to_cardinal(int(integer_part)) appended_currency = False for ext in ( 'milhão', 'milhões', 'bilhão', 'bilhões', 'trilhão', 'trilhões', 'quatrilhão', 'quatrilhões'): if result.endswith(ext): result += ' de reais' appended_currency = True if result in ['um', 'menos um']: result += ' real' appended_currency = True if not appended_currency: result += ' reais' if int(decimal_part): cents = self.to_cardinal(int(decimal_part)) result += ' e ' + cents if cents == 'um': result += ' centavo' else: result += ' centavos' return result num2words-0.5.6/num2words/lang_RU.py000066400000000000000000000124511320535062200173240ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from .base import Num2Word_Base from .utils import get_digits, splitby3 ZERO = ('ноль',) ONES_FEMININE = { 1: ('одна',), 2: ('две',), 3: ('три',), 4: ('четыре',), 5: ('пять',), 6: ('шесть',), 7: ('семь',), 8: ('восемь',), 9: ('девять',), } ONES = { 1: ('один',), 2: ('два',), 3: ('три',), 4: ('четыре',), 5: ('пять',), 6: ('шесть',), 7: ('семь',), 8: ('восемь',), 9: ('девять',), } TENS = { 0: ('десять',), 1: ('одиннадцать',), 2: ('двенадцать',), 3: ('тринадцать',), 4: ('четырнадцать',), 5: ('пятнадцать',), 6: ('шестнадцать',), 7: ('семнадцать',), 8: ('восемнадцать',), 9: ('девятнадцать',), } TWENTIES = { 2: ('двадцать',), 3: ('тридцать',), 4: ('сорок',), 5: ('пятьдесят',), 6: ('шестьдесят',), 7: ('семьдесят',), 8: ('восемьдесят',), 9: ('девяносто',), } HUNDREDS = { 1: ('сто',), 2: ('двести',), 3: ('триста',), 4: ('четыреста',), 5: ('пятьсот',), 6: ('шестьсот',), 7: ('семьсот',), 8: ('восемьсот',), 9: ('девятьсот',), } THOUSANDS = { 1: ('тысяча', 'тысячи', 'тысяч'), # 10^3 2: ('миллион', 'миллиона', 'миллионов'), # 10^6 3: ('миллиард', 'миллиарда', 'миллиардов'), # 10^9 4: ('триллион', 'триллиона', 'триллионов'), # 10^12 5: ('квадриллион', 'квадриллиона', 'квадриллионов'), # 10^15 6: ('квинтиллион', 'квинтиллиона', 'квинтиллионов'), # 10^18 7: ('секстиллион', 'секстиллиона', 'секстиллионов'), # 10^21 8: ('септиллион', 'септиллиона', 'септиллионов'), # 10^24 9: ('октиллион', 'октиллиона', 'октиллионов'), # 10^27 10: ('нониллион', 'нониллиона', 'нониллионов'), # 10^30 } class Num2Word_RU(Num2Word_Base): CURRENCY_FORMS = { 'RUB': ( ('рубль', 'рубля', 'рублей'), ('копейка', 'копейки', 'копеек') ), 'EUR': ( ('евро', 'евро', 'евро'), ('цент', 'цента', 'центов') ), } def setup(self): self.negword = "минус" self.pointword = "запятая" def set_numwords(self): # @FIXME self.cards[0] = [] def to_cardinal(self, number): n = str(number).replace(',', '.') if '.' in n: left, right = n.split('.') return u'%s %s %s' % ( self._int2word(int(left)), self.pointword, self._int2word(int(right)) ) else: return self._int2word(int(n)) def pluralize(self, n, forms): if n % 100 < 10 or n % 100 > 20: if n % 10 == 1: form = 0 elif 5 > n % 10 > 1: form = 1 else: form = 2 else: form = 2 return forms[form] def to_ordinal(self, number): raise NotImplementedError() def _cents_verbose(self, number, currency): return self._int2word(number, currency == 'RUB') def _int2word(self, n, feminine=False): if n < 0: return ' '.join([self.negword, self._int2word(abs(n))]) if n == 0: return ZERO[0] words = [] chunks = list(splitby3(str(n))) i = len(chunks) for x in chunks: i -= 1 n1, n2, n3 = get_digits(x) if n3 > 0: words.append(HUNDREDS[n3][0]) if n2 > 1: words.append(TWENTIES[n2][0]) if n2 == 1: words.append(TENS[n1][0]) elif n1 > 0: ones = ONES_FEMININE if i == 1 or feminine and i == 0 else ONES words.append(ones[n1][0]) if i > 0 and x != 0: words.append(self.pluralize(x, THOUSANDS[i])) return ' '.join(words) num2words-0.5.6/num2words/lang_SL.py000066400000000000000000000136111320535062200173130ustar00rootroot00000000000000# -*- coding: utf-8 -*- # Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # Copyright (c) 2015, Blaz Bregar. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA # -*- coding: utf-8 -*- from __future__ import unicode_literals from .lang_EU import Num2Word_EU class Num2Word_SL(Num2Word_EU): def set_high_numwords(self, high): max = 3 + 6*len(high) for word, n in zip(high, range(max, 3, -6)): self.cards[10**n] = word + "iljard" self.cards[10**(n-3)] = word + "iljon" def setup(self): self.negword = "minus " self.pointword = "celih" self.errmsg_nonnum = "Only numbers may be converted to words." self.errmsg_toobig = "Number is too large to convert to words." self.exclude_title = [] self.mid_numwords = [(1000, "tisoč"), (900, "devetsto"), (800, "osemsto"), (700, "sedemsto"), (600, "šesto"), (500, "petsto"), (400, "štiristo"), (300, "tristo"), (200, "dvesto"), (100, "sto"), (90, "devetdeset"), (80, "osemdeset"), (70, "sedemdeset"), (60, "šestdeset"), (50, "petdeset"), (40, "štirideset"), (30, "trideset")] self.low_numwords = ["dvajset", "devetnajst", "osemnajst", "sedemnajst", "šestnajst", "petnajst", "štirinajst", "trinajst", "dvanajst", "enajst", "deset", "devet", "osem", "sedem", "šest", "pet", "štiri", "tri", "dve", "ena", "nič"] self.ords = {"ena": "prv", "dve": "drug", "tri": "tretj", "štiri": "četrt", "sedem": "sedm", "osem": "osm", "sto": "stot", "tisoč": "tisoč", "miljon": "miljont" } self.ordflag = False def merge(self, curr, next): ctext, cnum, ntext, nnum = curr + next if ctext == "dve" and not self.ordflag: ctext = "dva" if cnum == 1: if nnum < 10**6 or self.ordflag: return next ctext = "" if nnum > cnum: if nnum >= 10**6: if self.ordflag: ntext += "t" elif cnum == 2: if ntext.endswith("d"): ntext += "i" else: ntext += "a" elif 2 < cnum < 5: if ntext.endswith("d"): ntext += "e" elif not ntext.endswith("d"): ntext += "i" else: if ntext.endswith("d"): ntext += "" elif ntext.endswith("d"): ntext += "e" else: ntext += "ov" if nnum >= 10**2 and self.ordflag is False: ctext += " " val = cnum * nnum else: if nnum < 10 < cnum < 100: ntext, ctext = ctext, ntext + "in" elif cnum >= 10**2 and self.ordflag is False: ctext += " " val = cnum + nnum word = ctext + ntext return (word, val) def to_ordinal(self, value): self.verify_ordinal(value) self.ordflag = True outword = self.to_cardinal(value) self.ordflag = False for key in self.ords: if outword.endswith(key): outword = outword[:len(outword) - len(key)] + self.ords[key] break return outword + "i" # Is this correct?? def to_ordinal_num(self, value): self.verify_ordinal(value) return str(value) + "." def to_currency(self, val, longval=True, old=False): if old: return self.to_splitnum(val, hightxt="evro/a/v", lowtxt="stotin/a/i/ov", jointxt="in", longval=longval) return super(Num2Word_SL, self).to_currency(val, jointxt="in", longval=longval) def to_year(self, val, longval=True): if not (val//100) % 10: return self.to_cardinal(val) return self.to_splitnum(val, hightxt="hundert", longval=longval) n2w = Num2Word_SL() to_card = n2w.to_cardinal to_ord = n2w.to_ordinal to_ordnum = n2w.to_ordinal_num def main(): for val in [1, 11, 12, 21, 31, 33, 71, 80, 81, 91, 99, 100, 101, 102, 155, 180, 300, 308, 832, 1000, 1001, 1061, 1100, 1500, 1701, 3000, 8280, 8291, 150000, 500000, 1000000, 2000000, 2000001, -21212121211221211111, -2.121212, -1.0000100]: n2w.test(val) n2w.test(13253254360678768017687001076010010122121321432104732075403270573) print(n2w.to_currency(112121)) print(n2w.to_year(2000)) if __name__ == "__main__": main() num2words-0.5.6/num2words/lang_TR.py000066400000000000000000001143441320535062200173270ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # Copyright (c) 2017, Tufan Kaynak, Framras. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals class Num2Word_TR(object): def __init__(self): self.precision = 2 self.negword = u"eksi" self.pointword = u"virgül" self.CURRENCY_UNIT = (u"lira",) self.CURRENCY_SUBUNIT = (u"kuruş",) self.errmsg_nonnum = u"Sadece sayılar yazıya çevrilebilir." self.errmsg_floatord = u"Tam sayı olmayan {} sıralamada kullanılamaz." self.errmsg_negord = u"Pozitif olmayan {} sıralamada kullanılamaz." self.errmsg_toobig = u"abs({}) sayı yazıya çevirmek için çok büyük. " \ u"Yazıya çevrilebilecek en büyük rakam {}." self.exclude_title = [] self.DECIMAL_SIGN = (",",) self.ORDINAL_SIGN = (".",) self.ZERO = (u"sıfır",) self.CARDINAL_ONES = { "1": u"bir", "2": u"iki", "3": u"üç", "4": u"dört", "5": u"beş", "6": u"altı", "7": u"yedi", "8": u"sekiz", "9": u"dokuz" } self.ORDINAL_ONES = { "1": u"birinci", "2": u"ikinci", "3": u"üçüncü", "4": u"dördüncü", "5": u"beşinci", "6": u"altıncı", "7": u"yedinci", "8": u"sekizinci", "9": u"dokuzuncu" } self.CARDINAL_TENS = { "1": u"on", "2": u"yirmi", "3": u"otuz", "4": u"kırk", "5": u"elli", "6": u"altmış", "7": u"yetmiş", "8": u"seksen", "9": u"doksan" } self.ORDINAL_TENS = { "1": u"onuncu", "2": u"yirminci", "3": u"otuzuncu", "4": u"kırkıncı", "5": u"ellinci", "6": u"altmışıncı", "7": u"yetmişinci", "8": u"sekseninci", "9": u"doksanıncı" } self.HUNDREDS = { "2": u"iki", "3": u"üç", "4": u"dört", "5": u"beş", "6": u"altı", "7": u"yedi", "8": u"sekiz", "9": u"dokuz" } self.CARDINAL_HUNDRED = (u"yüz",) self.ORDINAL_HUNDRED = (u"yüzüncü",) self.CARDINAL_TRIPLETS = { 1: u"bin", 2: u"milyon", 3: u"milyar", 4: u"trilyon", 5: u"katrilyon", 6: u"kentilyon" } self.ORDINAL_TRIPLETS = { 1: u"bininci", 2: u"milyonuncu", 3: u"milyarıncı", 4: u"trilyonuncu", 5: u"katrilyonuncu", 6: u"kentilyon" } self.MAXVAL = (10 ** ((len(self.CARDINAL_TRIPLETS) + 1) * 3)) - 1 self.integers_to_read = [] self.total_triplets_to_read = 0 self.total_digits_outside_triplets = 0 self.order_of_last_zero_digit = 0 def to_cardinal(self, value): wrd = "" is_cardinal = self.verify_cardinal(value) if not is_cardinal: return wrd if not int(value) == value: return self.to_cardinal_float(value) self.to_splitnum(value) if self.order_of_last_zero_digit >= len(self.integers_to_read[0]): # number like 00 and all 0s and even more, raise error return wrd if self.total_triplets_to_read == 1: if self.total_digits_outside_triplets == 2: if self.order_of_last_zero_digit == 1: # number like x0, read cardinal x0 and return wrd += self.CARDINAL_TENS.get( self.integers_to_read[0][0], "" ) return wrd if self.order_of_last_zero_digit == 0: # number like xy, read cardinal xy and return wrd += self.CARDINAL_TENS.get( self.integers_to_read[0][0], "" ) wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][1], "" ) return wrd if self.total_digits_outside_triplets == 1: if self.order_of_last_zero_digit == 0: # number like x, read cardinal x and return wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][0], "" ) return wrd if self.total_digits_outside_triplets == 0: if self.order_of_last_zero_digit == 2: # number like x00, read cardinal x00 and return wrd += self.HUNDREDS.get( self.integers_to_read[0][0], "" ) wrd += self.CARDINAL_HUNDRED[0] return wrd if self.order_of_last_zero_digit == 1: # number like xy0, read cardinal xy0 and return wrd += self.HUNDREDS.get( self.integers_to_read[0][0], "" ) wrd += self.CARDINAL_HUNDRED[0] wrd += self.CARDINAL_TENS.get( self.integers_to_read[0][1], "" ) return wrd if self.order_of_last_zero_digit == 0: # number like xyz, read cardinal xyz and return wrd += self.HUNDREDS.get( self.integers_to_read[0][0], "" ) wrd += self.CARDINAL_HUNDRED[0] wrd += self.CARDINAL_TENS.get( self.integers_to_read[0][1], "" ) wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][2], "" ) return wrd if self.total_triplets_to_read >= 2: if self.total_digits_outside_triplets == 2: if self.order_of_last_zero_digit == len( self.integers_to_read[0]) - 1: # number like x0 and all 0s, read cardinal x0 0..0 # and return wrd += self.CARDINAL_TENS.get( self.integers_to_read[0][0], "" ) wrd += self.CARDINAL_TRIPLETS[ self.total_triplets_to_read - 1 ] return wrd if self.order_of_last_zero_digit == len( self.integers_to_read[0]) - 2: # number like xy and all 0s, read cardinal xy 0..0 # and return wrd += self.CARDINAL_TENS.get( self.integers_to_read[0][0], "" ) wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][1], "" ) wrd += self.CARDINAL_TRIPLETS[ self.total_triplets_to_read - 1 ] return wrd if self.order_of_last_zero_digit < len( self.integers_to_read[0]) - 2: # number like xy and others, read cardinal xy n..n # and return wrd += self.CARDINAL_TENS.get( self.integers_to_read[0][0], "" ) wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][1], "" ) wrd += self.CARDINAL_TRIPLETS[ self.total_triplets_to_read - 1 ] if self.total_digits_outside_triplets == 1: if self.order_of_last_zero_digit == len( self.integers_to_read[0]) - 1: # number like x and all 0s, read cardinal x 0..0 # and return if not (self.total_triplets_to_read == 2 and self.integers_to_read[0][0] == "1"): wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][0], "" ) wrd += self.CARDINAL_TRIPLETS[ self.total_triplets_to_read - 1 ] return wrd if self.order_of_last_zero_digit < len( self.integers_to_read[0]) - 1: # number like x and others, read cardinal x n..n # and return if not (self.total_triplets_to_read == 2 and self.integers_to_read[0][0] == "1"): wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][0], "" ) wrd += self.CARDINAL_TRIPLETS[ self.total_triplets_to_read - 1 ] if self.total_digits_outside_triplets == 0: if self.order_of_last_zero_digit == len( self.integers_to_read[0]) - 1: # number like x00 and all 0s, read cardinal x00 0..0 # and return wrd += self.HUNDREDS.get(self.integers_to_read[0][0], "") wrd += self.CARDINAL_HUNDRED[0] wrd += self.CARDINAL_TRIPLETS[ self.total_triplets_to_read - 1 ] return wrd if self.order_of_last_zero_digit == len( self.integers_to_read[0]) - 2: # number like xy0 and all 0s, read cardinal xy0 0..0 # and return wrd += self.HUNDREDS.get( self.integers_to_read[0][0], "" ) wrd += self.CARDINAL_HUNDRED[0] wrd += self.CARDINAL_TENS.get( self.integers_to_read[0][1], "" ) wrd += self.CARDINAL_TRIPLETS[ self.total_triplets_to_read - 1 ] return wrd if self.order_of_last_zero_digit == len( self.integers_to_read[0]) - 3: # number like xyz and all 0s, read cardinal xyz 0..0 # and return wrd += self.HUNDREDS.get(self.integers_to_read[0][0], "") wrd += self.CARDINAL_HUNDRED[0] wrd += self.CARDINAL_TENS.get( self.integers_to_read[0][1], "" ) wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][2], "" ) wrd += self.CARDINAL_TRIPLETS[ self.total_triplets_to_read - 1 ] return wrd if self.order_of_last_zero_digit < len( self.integers_to_read[0]) - 3: # number like xyz and all others, read cardinal xyz n..n wrd += self.HUNDREDS.get(self.integers_to_read[0][0], "") wrd += self.CARDINAL_HUNDRED[0] wrd += self.CARDINAL_TENS.get( self.integers_to_read[0][1], "" ) if not (self.total_triplets_to_read == 2 and self.integers_to_read[0][2] == "1"): wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][2], "" ) wrd += self.CARDINAL_TRIPLETS[ self.total_triplets_to_read - 1 ] for i in list(range(self.total_triplets_to_read - 1, 0, -1)): reading_triplet_order = self.total_triplets_to_read - i if self.total_digits_outside_triplets == 0: last_read_digit_order = reading_triplet_order * 3 else: last_read_digit_order = (reading_triplet_order - 1) * 3 +\ self.total_digits_outside_triplets if not self.integers_to_read[0][ last_read_digit_order: last_read_digit_order + 3 ] == "000": if not self.integers_to_read[0][ last_read_digit_order ] == "0": wrd += self.HUNDREDS.get( self.integers_to_read[0][last_read_digit_order], "" ) if self.order_of_last_zero_digit == len( self.integers_to_read[0]) - ( last_read_digit_order) - 1: if i == 1: wrd += self.CARDINAL_HUNDRED[0] return wrd elif i > 1: wrd += self.CARDINAL_HUNDRED[0] wrd += self.CARDINAL_TRIPLETS[i - 1] return wrd else: wrd += self.CARDINAL_HUNDRED[0] if not self.integers_to_read[0][ last_read_digit_order + 1] == "0": if self.order_of_last_zero_digit == len( self.integers_to_read[0]) - ( last_read_digit_order) - 2: if i == 1: wrd += self.CARDINAL_TENS.get( self.integers_to_read[0][ last_read_digit_order + 1], "" ) return wrd elif i > 1: wrd += self.CARDINAL_TENS.get( self.integers_to_read[0][ last_read_digit_order + 1], "" ) wrd += self.CARDINAL_TRIPLETS[i - 1] return wrd else: wrd += self.CARDINAL_TENS.get( self.integers_to_read[0][ last_read_digit_order + 1], "" ) if not self.integers_to_read[0][ last_read_digit_order + 2] == "0": if self.order_of_last_zero_digit == len( self.integers_to_read[0]) - ( last_read_digit_order) - 3: if i == 1: wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][ last_read_digit_order + 2], "" ) return wrd if i == 2: if not self.integers_to_read[0][ last_read_digit_order: last_read_digit_order + 2 ] == "00": wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][ last_read_digit_order + 2], "" ) elif not self.integers_to_read[0][ last_read_digit_order + 2] == "1": wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][ last_read_digit_order + 2], "" ) wrd += self.CARDINAL_TRIPLETS[i - 1] return wrd if i > 2: wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][ last_read_digit_order + 2], "" ) wrd += self.CARDINAL_TRIPLETS[i - 1] return wrd else: if not self.integers_to_read[0][ last_read_digit_order: last_read_digit_order + 2 ] == "00": wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][ last_read_digit_order + 2], "" ) else: if i == 2: if not self.integers_to_read[0][ last_read_digit_order: last_read_digit_order + 2 ] == "00": wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][ last_read_digit_order + 2], "" ) elif not self.integers_to_read[0][ last_read_digit_order + 2 ] == "1": wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][ last_read_digit_order + 2], "" ) wrd += self.CARDINAL_TRIPLETS[i - 1] return wrd def to_cardinal_float(self, value): self.to_splitnum(value) wrd = "" wrd += self.pointword if len(self.integers_to_read[1]) >= 1: wrd += self.CARDINAL_TENS.get(self.integers_to_read[1][0], "") if len(self.integers_to_read[1]) == 2: wrd += self.CARDINAL_ONES.get(self.integers_to_read[1][1], "") if self.integers_to_read[0] == "0": wrd = self.ZERO[0] + wrd else: wrd = self.to_cardinal(int(self.integers_to_read[0])) + wrd return wrd def verify_cardinal(self, value): iscardinal = True try: if not float(value) == value: iscardinal = False except (ValueError, TypeError): raise TypeError(self.errmsg_nonnum) if abs(value) >= self.MAXVAL: raise OverflowError(self.errmsg_toobig.format(value, self.MAXVAL)) return iscardinal def verify_ordinal(self, value): isordinal = True try: if not int(value) == value: isordinal = False if not abs(value) == value: raise TypeError(self.errmsg_negord.format(value)) except (ValueError, TypeError): raise TypeError(self.errmsg_nonnum) if abs(value) >= self.MAXVAL: raise OverflowError(self.errmsg_toobig.format(value, self.MAXVAL)) return isordinal def to_ordinal(self, value): wrd = "" isordinal = self.verify_ordinal(value) if isordinal: self.to_splitnum(value) if self.order_of_last_zero_digit >= len(self.integers_to_read[0]): # number like 00 and all 0s and even more, raise error return wrd if self.total_triplets_to_read == 1: if self.total_digits_outside_triplets == 2: if self.order_of_last_zero_digit == 1: # number like x0, read ordinal x0 and return wrd += self.ORDINAL_TENS.get( self.integers_to_read[0][0], "" ) return wrd if self.order_of_last_zero_digit == 0: # number like xy, read ordinal xy and return wrd += self.CARDINAL_TENS.get( self.integers_to_read[0][0], "" ) wrd += self.ORDINAL_ONES.get( self.integers_to_read[0][1], "" ) return wrd if self.total_digits_outside_triplets == 1: if self.order_of_last_zero_digit == 0: # number like x, read ordinal x and return wrd += self.ORDINAL_ONES.get( self.integers_to_read[0][0], "" ) return wrd if self.total_digits_outside_triplets == 0: if self.order_of_last_zero_digit == 2: # number like x00, read ordinal x00 and return wrd += self.HUNDREDS.get( self.integers_to_read[0][0], "" ) wrd += self.ORDINAL_HUNDRED[0] return wrd if self.order_of_last_zero_digit == 1: # number like xy0, read ordinal xy0 and return wrd += self.HUNDREDS.get( self.integers_to_read[0][0], "" ) wrd += self.CARDINAL_HUNDRED[0] wrd += self.ORDINAL_TENS.get( self.integers_to_read[0][1], "" ) return wrd if self.order_of_last_zero_digit == 0: # number like xyz, read ordinal xyz and return wrd += self.HUNDREDS.get( self.integers_to_read[0][0], "" ) wrd += self.CARDINAL_HUNDRED[0] wrd += self.CARDINAL_TENS.get( self.integers_to_read[0][1], "" ) if not self.integers_to_read[0][2] == "0": wrd += self.ORDINAL_ONES.get( self.integers_to_read[0][2], "" ) return wrd if self.total_triplets_to_read >= 2: if self.total_digits_outside_triplets == 2: if self.order_of_last_zero_digit == len( self.integers_to_read[0]) - 1: # number like x0 and all 0s, read ordinal x0 0..0 # and return wrd += self.CARDINAL_TENS.get( self.integers_to_read[0][0], "" ) wrd += self.ORDINAL_TRIPLETS[ self.total_triplets_to_read - 1 ] return wrd if self.order_of_last_zero_digit == len( self.integers_to_read[0]) - 2: # number like xy and all 0s, read ordinal xy 0..0 # and return wrd += self.CARDINAL_TENS.get( self.integers_to_read[0][0], "" ) wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][1], "" ) wrd += self.ORDINAL_TRIPLETS[ self.total_triplets_to_read - 1 ] return wrd if self.order_of_last_zero_digit < len( self.integers_to_read[0]) - 2: # number like xy and others, read cardinal xy n..n # and return wrd += self.CARDINAL_TENS.get( self.integers_to_read[0][0], "" ) wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][1], "" ) wrd += self.CARDINAL_TRIPLETS[ self.total_triplets_to_read - 1 ] if self.total_digits_outside_triplets == 1: if self.order_of_last_zero_digit == len( self.integers_to_read[0]) - 1: # number like x and all 0s, read ordinal x 0..0 # and return if not (self.total_triplets_to_read == 2 and self.integers_to_read[0][0] == "1"): wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][0], "" ) wrd += self.ORDINAL_TRIPLETS[ self.total_triplets_to_read - 1 ] return wrd if self.order_of_last_zero_digit < len( self.integers_to_read[0]) - 1: # number like x and others, read cardinal x n..n # and return if not (self.total_triplets_to_read == 2 and self.integers_to_read[0][0] == "1"): wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][0], "" ) wrd += self.CARDINAL_TRIPLETS[ self.total_triplets_to_read - 1 ] if self.total_digits_outside_triplets == 0: if self.order_of_last_zero_digit == len( self.integers_to_read[0]) - 1: # number like x00 and all 0s, read ordinal x00 0..0 # and return wrd += self.HUNDREDS.get( self.integers_to_read[0][0], "" ) wrd += self.CARDINAL_HUNDRED[0] wrd += self.ORDINAL_TRIPLETS[ self.total_triplets_to_read - 1 ] return wrd if self.order_of_last_zero_digit == len( self.integers_to_read[0]) - 2: # number like xy0 and all 0s, read ordinal xy0 0..0 # and return wrd += self.HUNDREDS.get( self.integers_to_read[0][0], "" ) wrd += self.CARDINAL_HUNDRED[0] wrd += self.CARDINAL_TENS.get( self.integers_to_read[0][1], "" ) wrd += self.ORDINAL_TRIPLETS[ self.total_triplets_to_read - 1 ] return wrd if self.order_of_last_zero_digit == len( self.integers_to_read[0]) - 3: # number like xyz and all 0s, read ordinal xyz 0..0 # and return wrd += self.HUNDREDS.get( self.integers_to_read[0][0], "" ) wrd += self.CARDINAL_HUNDRED[0] wrd += self.CARDINAL_TENS.get( self.integers_to_read[0][1], "" ) wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][2], "" ) wrd += self.ORDINAL_TRIPLETS[ self.total_triplets_to_read - 1 ] return wrd if self.order_of_last_zero_digit < len( self.integers_to_read[0]) - 3: # number like xyz and all others, read cardinal # xyz n..n wrd += self.HUNDREDS.get( self.integers_to_read[0][0], "" ) wrd += self.CARDINAL_HUNDRED[0] wrd += self.CARDINAL_TENS.get( self.integers_to_read[0][1], "" ) if not (self.total_triplets_to_read == 2 and self.integers_to_read[0][2] == "1"): wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][2], "" ) wrd += self.CARDINAL_TRIPLETS[ self.total_triplets_to_read - 1 ] for i in list(range(self.total_triplets_to_read - 1, 0, -1)): reading_triplet_order = self.total_triplets_to_read - i if self.total_digits_outside_triplets == 0: last_read_digit_order = reading_triplet_order * 3 else: last_read_digit_order = \ (reading_triplet_order - 1) * 3 + \ self.total_digits_outside_triplets if not self.integers_to_read[0][ last_read_digit_order: last_read_digit_order + 3 ] == "000": if not self.integers_to_read[0][ last_read_digit_order ] == "0": if not self.integers_to_read[0][ last_read_digit_order ] == "1": wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][ last_read_digit_order ], "" ) if self.order_of_last_zero_digit == len( self.integers_to_read[0]) - ( last_read_digit_order) - 1: if i == 1: wrd += self.ORDINAL_HUNDRED[0] return wrd elif i > 1: wrd += self.CARDINAL_HUNDRED[0] wrd += self.ORDINAL_TRIPLETS[i - 1] return wrd else: wrd += self.CARDINAL_HUNDRED[0] if not self.integers_to_read[0][ last_read_digit_order + 1 ] == "0": if self.order_of_last_zero_digit == len( self.integers_to_read[0]) - ( last_read_digit_order) - 2: if i == 1: wrd += self.ORDINAL_TENS.get( self.integers_to_read[0][ last_read_digit_order + 1], "" ) return wrd elif i > 1: wrd += self.CARDINAL_TENS.get( self.integers_to_read[0][ last_read_digit_order + 1], "" ) wrd += self.ORDINAL_TRIPLETS[i - 1] return wrd else: wrd += self.CARDINAL_TENS.get( self.integers_to_read[0][ last_read_digit_order + 1], "" ) if not self.integers_to_read[0][ last_read_digit_order + 2 ] == "0": if self.order_of_last_zero_digit == len( self.integers_to_read[0]) - ( last_read_digit_order) - 3: if i == 1: wrd += self.ORDINAL_ONES.get( self.integers_to_read[0][ last_read_digit_order + 2], "" ) return wrd if i == 2: if not self.integers_to_read[0][ last_read_digit_order: last_read_digit_order + 2] == "00": wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][ last_read_digit_order + 2], "" ) elif not self.integers_to_read[0][ last_read_digit_order + 2 ] == "1": wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][ last_read_digit_order + 2], "" ) wrd += self.ORDINAL_TRIPLETS[i - 1] return wrd if i > 2: wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][ last_read_digit_order + 2], "" ) wrd += self.ORDINAL_TRIPLETS[i - 1] return wrd else: if not self.integers_to_read[0][ last_read_digit_order: last_read_digit_order + 2] == "00": wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][ last_read_digit_order + 2], "" ) else: if not self.integers_to_read[0][ last_read_digit_order: last_read_digit_order + 2] == "00": wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][ last_read_digit_order + 2], "" ) elif not self.integers_to_read[0][ last_read_digit_order + 2] == "1": wrd += self.CARDINAL_ONES.get( self.integers_to_read[0][ last_read_digit_order + 2], "" ) wrd += self.CARDINAL_TRIPLETS[i - 1] return wrd def to_splitnum(self, val): float_digits = str(int(val * 10 ** self.precision)) if not int(val) == 0: self.integers_to_read = [ str(int(val)), float_digits[len(float_digits) - self.precision:] ] else: self.integers_to_read = [ "0", "0" * (self.precision - len(float_digits)) + float_digits[len(float_digits) - self.precision:] ] if len(self.integers_to_read[0]) % 3 > 0: self.total_triplets_to_read = (len(self.integers_to_read[0]) // 3)\ + 1 elif len(self.integers_to_read[0]) % 3 == 0: self.total_triplets_to_read = len(self.integers_to_read[0]) // 3 self.total_digits_outside_triplets = len(self.integers_to_read[0]) % 3 okunacak = list(self.integers_to_read[0][::-1]) self.order_of_last_zero_digit = 0 found = 0 for i in range(len(okunacak) - 1): if int(okunacak[i]) == 0 and found == 0: self.order_of_last_zero_digit = i + 1 else: found = 1 def to_currency(self, value): valueparts = self.to_cardinal(value).split(self.pointword) if len(valueparts) == 1: return valueparts[0] + self.CURRENCY_UNIT[0] if len(valueparts) == 2: return self.CURRENCY_UNIT[0].join(valueparts) + \ self.CURRENCY_SUBUNIT[0] num2words-0.5.6/num2words/lang_UK.py000066400000000000000000000124711320535062200173170ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from .base import Num2Word_Base from .utils import get_digits, splitby3 ZERO = ('нуль',) ONES_FEMININE = { 1: ('одна',), 2: ('двi',), 3: ('три',), 4: ('чотири',), 5: ('п\'ять',), 6: ('шiсть',), 7: ('сiм',), 8: ('вiсiм',), 9: ('дев\'ять',), } ONES = { 1: ('один',), 2: ('два',), 3: ('три',), 4: ('чотири',), 5: ('п\'ять',), 6: ('шiсть',), 7: ('сiм',), 8: ('вiсiм',), 9: ('дев\'ять',), } TENS = { 0: ('десять',), 1: ('одинадцять',), 2: ('дванадцять',), 3: ('тринадцять',), 4: ('чотирнадцять',), 5: ('п\'ятнадцять',), 6: ('шiстнадцять',), 7: ('сiмнадцять',), 8: ('вiсiмнадцять',), 9: ('дев\'ятнадцять',), } TWENTIES = { 2: ('двадцять',), 3: ('тридцять',), 4: ('сорок',), 5: ('п\'ятдесят',), 6: ('шiстдесят',), 7: ('сiмдесят',), 8: ('вiсiмдесят',), 9: ('дев\'яносто',), } HUNDREDS = { 1: ('сто',), 2: ('двiстi',), 3: ('триста',), 4: ('чотириста',), 5: ('п\'ятсот',), 6: ('шiстсот',), 7: ('сiмсот',), 8: ('вiсiмсот',), 9: ('дев\'ятсот',), } THOUSANDS = { 1: ('тисяча', 'тисячi', 'тисяч'), # 10^3 2: ('мiльйон', 'мiльйони', 'мiльйонiв'), # 10^6 3: ('мiльярд', 'мiльярди', 'мiльярдiв'), # 10^9 4: ('трильйон', 'трильйони', 'трильйонiв'), # 10^12 5: ('квадрильйон', 'квадрильйони', 'квадрильйонiв'), # 10^15 6: ('квiнтильйон', 'квiнтильйони', 'квiнтильйонiв'), # 10^18 7: ('секстильйон', 'секстильйони', 'секстильйонiв'), # 10^21 8: ('септильйон', 'септильйони', 'септильйонiв'), # 10^24 9: ('октильйон', 'октильйони', 'октильйонiв'), # 10^27 10: ('нонiльйон', 'нонiльйони', 'нонiльйонiв'), # 10^30 } class Num2Word_UK(Num2Word_Base): CURRENCY_FORMS = { 'UAH': ( ('гривня', 'гривнi', 'гривень'), ('копiйка', 'копiйки', 'копiйок') ), 'EUR': ( ('евро', 'евро', 'евро'), ('цент', 'центи', 'центiв') ), } def setup(self): self.negword = "мiнус" self.pointword = "кома" def set_numwords(self): # @FIXME self.cards[0] = [] def to_cardinal(self, number): n = str(number).replace(',', '.') if '.' in n: left, right = n.split('.') return '%s %s %s' % ( self._int2word(int(left)), self.pointword, self._int2word(int(right)) ) else: return self._int2word(int(n)) def pluralize(self, n, forms): if n % 100 < 10 or n % 100 > 20: if n % 10 == 1: form = 0 elif 5 > n % 10 > 1: form = 1 else: form = 2 else: form = 2 return forms[form] def _int2word(self, n, feminine=True): if n < 0: return ' '.join([self.negword, self._int2word(abs(n))]) if n == 0: return ZERO[0] words = [] chunks = list(splitby3(str(n))) i = len(chunks) for x in chunks: i -= 1 n1, n2, n3 = get_digits(x) if n3 > 0: words.append(HUNDREDS[n3][0]) if n2 > 1: words.append(TWENTIES[n2][0]) if n2 == 1: words.append(TENS[n1][0]) # elif n1 > 0 and not (i > 0 and x == 1): elif n1 > 0: ones = ONES_FEMININE if i == 1 or feminine and i == 0 else ONES words.append(ones[n1][0]) if i > 0 and ((n1 + n2 + n3) > 0): words.append(self.pluralize(x, THOUSANDS[i])) return ' '.join(words) def _cents_verbose(self, number, currency): return self._int2word(number, currency == 'UAH') def to_ordinal(self, number): raise NotImplementedError() num2words-0.5.6/num2words/lang_VN.py000066400000000000000000000100671320535062200173220ustar00rootroot00000000000000# -*- coding: utf-8 -*- # Copyright (c) 2003, Taro Ogawa. All Rights Reserved. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals to_19 = (u'không', u'một', u'hai', u'ba', u'bốn', u'năm', u'sáu', u'bảy', u'tám', u'chín', u'mười', u'mười một', u'mười hai', u'mười ba', u'mười bốn', u'mười lăm', u'mười sáu', u'mười bảy', u'mười tám', u'mười chín') tens = (u'hai mươi', u'ba mươi', u'bốn mươi', u'năm mươi', u'sáu mươi', u'bảy mươi', u'tám mươi', u'chín mươi') denom = ('', u'nghìn', u'triệu', u'tỷ', u'nghìn tỷ', u'trăm nghìn tỷ', 'Quintillion', 'Sextillion', 'Septillion', 'Octillion', 'Nonillion', 'Decillion', 'Undecillion', 'Duodecillion', 'Tredecillion', 'Quattuordecillion', 'Sexdecillion', 'Septendecillion', 'Octodecillion', 'Novemdecillion', 'Vigintillion') class Num2Word_VN(object): def _convert_nn(self, val): if val < 20: return to_19[val] for (dcap, dval) in ((k, 20 + (10 * v)) for (v, k) in enumerate(tens)): if dval + 10 > val: if val % 10: a = u'lăm' if to_19[val % 10] == u'một': a = u'mốt' else: a = to_19[val % 10] if to_19[val % 10] == u'năm': a = u'lăm' return dcap + ' ' + a return dcap def _convert_nnn(self, val): word = '' (mod, rem) = (val % 100, val // 100) if rem > 0: word = to_19[rem] + u' trăm' if mod > 0: word = word + ' ' if mod > 0 and mod < 10: if mod == 5: word = word != '' and word + u'lẻ năm' or word + u'năm' else: word = word != '' and word + u'lẻ ' \ + self._convert_nn(mod) or word + self._convert_nn(mod) if mod >= 10: word = word + self._convert_nn(mod) return word def vietnam_number(self, val): if val < 100: return self._convert_nn(val) if val < 1000: return self._convert_nnn(val) for (didx, dval) in ((v - 1, 1000 ** v) for v in range(len(denom))): if dval > val: mod = 1000 ** didx lval = val // mod r = val - (lval * mod) ret = self._convert_nnn(lval) + u' ' + denom[didx] if 99 >= r > 0: ret = self._convert_nnn(lval) + u' ' + denom[didx] + u' lẻ' if r > 0: ret = ret + ' ' + self.vietnam_number(r) return ret def number_to_text(self, number): number = '%.2f' % number the_list = str(number).split('.') start_word = self.vietnam_number(int(the_list[0])) final_result = start_word if len(the_list) > 1 and int(the_list[1]) > 0: end_word = self.vietnam_number(int(the_list[1])) final_result = final_result + ' phẩy ' + end_word return final_result def to_cardinal(self, number): return self.number_to_text(number) def to_ordinal(self, number): return self.to_cardinal(number) num2words-0.5.6/num2words/utils.py000066400000000000000000000005071320535062200171340ustar00rootroot00000000000000def splitby3(n): length = len(n) if length > 3: start = length % 3 if start > 0: yield int(n[:start]) for i in range(start, length, 3): yield int(n[i:i+3]) else: yield int(n) def get_digits(n): return [int(x) for x in reversed(list(('%03d' % n)[-3:]))] num2words-0.5.6/requirements-test.txt000066400000000000000000000000731320535062200177210ustar00rootroot00000000000000flake8 flake8-copyright isort pep8<1.6 coverage coveralls num2words-0.5.6/setup.py000066400000000000000000000025451320535062200152000ustar00rootroot00000000000000from setuptools import find_packages, setup CLASSIFIERS = [ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'License :: OSI Approved :: GNU Library or Lesser General Public License ' '(LGPL)', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Topic :: Software Development :: Internationalization', 'Topic :: Software Development :: Libraries :: Python Modules', 'Topic :: Software Development :: Localization', 'Topic :: Text Processing :: Linguistic', ] LONG_DESC = open('README.rst', 'rt').read() + '\n\n' + \ open('CHANGES.rst', 'rt').read() setup( name='num2words', version='0.5.6', description='Modules to convert numbers to words. Easily extensible.', long_description=LONG_DESC, license='LGPL', author='Taro Ogawa ', author_email='tos@users.sourceforge.net', maintainer='Savoir-faire Linux inc.', maintainer_email='ernesto.rodriguezortiz@savoirfairelinux.com', keywords=' number word numbers words convert conversion i18n ' 'localisation localization internationalisation ' 'internationalization', url='https://github.com/savoirfairelinux/num2words', packages=find_packages(exclude=['tests']), test_suite='tests', classifiers=CLASSIFIERS, ) num2words-0.5.6/tests/000077500000000000000000000000001320535062200146225ustar00rootroot00000000000000num2words-0.5.6/tests/__init__.py000066400000000000000000000000001320535062200167210ustar00rootroot00000000000000num2words-0.5.6/tests/test_ar.py000066400000000000000000000037361320535062200166460ustar00rootroot00000000000000# encoding: UTF-8 # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from unittest import TestCase from num2words import num2words TEST_CASES_CARDINAL = ( (1, 'واحد'), (2, 'اثنين'), (11, 'أحد عشر'), (12, 'اثناعشر'), (20, 'عشرين'), (21, 'واحد وعشرين'), (26, 'ستة وعشرين'), (30, 'ثلاثين'), (67, 'سبعة وستين'), (70, 'سبعين'), (100, 'مئة'), (101, 'مئة و واحد'), (199, 'مئة و تسعة وتسعين'), (203, 'مئتين و ثلاثة'), (1000, 'ألف'), (1001, 'ألف و واحد'), (1097, 'ألف و سبعة وتسعين'), (1000000, 'مليون'), (1000001, 'مليون و واحد'), ) TEST_CASES_ORDINAL = ( (1, 'أول'), (8, 'ثامن'), (12, 'ثاني عشر'), (100, 'مئة'), ) class Num2WordsARTest(TestCase): def test_number(self): for test in TEST_CASES_CARDINAL: self.assertEqual(num2words(test[0], lang='ar'), test[1]) def test_ordinal(self): for test in TEST_CASES_ORDINAL: self.assertEqual( num2words(test[0], lang='ar', ordinal=True), test[1] ) num2words-0.5.6/tests/test_currency.py000066400000000000000000000021751320535062200200720ustar00rootroot00000000000000from decimal import Decimal from unittest import TestCase from num2words.currency import parse_currency_parts class CurrencyTestCase(TestCase): def test_parse_currency_parts(self): # integer cents self.assertEqual(parse_currency_parts(101), (1, 1, False)) self.assertEqual(parse_currency_parts(-123), (1, 23, True)) # decimal self.assertEqual(parse_currency_parts(Decimal("1.01")), (1, 1, False)) self.assertEqual(parse_currency_parts(Decimal("-1.23")), (1, 23, True)) self.assertEqual(parse_currency_parts(Decimal("-1.233")), (1, 23, True)) # string self.assertEqual(parse_currency_parts("1.01"), (1, 1, False)) self.assertEqual(parse_currency_parts("-1.23"), (1, 23, True)) self.assertEqual(parse_currency_parts("-1.2"), (1, 20, True)) self.assertEqual(parse_currency_parts("1"), (1, 0, False)) # float self.assertEqual(parse_currency_parts(1.01), (1, 1, False)) self.assertEqual(parse_currency_parts(-1.23), (1, 23, True)) self.assertEqual(parse_currency_parts(-1.2), (1, 20, True)) num2words-0.5.6/tests/test_de.py000066400000000000000000000051601320535062200166250ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from unittest import TestCase from num2words import num2words class Num2WordsDETest(TestCase): def test_ordinal_less_than_twenty(self): self.assertEqual(num2words(7, ordinal=True, lang='de'), "siebte") self.assertEqual(num2words(8, ordinal=True, lang='de'), "achte") self.assertEqual(num2words(12, ordinal=True, lang='de'), "zwölfte") self.assertEqual(num2words(17, ordinal=True, lang='de'), "siebzehnte") def test_ordinal_more_than_twenty(self): self.assertEqual( num2words(81, ordinal=True, lang='de'), "einundachtzigste" ) def test_ordinal_at_crucial_number(self): self.assertEqual( num2words(100, ordinal=True, lang='de'), "hundertste" ) self.assertEqual( num2words(1000, ordinal=True, lang='de'), "tausendste" ) self.assertEqual( num2words(4000, ordinal=True, lang='de'), "viertausendste" ) self.assertEqual( num2words(2000000, ordinal=True, lang='de'), "zwei millionenste" ) self.assertEqual( num2words(5000000000, ordinal=True, lang='de'), "fünf milliardenste" ) def test_cardinal_at_some_numbers(self): self.assertEqual(num2words(2000000, lang='de'), "zwei millionen") self.assertEqual(num2words(4000000000, lang='de'), "vier milliarden") def test_cardinal_for_decimal_number(self): self.assertEqual( num2words(3.486, lang='de'), "drei Komma vier acht sechs" ) def test_ordinal_for_negative_numbers(self): self.assertRaises(TypeError, num2words, -12, ordinal=True, lang='de') def test_ordinal_for_floating_numbers(self): self.assertRaises(TypeError, num2words, 2.453, ordinal=True, lang='de') num2words-0.5.6/tests/test_en.py000066400000000000000000000050141320535062200166350ustar00rootroot00000000000000# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from unittest import TestCase from num2words import num2words class Num2WordsENTest(TestCase): def test_and_join_199(self): # ref https://github.com/savoirfairelinux/num2words/issues/8 self.assertEqual(num2words(199), "one hundred and ninety-nine") def test_cardinal_for_float_number(self): # issue 24 self.assertEqual(num2words(12.5), "twelve point five") self.assertEqual(num2words(12.51), "twelve point five one") self.assertEqual(num2words(12.53), "twelve point five three") self.assertEqual(num2words(12.59), "twelve point five nine") def test_to_currency(self): self.assertEqual( num2words('38.4', lang='en', to='currency', seperator=' and', cents=False, currency='USD'), "thirty-eight dollars and 40 cents" ) self.assertEqual( num2words('0', lang='en', to='currency', seperator=' and', cents=False, currency='USD'), "zero dollars and 00 cents" ) self.assertEqual( num2words('1.01', lang='en', to='currency', seperator=' and', cents=True, currency='USD'), "one dollar and one cent" ) self.assertEqual( num2words('4778.00', lang='en', to='currency', seperator=' and', cents=True, currency='USD', adjective=True), 'four thousand, seven hundred and seventy-eight US dollars' ' and zero cents') self.assertEqual( num2words('4778.00', lang='en', to='currency', seperator=' and', cents=True, currency='USD'), 'four thousand, seven hundred and seventy-eight dollars and' ' zero cents') num2words-0.5.6/tests/test_es.py000066400000000000000000000120161320535062200166420ustar00rootroot00000000000000# encoding: UTF-8 # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from unittest import TestCase from num2words import num2words TEST_CASES_CARDINAL = ( (1, 'uno'), (2, 'dos'), (3, 'tres'), (5.5, 'cinco punto cinco'), (11, 'once'), (12, 'doce'), (16, 'dieciseis'), (17.42, 'diecisiete punto cuatro dos'), (19, 'diecinueve'), (20, 'veinte'), (21, 'veintiuno'), (26, 'veintiséis'), (27.312, 'veintisiete punto tres uno dos'), (28, 'veintiocho'), (30, 'treinta'), (31, 'treinta y uno'), (40, 'cuarenta'), (44, 'cuarenta y cuatro'), (50, 'cincuenta'), (53.486, 'cincuenta y tres punto cuatro ocho seis'), (55, 'cincuenta y cinco'), (60, 'sesenta'), (67, 'sesenta y siete'), (70, 'setenta'), (79, 'setenta y nueve'), (89, 'ochenta y nueve'), (95, 'noventa y cinco'), (100, 'cien'), (101, 'ciento uno'), (199, 'ciento noventa y nueve'), (203, 'doscientos tres'), (287, 'doscientos ochenta y siete'), (300.42, 'trescientos punto cuatro dos'), (356, 'trescientos cincuenta y seis'), (400, 'cuatrocientos'), (434, 'cuatrocientos treinta y cuatro'), (578, 'quinientos setenta y ocho'), (689, 'seiscientos ochenta y nueve'), (729, 'setecientos veintinueve'), (894, 'ochocientos noventa y cuatro'), (999, 'novecientos noventa y nueve'), (1000, 'mil'), (1001, 'mil uno'), (1097, 'mil noventa y siete'), (1104, 'mil ciento cuatro'), (1243, 'mil doscientos cuarenta y tres'), (2385, 'dos mil trescientos ochenta y cinco'), (3766, 'tres mil setecientos sesenta y seis'), (4196, 'cuatro mil ciento noventa y seis'), (4196.42, 'cuatro mil ciento noventa y seis punto cuatro dos'), (5846, 'cinco mil ochocientos cuarenta y seis'), (6459, 'seis mil cuatrocientos cincuenta y nueve'), (7232, 'siete mil doscientos treinta y dos'), (8569, 'ocho mil quinientos sesenta y nueve'), (9539, 'nueve mil quinientos treinta y nueve'), (1000000, 'un millón'), (1000001, 'un millón uno'), (4000000, 'cuatro millones'), (10000000000000, 'diez billones'), (100000000000000, 'cien billones'), (1000000000000000000, 'un trillón'), (1000000000000000000000, 'mil trillones'), (10000000000000000000000000, 'diez cuatrillones') ) TEST_CASES_ORDINAL = ( (1, 'primero'), (8, 'octavo'), (12, 'décimosegundo'), (14, 'décimo cuarto'), (28, 'vigésimo octavo'), (100, 'centésimo'), (1000, 'milésimo'), (1000000, 'millonésimo'), (1000000000000000, 'cuadrillonésimo'), (1000000000000000000, 'un trillón') # over 1e18 is not supported ) TEST_CASES_ORDINAL_NUM = ( (1, '1º'), (8, '8º'), (12, '12º'), (14, '14º'), (28, '28º'), (100, '100º'), (1000, '1000º'), (1000000, '1000000º') ) TEST_CASES_TO_CURRENCY = ( (1, 'un euro'), (2, 'dos euros'), (8, 'ocho euros'), (12, 'doce euros'), (21, 'veintiun euros'), (81.25, 'ochenta y un euros y veinticinco centavos'), (100, 'cien euros'), ) TEST_CASES_TO_CURRENCY_OLD = ( (1, 'un peso'), (2, 'dos pesos'), (8, 'ocho pesos'), (12, 'doce pesos'), (21, 'veintiun pesos'), (81.25, 'ochenta y un pesos y veinticinco pesetas'), (100, 'cien pesos'), ) class Num2WordsESTest(TestCase): def test_number(self): for test in TEST_CASES_CARDINAL: self.assertEqual(num2words(test[0], lang='es'), test[1]) def test_ordinal(self): for test in TEST_CASES_ORDINAL: self.assertEqual( num2words(test[0], lang='es', ordinal=True), test[1] ) def test_ordinal_num(self): for test in TEST_CASES_ORDINAL_NUM: self.assertEqual( num2words(test[0], lang='es', to='ordinal_num'), test[1] ) def test_currency(self): for test in TEST_CASES_TO_CURRENCY: self.assertEqual( num2words(test[0], lang='es', to='currency'), test[1] ) def test_currency_old(self): for test in TEST_CASES_TO_CURRENCY_OLD: self.assertEqual( num2words(test[0], lang='es', to='currency', old=True), test[1] ) num2words-0.5.6/tests/test_es_co.py000066400000000000000000000036641320535062200173340ustar00rootroot00000000000000# encoding: UTF-8 # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from num2words import num2words from . import test_es TEST_CASES_TO_CURRENCY = ( (1, 'un peso'), (2, 'dos pesos'), (8, 'ocho pesos'), (12, 'doce pesos'), (21, 'veintiun pesos'), (81.25, 'ochenta y un pesos y veinticinco centavos'), (100, 'cien pesos'), ) class Num2WordsESCOTest(test_es.Num2WordsESTest): def test_number(self): for test in test_es.TEST_CASES_CARDINAL: self.assertEqual(num2words(test[0], lang='es_CO'), test[1]) def test_ordinal(self): for test in test_es.TEST_CASES_ORDINAL: self.assertEqual( num2words(test[0], lang='es_CO', ordinal=True), test[1] ) def test_ordinal_num(self): for test in test_es.TEST_CASES_ORDINAL_NUM: self.assertEqual( num2words(test[0], lang='es', to='ordinal_num'), test[1] ) def test_currency(self): for test in TEST_CASES_TO_CURRENCY: self.assertEqual( num2words(test[0], lang='es_CO', to='currency'), test[1] ) num2words-0.5.6/tests/test_es_ve.py000066400000000000000000000037401320535062200173400ustar00rootroot00000000000000# encoding: UTF-8 # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from num2words import num2words from . import test_es TEST_CASES_TO_CURRENCY = ( (1, 'un bolívar'), (2, 'dos bolívares'), (8, 'ocho bolívares'), (12, 'doce bolívares'), (21, 'veintiun bolívares'), (81.25, 'ochenta y un bolívares y veinticinco centavos'), (100, 'cien bolívares'), ) class Num2WordsESVETest(test_es.Num2WordsESTest): def test_number(self): for test in test_es.TEST_CASES_CARDINAL: self.assertEqual(num2words(test[0], lang='es_VE'), test[1]) def test_ordinal(self): for test in test_es.TEST_CASES_ORDINAL: self.assertEqual( num2words(test[0], lang='es_VE', ordinal=True), test[1] ) def test_ordinal_num(self): for test in test_es.TEST_CASES_ORDINAL_NUM: self.assertEqual( num2words(test[0], lang='es', to='ordinal_num'), test[1] ) def test_currency(self): for test in TEST_CASES_TO_CURRENCY: self.assertEqual( num2words(test[0], lang='es_VE', to='currency', old=True), test[1] ) num2words-0.5.6/tests/test_fr.py000066400000000000000000000131251320535062200166440ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # Copetright (c) 2015, Savoir-faire Linux inc. All Rights Reserved. # This libraret is free software; etou can redistribute it and/or # modifet it under the terms of the GNU Lesser General Public # License as published bet the Free Software Foundation; either # version 2.1 of the License, or (at etour option) anet later version. # This libraret is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warrantet of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copet of the GNU Lesser General Public # License along with this libraret; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from unittest import TestCase from num2words import num2words TEST_CASES_CARDINAL = ( (1, 'un'), (2, 'deux'), (3, 'trois'), (5.5, 'cinq virgule cinq'), (11, 'onze'), (12, 'douze'), (16, 'seize'), (17.42, 'dix-sept virgule quatre deux'), (19, 'dix-neuf'), (20, 'vingt'), (21, 'vingt et un'), (26, 'vingt-six'), (27.312, 'vingt-sept virgule trois un deux'), (28, 'vingt-huit'), (30, 'trente'), (31, 'trente et un'), (40, 'quarante'), (44, 'quarante-quatre'), (50, 'cinquante'), (53.486, 'cinquante-trois virgule quatre huit six'), (55, 'cinquante-cinq'), (60, 'soixante'), (67, 'soixante-sept'), (70, 'soixante-dix'), (79, 'soixante-dix-neuf'), (89, 'quatre-vingt-neuf'), (95, 'quatre-vingt-quinze'), (100, 'cent'), (101, 'cent un'), (199, 'cent quatre-vingt-dix-neuf'), (203, 'deux cent trois'), (287, 'deux cent quatre-vingt-sept'), (300.42, 'trois cents virgule quatre deux'), (356, 'trois cent cinquante-six'), (400, 'quatre cents'), (434, 'quatre cent trente-quatre'), (578, 'cinq cent soixante-dix-huit'), (689, 'six cent quatre-vingt-neuf'), (729, 'sept cent vingt-neuf'), (894, 'huit cent quatre-vingt-quatorze'), (999, 'neuf cent quatre-vingt-dix-neuf'), (1000, 'mille'), (1001, 'mille un'), (1097, 'mille quatre-vingt-dix-sept'), (1104, 'mille cent quatre'), (1243, 'mille deux cent quarante-trois'), (2385, 'deux mille trois cent quatre-vingt-cinq'), (3766, 'trois mille sept cent soixante-six'), (4196, 'quatre mille cent quatre-vingt-seize'), (4196.42, 'quatre mille cent quatre-vingt-seize virgule quatre deux'), (5846, 'cinq mille huit cent quarante-six'), (6459, 'six mille quatre cent cinquante-neuf'), (7232, 'sept mille deux cent trente-deux'), (8569, 'huit mille cinq cent soixante-neuf'), (9539, 'neuf mille cinq cent trente-neuf'), (1000000, 'un million'), (1000001, 'un million un'), (4000000, 'quatre millions'), (10000000000000, 'dix billions'), (100000000000000, 'cent billions'), (1000000000000000000, 'un trillion'), (1000000000000000000000, 'un trilliard'), (10000000000000000000000000, 'dix quadrillions') ) TEST_CASES_ORDINAL = ( (1, 'premier'), (8, 'huitième'), (12, 'douzième'), (14, 'quatorzième'), (28, 'vingt-huitième'), (100, 'centième'), (1000, 'millième'), (1000000, 'un millionième'), (1000000000000000, 'un billiardième'), (1000000000000000000, 'un trillionième') # over 1e18 is not supported ) TEST_CASES_ORDINAL_NUM = ( (1, '1er'), (8, '8me'), (12, '12me'), (14, '14me'), (28, '28me'), (100, '100me'), (1000, '1000me'), (1000000, '1000000me') ) TEST_CASES_TO_CURRENCY = ( (1, 'un euro'), (2, 'deux euros'), (8, 'huit euros'), (12, 'douze euros'), (21, 'vingt et un euros'), (81.25, 'quatre-vingt-un euros et vingt-cinq centimes'), (100, 'cent euros'), ) TEST_CASES_TO_CURRENCY_OLD = ( (1, 'un franc'), (2, 'deux francs'), (8, 'huit francs'), (12, 'douze francs'), (21, 'vingt et un francs'), (81.25, 'quatre-vingt-un francs et vingt-cinq centimes'), (100, 'cent francs'), ) class Num2WordsENTest(TestCase): def test_ordinal_special_joins(self): # ref https://github.com/savoirfairelinux/num2words/issues/18 self.assertEqual( num2words(5, ordinal=True, lang='fr'), "cinquième" ) self.assertEqual( num2words(35, ordinal=True, lang='fr'), "trente-cinquième" ) self.assertEqual( num2words(9, ordinal=True, lang='fr'), "neuvième" ) self.assertEqual( num2words(49, ordinal=True, lang='fr'), "quarante-neuvième" ) def test_number(self): for test in TEST_CASES_CARDINAL: self.assertEqual(num2words(test[0], lang='fr'), test[1]) def test_ordinal(self): for test in TEST_CASES_ORDINAL: self.assertEqual( num2words(test[0], lang='fr', ordinal=True), test[1] ) def test_ordinal_num(self): for test in TEST_CASES_ORDINAL_NUM: self.assertEqual( num2words(test[0], lang='fr', to='ordinal_num'), test[1] ) def test_currency(self): for test in TEST_CASES_TO_CURRENCY: self.assertEqual( num2words(test[0], lang='fr', to='currency'), test[1] ) def test_currency_old(self): for test in TEST_CASES_TO_CURRENCY_OLD: self.assertEqual( num2words(test[0], lang='fr', to='currency', old=True), test[1] ) num2words-0.5.6/tests/test_fr_ch.py000066400000000000000000000103151320535062200173140ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from unittest import TestCase from num2words import num2words TEST_CASES_CARDINAL = ( (70, 'septante'), (79, 'septante-neuf'), (89, 'huitante-neuf'), (95, 'nonante-cinq'), (729, 'sept cents vingt-neuf'), (894, 'huit cents nonante-quatre'), (999, 'neuf cents nonante-neuf'), (7232, 'sept mille deux cents trente-deux'), (8569, 'huit mille cinq cents soixante-neuf'), (9539, 'neuf mille cinq cents trente-neuf'), (1000000, 'un millions'), (1000001, 'un millions un'), (4000000, 'quatre millions'), (10000000000000, 'dix billions'), (100000000000000, 'cent billions'), (1000000000000000000, 'un trillions'), (1000000000000000000000, 'un trilliards'), (10000000000000000000000000, 'dix quadrillions') ) TEST_CASES_ORDINAL = ( (1, 'premier'), (8, 'huitième'), (12, 'douzième'), (14, 'quatorzième'), (28, 'vingt-huitième'), (100, 'centième'), (1000, 'millième'), (1000000, 'un millionsième'), (1000000000000000, 'un billiardsième'), (1000000000000000000, 'un trillionsième') # over 1e18 is not supported ) TEST_CASES_TO_CURRENCY = ( (1, 'un euro'), (2, 'deux euros'), (8, 'huit euros'), (12, 'douze euros'), (21, 'vingt et un euros'), (81.25, 'huitante et un euros et vingt-cinq centimes'), (100, 'cent euros'), ) TEST_CASES_TO_CURRENCY_OLD = ( (1, 'un franc'), (2, 'deux francs'), (8, 'huit francs'), (12, 'douze francs'), (21, 'vingt et un francs'), (81.25, 'huitante et un francs et vingt-cinq centimes'), (100, 'cent francs'), ) class Num2WordsENTest(TestCase): def test_ordinal_special_joins(self): self.assertEqual( num2words(5, ordinal=True, lang='fr_CH'), "cinquième" ) self.assertEqual( num2words(6, ordinal=True, lang='fr_CH'), "sixième" ) self.assertEqual( num2words(35, ordinal=True, lang='fr_CH'), "trente-cinquième" ) self.assertEqual(num2words(9, ordinal=True, lang='fr_CH'), "neuvième") self.assertEqual( num2words(49, ordinal=True, lang='fr_CH'), "quarante-neuvième" ) self.assertEqual(num2words(71, lang='fr_CH'), "septante et un") self.assertEqual(num2words(81, lang='fr_CH'), "huitante et un") self.assertEqual(num2words(80, lang='fr_CH'), "huitante") self.assertEqual(num2words(880, lang='fr_CH'), "huit cents huitante") self.assertEqual( num2words(91, ordinal=True, lang='fr_CH'), "nonante et unième" ) self.assertEqual(num2words(53, lang='fr_CH'), "cinquante-trois") def test_number(self): for test in TEST_CASES_CARDINAL: self.assertEqual(num2words(test[0], lang='fr_CH'), test[1]) def test_ordinal(self): for test in TEST_CASES_ORDINAL: self.assertEqual( num2words(test[0], lang='fr_CH', ordinal=True), test[1] ) def test_currency(self): for test in TEST_CASES_TO_CURRENCY: self.assertEqual( num2words(test[0], lang='fr_CH', to='currency'), test[1] ) def test_currency_old(self): for test in TEST_CASES_TO_CURRENCY_OLD: self.assertEqual( num2words(test[0], lang='fr_CH', to='currency', old=True), test[1] ) num2words-0.5.6/tests/test_fr_dz.py000066400000000000000000000042731320535062200173450ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from unittest import TestCase from num2words import num2words from . import test_fr TEST_CASES_TO_CURRENCY = ( (1, 'un dinard'), (2, 'deux dinards'), (8, 'huit dinards'), (12, 'douze dinards'), (21, 'vingt et un dinards'), (81.25, 'quatre-vingt-un dinards virgule vingt-cinq centimes'), (100, 'cent dinards'), ) class Num2WordsPLTest(TestCase): def test_currency(self): self.assertEqual( num2words(1234.12, lang='fr_DZ', to='currency'), "mille deux cent trente-quatre dinards virgule douze centimes" ) self.assertEqual( num2words(45689.89, lang='fr_DZ', to='currency'), "quarante-cinq mille six cent quatre-vingt-neuf dinards virgule " "quatre-vingt-neuf centimes" ) def test_number(self): for test in test_fr.TEST_CASES_CARDINAL: self.assertEqual(num2words(test[0], lang='fr_DZ'), test[1]) def test_ordinal(self): for test in test_fr.TEST_CASES_ORDINAL: self.assertEqual( num2words(test[0], lang='fr_DZ', ordinal=True), test[1] ) def test_ordinal_num(self): for test in test_fr.TEST_CASES_ORDINAL_NUM: self.assertEqual( num2words(test[0], lang='fr_DZ', to='ordinal_num'), test[1] ) num2words-0.5.6/tests/test_id.py000066400000000000000000000046721320535062200166400ustar00rootroot00000000000000# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from unittest import TestCase from num2words import num2words class Num2WordsIDTest(TestCase): def test_cardinal_for_natural_number(self): self.assertEqual(num2words(10, lang='id'), "sepuluh") self.assertEqual(num2words(11, lang='id'), "sebelas") self.assertEqual(num2words(108, lang='id'), "seratus delapan") self.assertEqual(num2words(1075, lang='id'), "seribu tujuh puluh lima") self.assertEqual( num2words(1087231, lang='id'), "satu juta delapan puluh tujuh ribu dua ratus tiga puluh satu" ) self.assertEqual( num2words(1000000408, lang='id'), "satu miliar empat ratus delapan" ) def test_cardinal_for_decimal_number(self): self.assertEqual( num2words(12.234, lang='id'), "dua belas koma dua tiga empat" ) self.assertEqual( num2words(9.076, lang='id'), "sembilan koma nol tujuh enam" ) def test_cardinal_for_negative_number(self): self.assertEqual( num2words(-923, lang='id'), "min sembilan ratus dua puluh tiga" ) self.assertEqual( num2words(-0.234, lang='id'), "min nol koma dua tiga empat" ) def test_ordinal_for_natural_number(self): self.assertEqual(num2words(1, ordinal=True, lang='id'), "pertama") self.assertEqual(num2words(10, ordinal=True, lang='id'), "kesepuluh") def test_ordinal_for_negative_number(self): self.assertRaises(TypeError, num2words, -12, ordinal=True, lang='id') def test_ordinal_for_floating_number(self): self.assertRaises(TypeError, num2words, 3.243, ordinal=True, lang='id') num2words-0.5.6/tests/test_it.py000066400000000000000000000223311320535062200166500ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from unittest import TestCase from num2words import num2words class Num2WordsITTest(TestCase): maxDiff = None def test_negative(self): number = 648972145 pos_crd = num2words(+number, lang="it") neg_crd = num2words(-number, lang="it") pos_ord = num2words(+number, lang="it", ordinal=True) neg_ord = num2words(-number, lang="it", ordinal=True) self.assertEqual("meno " + pos_crd, neg_crd) self.assertEqual("meno " + pos_ord, neg_ord) def test_float_to_cardinal(self): self.assertEqual( num2words(3.1415, lang="it"), "tre virgola uno quattro uno cinque" ) self.assertEqual( num2words(-5.15, lang="it"), "meno cinque virgola uno cinque" ) self.assertEqual( num2words(-0.15, lang="it"), "meno zero virgola uno cinque" ) def test_float_to_ordinal(self): self.assertEqual( num2words(3.1415, lang="it", ordinal=True), "terzo virgola uno quattro uno cinque" ) self.assertEqual( num2words(-5.15, lang="it", ordinal=True), "meno quinto virgola uno cinque" ) self.assertEqual( num2words(-0.15, lang="it", ordinal=True), "meno zero virgola uno cinque" ) def test_0(self): self.assertEqual(num2words(0, lang="it"), "zero") self.assertEqual(num2words(0, lang="it", ordinal=True), "zero") def test_1_to_10(self): self.assertEqual(num2words(1, lang="it"), "uno") self.assertEqual(num2words(2, lang="it"), "due") self.assertEqual(num2words(7, lang="it"), "sette") self.assertEqual(num2words(10, lang="it"), "dieci") def test_11_to_19(self): self.assertEqual(num2words(11, lang="it"), "undici") self.assertEqual(num2words(13, lang="it"), "tredici") self.assertEqual(num2words(15, lang="it"), "quindici") self.assertEqual(num2words(16, lang="it"), "sedici") self.assertEqual(num2words(19, lang="it"), "diciannove") def test_20_to_99(self): self.assertEqual(num2words(20, lang="it"), "venti") self.assertEqual(num2words(23, lang="it"), "ventitré") self.assertEqual(num2words(28, lang="it"), "ventotto") self.assertEqual(num2words(31, lang="it"), "trentuno") self.assertEqual(num2words(40, lang="it"), "quaranta") self.assertEqual(num2words(66, lang="it"), "sessantasei") self.assertEqual(num2words(92, lang="it"), "novantadue") def test_100_to_999(self): self.assertEqual(num2words(100, lang="it"), "cento") self.assertEqual(num2words(111, lang="it"), "centoundici") self.assertEqual(num2words(150, lang="it"), "centocinquanta") self.assertEqual(num2words(196, lang="it"), "centonovantasei") self.assertEqual(num2words(200, lang="it"), "duecento") self.assertEqual(num2words(210, lang="it"), "duecentodieci") self.assertEqual(num2words(701, lang="it"), "settecentouno") def test_1000_to_9999(self): self.assertEqual(num2words(1000, lang="it"), "mille") self.assertEqual(num2words(1001, lang="it"), "milleuno") self.assertEqual(num2words(1500, lang="it"), "millecinquecento") self.assertEqual( num2words(7378, lang="it"), "settemilatrecentosettantotto" ) self.assertEqual(num2words(2000, lang="it"), "duemila") self.assertEqual(num2words(2100, lang="it"), "duemilacento") self.assertEqual( num2words(6870, lang="it"), "seimilaottocentosettanta" ) self.assertEqual(num2words(10000, lang="it"), "diecimila") self.assertEqual( num2words(98765, lang="it"), "novantottomilasettecentosessantacinque" ) self.assertEqual(num2words(100000, lang="it"), "centomila") self.assertEqual( num2words(523456, lang="it"), "cinquecentoventitremilaquattrocentocinquantasei" ) def test_big(self): self.assertEqual(num2words(1000000, lang="it"), "un milione") self.assertEqual(num2words(1000007, lang="it"), "un milione e sette") self.assertEqual( num2words(1200000, lang="it"), "un milione e duecentomila" ) self.assertEqual(num2words(3000000, lang="it"), "tre milioni") self.assertEqual(num2words(3000005, lang="it"), "tre milioni e cinque") self.assertEqual( num2words(3800000, lang="it"), "tre milioni e ottocentomila" ) self.assertEqual(num2words(1000000000, lang="it"), "un miliardo") self.assertEqual( num2words(1000000017, lang="it"), "un miliardo e diciassette" ) self.assertEqual(num2words(2000000000, lang="it"), "due miliardi") self.assertEqual( num2words(2000001000, lang="it"), "due miliardi e mille" ) self.assertEqual( num2words(1234567890, lang="it"), "un miliardo, duecentotrentaquattro milioni e " "cinquecentosessantasettemilaottocentonovanta" ) self.assertEqual(num2words(1000000000000, lang="it"), "un bilione") self.assertEqual( num2words(123456789012345678901234567890, lang="it"), "centoventitré quadriliardi, quattrocentocinquantasei " "quadrilioni, settecentottantanove triliardi, dodici trilioni, " "trecentoquarantacinque biliardi, seicentosettantotto bilioni, " "novecentouno miliardi, duecentotrentaquattro milioni e " "cinquecentosessantasettemilaottocentonovanta" ) def test_nth_1_to_99(self): self.assertEqual(num2words(1, lang="it", ordinal=True), "primo") self.assertEqual(num2words(8, lang="it", ordinal=True), "ottavo") self.assertEqual( num2words(23, lang="it", ordinal=True), "ventitreesimo" ) self.assertEqual( num2words(47, lang="it", ordinal=True), "quarantasettesimo" ) self.assertEqual( num2words(99, lang="it", ordinal=True), "novantanovesimo" ) def test_nth_100_to_999(self): self.assertEqual(num2words(100, lang="it", ordinal=True), "centesimo") self.assertEqual( num2words(112, lang="it", ordinal=True), "centododicesimo" ) self.assertEqual( num2words(120, lang="it", ordinal=True), "centoventesimo" ) self.assertEqual( num2words(316, lang="it", ordinal=True), "trecentosedicesimo" ) self.assertEqual( num2words(700, lang="it", ordinal=True), "settecentesimo" ) self.assertEqual( num2words(803, lang="it", ordinal=True), "ottocentotreesimo" ) self.assertEqual( num2words(923, lang="it", ordinal=True), "novecentoventitreesimo" ) def test_nth_1000_to_999999(self): self.assertEqual(num2words(1000, lang="it", ordinal=True), "millesimo") self.assertEqual( num2words(1001, lang="it", ordinal=True), "milleunesimo" ) self.assertEqual( num2words(1003, lang="it", ordinal=True), "milletreesimo" ) self.assertEqual( num2words(1200, lang="it", ordinal=True), "milleduecentesimo" ) self.assertEqual( num2words(8640, lang="it", ordinal=True), "ottomilaseicentoquarantesimo" ) self.assertEqual( num2words(14000, lang="it", ordinal=True), "quattordicimillesimo" ) self.assertEqual( num2words(123456, lang="it", ordinal=True), "centoventitremilaquattrocentocinquantaseiesimo" ) self.assertEqual( num2words(987654, lang="it", ordinal=True), "novecentottantasettemilaseicentocinquantaquattresimo" ) def test_nth_big(self): self.assertEqual( num2words(1000000001, lang="it", ordinal=True), "un miliardo e unesimo" ) self.assertEqual( num2words(123456789012345678901234567890, lang="it", ordinal=True), "centoventitré quadriliardi, quattrocentocinquantasei " "quadrilioni, settecentottantanove triliardi, dodici trilioni, " "trecentoquarantacinque biliardi, seicentosettantotto bilioni, " "novecentouno miliardi, duecentotrentaquattro milioni e " "cinquecentosessantasettemilaottocentonovantesimo" ) num2words-0.5.6/tests/test_lt.py000066400000000000000000000073111320535062200166540ustar00rootroot00000000000000# -*- encoding: utf-8 -*- from __future__ import unicode_literals from unittest import TestCase from num2words import num2words class Num2WordsLTTest(TestCase): def test_to_cardinal(self): self.assertEqual(num2words(100, lang='lt'), 'vienas šimtas') self.assertEqual(num2words(101, lang='lt'), 'vienas šimtas vienas') self.assertEqual(num2words(110, lang='lt'), 'vienas šimtas dešimt') self.assertEqual(num2words(115, lang='lt'), 'vienas šimtas penkiolika') self.assertEqual(num2words(123, lang='lt'), 'vienas šimtas dvidešimt trys') self.assertEqual(num2words(1000, lang='lt'), 'vienas tūkstantis') self.assertEqual(num2words(1001, lang='lt'), 'vienas tūkstantis vienas') self.assertEqual(num2words(2012, lang='lt'), 'du tūkstančiai dvylika') self.assertEqual( num2words(1234567890, lang='lt'), "vienas milijardas du šimtai trisdešimt keturi milijonai " "penki šimtai šešiasdešimt septyni tūkstančiai aštuoni šimtai " "devyniasdešimt") self.assertEqual( num2words(215461407892039002157189883901676, lang='lt'), "du šimtai penkiolika naintilijonų keturi šimtai šešiasdešimt " "vienas oktilijonas keturi šimtai septyni septilijonai aštuoni " "šimtai devyniasdešimt du sikstilijonai trisdešimt devyni " "kvintilijonai du kvadrilijonai vienas šimtas penkiasdešimt " "septyni trilijonai vienas šimtas aštuoniasdešimt devyni " "milijardai aštuoni šimtai aštuoniasdešimt trys milijonai " "devyni šimtai vienas tūkstantis šeši šimtai " "septyniasdešimt šeši") self.assertEqual( num2words(719094234693663034822824384220291, lang='lt'), "septyni šimtai devyniolika naintilijonų devyniasdešimt keturi " "oktilijonai du šimtai trisdešimt keturi septilijonai šeši " "šimtai devyniasdešimt trys sikstilijonai šeši šimtai " "šešiasdešimt trys kvintilijonai trisdešimt keturi kvadrilijonai " "aštuoni šimtai dvidešimt du trilijonai aštuoni šimtai dvidešimt " "keturi milijardai trys šimtai aštuoniasdešimt keturi milijonai " "du šimtai dvidešimt tūkstančių du šimtai devyniasdešimt vienas") # print(fill(n2w(1000000000000000000000000000000))) # naintilijonas def test_to_ordinal(self): # @TODO: implement to_ordinal with self.assertRaises(NotImplementedError): num2words(1, lang='lt', to='ordinal') def test_to_currency(self): self.assertEqual( num2words(1.0, lang='lt', to='currency', currency='LTL'), 'vienas litas, nulis centų' ) self.assertEqual( num2words(1234.56, lang='lt', to='currency', currency='LTL'), 'vienas tūkstantis du šimtai trisdešimt keturi litai, ' 'penkiasdešimt šeši centai' ) self.assertEqual( num2words(-1251985, lang='lt', to='currency', currency='EUR', cents=False), 'minus dvylika tūkstančių penki šimtai devyniolika eurų, ' '85 centai' ) self.assertEqual( num2words(1.0, lang='lt', to='currency', currency='EUR'), 'vienas euras, nulis centų' ) self.assertEqual( num2words(1234.56, lang='lt', to='currency', currency='EUR'), 'vienas tūkstantis du šimtai trisdešimt keturi eurai, ' 'penkiasdešimt šeši centai' ) num2words-0.5.6/tests/test_lv.py000066400000000000000000000131501320535062200166540ustar00rootroot00000000000000# -*- encoding: utf-8 -*- from __future__ import unicode_literals from unittest import TestCase from num2words import num2words class Num2WordsLVTest(TestCase): def test_to_cardinal(self): self.assertEqual(num2words(100, lang='lv'), 'simts') self.assertEqual(num2words(101, lang='lv'), 'simtu viens') self.assertEqual(num2words(110, lang='lv'), 'simts desmit') self.assertEqual(num2words(115, lang='lv'), 'simts piecpadsmit') self.assertEqual(num2words(123, lang='lv'), 'simts divdesmit trīs') self.assertEqual(num2words(1000, lang='lv'), 'tūkstotis') self.assertEqual(num2words(1001, lang='lv'), 'tūkstotis viens') self.assertEqual(num2words(2012, lang='lv'), 'divi tūkstoši divpadsmit') self.assertEqual( num2words(1234567890, lang='lv'), 'miljards divi simti trīsdesmit četri miljoni pieci simti ' 'sešdesmit septiņi tūkstoši astoņi simti deviņdesmit') self.assertEqual( num2words(215461407892039002157189883901676, lang='lv'), 'divi simti piecpadsmit nontiljoni četri simti sešdesmit ' 'viens oktiljons četri simti septiņi septiljoni astoņi ' 'simti deviņdesmit divi sikstiljoni trīsdesmit deviņi ' 'kvintiljoni divi kvadriljoni simts piecdesmit septiņi ' 'triljoni simts astoņdesmit deviņi miljardi astoņi simti ' 'astoņdesmit trīs miljoni deviņi simti viens tūkstotis ' 'seši simti septiņdesmit seši') self.assertEqual( num2words(719094234693663034822824384220291, lang='lv'), 'septiņi simti deviņpadsmit nontiljoni deviņdesmit četri ' 'oktiljoni divi simti trīsdesmit četri septiljoni seši simti ' 'deviņdesmit trīs sikstiljoni seši simti sešdesmit trīs ' 'kvintiljoni trīsdesmit četri kvadriljoni astoņi simti ' 'divdesmit divi triljoni astoņi simti divdesmit četri ' 'miljardi trīs simti astoņdesmit četri miljoni divi simti ' 'divdesmit tūkstoši divi simti deviņdesmit viens') # >>> print(fill(n2w(1000000000000000000000000000000))) # nontiljons self.assertEqual(num2words(0, lang='lv'), 'nulle') self.assertEqual(num2words(5, lang='lv'), "pieci") self.assertEqual(num2words(15, lang='lv'), "piecpadsmit") self.assertEqual(num2words(154, lang='lv'), "simts piecdesmit četri") self.assertEqual(num2words(101, lang='lv'), "simtu viens") self.assertEqual( num2words(1135, lang='lv'), "tūkstotis simts trīsdesmit pieci" ) self.assertEqual( num2words(418531, lang='lv'), "četri simti astoņpadsmit tūkstoši pieci simti trīsdesmit viens" ) self.assertEqual( num2words(1000139, lang='lv'), "miljons simts trīsdesmit deviņi" ) def test_to_ordinal(self): # @TODO: implement to_ordinal with self.assertRaises(NotImplementedError): num2words(1, lang='lv', to='ordinal') def test_to_currency(self): self.assertEqual( num2words(1.0, lang='lv', to='currency', currency='EUR'), "viens eiro, nulle centu" ) self.assertEqual( num2words(1.0, lang='lv', to='currency', currency='LVL'), "viens lats, nulle santīmu" ) self.assertEqual( num2words(1234.56, lang='lv', to='currency', currency='EUR'), "tūkstotis divi simti trīsdesmit četri eiro, piecdesmit seši centi" ) self.assertEqual( num2words(1234.56, lang='lv', to='currency', currency='LVL'), "tūkstotis divi simti trīsdesmit četri lati, " "piecdesmit seši santīmi" ) self.assertEqual( num2words(10111, lang='lv', to='currency', seperator=' un', currency='EUR'), "simtu viens eiro un vienpadsmit centi" ) self.assertEqual( num2words(10121, lang='lv', to='currency', seperator=' un', currency='LVL'), "simtu viens lats un divdesmit viens santīms" ) self.assertEqual( num2words(-1251985, lang='lv', to='currency', cents=False, currency='EUR'), "mīnus divpadsmit tūkstoši pieci simti deviņpadsmit eiro," " 85 centi" ) self.assertEqual( num2words('38.4', lang='lv', to='currency', seperator=' un', cents=False, currency='EUR'), "trīsdesmit astoņi eiro un 40 centi" ) # EUR legal form self.assertEqual( num2words('38.4', lang='lv', to='currency', seperator=' un', cents=False, currency='EUR_LEGAL'), "trīsdesmit astoņi euro un 40 centi" ) self.assertEqual( num2words('38.4', lang='lv', to='currency', seperator=' un', cents=False, currency='USD', adjective=False), "trīsdesmit astoņi dolāri un 40 centi" ) self.assertEqual( num2words('38.4', lang='lv', to='currency', seperator=' un', cents=False, currency='USD', adjective=True), "trīsdesmit astoņi ASV dolāri un 40 centi" ) def test_fractions(self): self.assertEqual(num2words(5.2, lang='lv'), "pieci komats divi") self.assertEqual( num2words(561.42, lang='lv'), "pieci simti sešdesmit viens komats četrdesmit divi" ) num2words-0.5.6/tests/test_nl.py000066400000000000000000000053231320535062200166470ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from unittest import TestCase from num2words import num2words class Num2WordsNLTest(TestCase): def test_ordinal_less_than_twenty(self): self.assertEqual(num2words(7, ordinal=True, lang='nl'), "zevende") self.assertEqual(num2words(8, ordinal=True, lang='nl'), "achtste") self.assertEqual(num2words(12, ordinal=True, lang='nl'), "twaalfde") self.assertEqual(num2words(17, ordinal=True, lang='nl'), "zeventiende") def test_ordinal_more_than_twenty(self): self.assertEqual( num2words(81, ordinal=True, lang='nl'), "eenentachtigste" ) def test_ordinal_at_crucial_number(self): self.assertEqual(num2words(100, ordinal=True, lang='nl'), "honderdste") self.assertEqual( num2words(1000, ordinal=True, lang='nl'), "duizendste" ) self.assertEqual( num2words(4000, ordinal=True, lang='nl'), "vierduizendste" ) self.assertEqual( num2words(2000000, ordinal=True, lang='nl'), "twee miljoenste" ) self.assertEqual( num2words(5000000000, ordinal=True, lang='nl'), "vijf miljardste" ) def test_cardinal_at_some_numbers(self): self.assertEqual(num2words(82, lang='nl'), u'twee\xebntachtig') self.assertEqual(num2words(1013, lang='nl'), "duizenddertien") self.assertEqual(num2words(2000000, lang='nl'), "twee miljoen") self.assertEqual(num2words(4000000000, lang='nl'), "vier miljard") def test_cardinal_for_decimal_number(self): self.assertEqual( num2words(3.486, lang='nl'), "drie komma vier acht zes" ) def test_ordinal_for_negative_numbers(self): self.assertRaises(TypeError, num2words, -12, ordinal=True, lang='nl') def test_ordinal_for_floating_numbers(self): self.assertRaises(TypeError, num2words, 2.453, ordinal=True, lang='nl') num2words-0.5.6/tests/test_pl.py000066400000000000000000000120531320535062200166470ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from unittest import TestCase from num2words import num2words class Num2WordsPLTest(TestCase): def test_cardinal(self): self.assertEqual(num2words(100, lang='pl'), "sto") self.assertEqual(num2words(101, lang='pl'), "sto jeden") self.assertEqual(num2words(110, lang='pl'), "sto dziesięć") self.assertEqual(num2words(115, lang='pl'), "sto piętnaście") self.assertEqual(num2words(123, lang='pl'), "sto dwadzieścia trzy") self.assertEqual(num2words(1000, lang='pl'), "tysiąc") self.assertEqual(num2words(1001, lang='pl'), "tysiąc jeden") self.assertEqual(num2words(2012, lang='pl'), "dwa tysiące dwanaście") self.assertEqual( num2words(12519.85, lang='pl'), "dwanaście tysięcy pięćset dziewiętnaście przecinek " "osiemdziesiąt pięć" ) self.assertEqual( num2words(123.50, lang='pl'), "sto dwadzieścia trzy przecinek pięć" ) self.assertEqual( num2words(1234567890, lang='pl'), "miliard dwieście trzydzieści cztery miliony pięćset " "sześćdziesiąt siedem tysięcy osiemset dziewięćdzisiąt" ) self.assertEqual( num2words(215461407892039002157189883901676, lang='pl'), "dwieście piętnaście kwintylionów czterysta sześćdziesiąt jeden " "kwadryliardów czterysta siedem kwadrylionów osiemset " "dziewięćdzisiąt dwa tryliardy trzydzieści dziewięć trylionów " "dwa biliardy sto pięćdziesiąt siedem bilionów sto osiemdziesiąt " "dziewięć miliardów osiemset osiemdziesiąt trzy miliony " "dziewęćset jeden tysięcy sześćset siedemdziesiąt sześć" ) self.assertEqual( num2words(719094234693663034822824384220291, lang='pl'), "siedemset dziewiętnaście kwintylionów dziewięćdzisiąt cztery " "kwadryliardy dwieście trzydzieści cztery kwadryliony sześćset " "dziewięćdzisiąt trzy tryliardy sześćset sześćdziesiąt trzy " "tryliony trzydzieści cztery biliardy osiemset dwadzieścia dwa " "biliony osiemset dwadzieścia cztery miliardy trzysta " "osiemdziesiąt cztery miliony dwieście dwadzieścia " "tysięcy dwieście dziewięćdzisiąt jeden" ) def test_to_ordinal(self): # @TODO: implement to_ordinal with self.assertRaises(NotImplementedError): num2words(1, lang='pl', to='ordinal') def test_currency(self): self.assertEqual( num2words(1.0, lang='pl', to='currency', currency='EUR'), "jeden euro, zero centów") self.assertEqual( num2words(1.0, lang='pl', to='currency', currency='PLN'), "jeden złoty, zero groszy") self.assertEqual( num2words(1234.56, lang='pl', to='currency', currency='EUR'), "tysiąc dwieście trzydzieści cztery euro, pięćdziesiąt sześć " "centów" ) self.assertEqual( num2words(1234.56, lang='pl', to='currency', currency='PLN'), "tysiąc dwieście trzydzieści cztery złote, pięćdziesiąt sześć " "groszy" ) self.assertEqual( num2words(10111, lang='pl', to='currency', currency='EUR', seperator=' i'), "sto jeden euro i jedenaście centów" ) self.assertEqual( num2words(10121, lang='pl', to='currency', currency='PLN', seperator=' i'), "sto jeden złotych i dwadzieścia jeden groszy" ) self.assertEqual( num2words(-1251985, lang='pl', to='currency', cents=False), "minus dwanaście tysięcy pięćset dziewiętnaście euro, 85 centów" ) self.assertEqual( num2words(123.50, lang='pl', to='currency', currency='PLN', seperator=' i'), "sto dwadzieścia trzy złote i pięćdziesiąt groszy" ) self.assertEqual( num2words(1950, lang='pl', to='currency', cents=False), "dziewiętnaście euro, 50 centów" ) num2words-0.5.6/tests/test_pt_BR.py000066400000000000000000000400651320535062200172460ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from decimal import Decimal from unittest import TestCase from num2words import num2words from num2words.lang_PT_BR import Num2Word_PT_BR class Num2WordsPTBRTest(TestCase): def setUp(self): super(Num2WordsPTBRTest, self).setUp() self.n2w = Num2Word_PT_BR() def test_cardinal_integer(self): self.assertEqual(num2words(1, lang='pt_BR'), 'um') self.assertEqual(num2words(2, lang='pt_BR'), 'dois') self.assertEqual(num2words(3, lang='pt_BR'), 'três') self.assertEqual(num2words(4, lang='pt_BR'), 'quatro') self.assertEqual(num2words(5, lang='pt_BR'), 'cinco') self.assertEqual(num2words(6, lang='pt_BR'), 'seis') self.assertEqual(num2words(7, lang='pt_BR'), 'sete') self.assertEqual(num2words(8, lang='pt_BR'), 'oito') self.assertEqual(num2words(9, lang='pt_BR'), 'nove') self.assertEqual(num2words(10, lang='pt_BR'), 'dez') self.assertEqual(num2words(11, lang='pt_BR'), 'onze') self.assertEqual(num2words(12, lang='pt_BR'), 'doze') self.assertEqual(num2words(13, lang='pt_BR'), 'treze') self.assertEqual(num2words(14, lang='pt_BR'), 'catorze') self.assertEqual(num2words(15, lang='pt_BR'), 'quinze') self.assertEqual(num2words(16, lang='pt_BR'), 'dezesseis') self.assertEqual(num2words(17, lang='pt_BR'), 'dezessete') self.assertEqual(num2words(18, lang='pt_BR'), 'dezoito') self.assertEqual(num2words(19, lang='pt_BR'), 'dezenove') self.assertEqual(num2words(20, lang='pt_BR'), 'vinte') self.assertEqual(num2words(21, lang='pt_BR'), 'vinte e um') self.assertEqual(num2words(22, lang='pt_BR'), 'vinte e dois') self.assertEqual(num2words(35, lang='pt_BR'), 'trinta e cinco') self.assertEqual(num2words(99, lang='pt_BR'), 'noventa e nove') self.assertEqual(num2words(100, lang='pt_BR'), 'cem') self.assertEqual(num2words(101, lang='pt_BR'), 'cento e um') self.assertEqual(num2words(128, lang='pt_BR'), 'cento e vinte e oito') self.assertEqual(num2words(713, lang='pt_BR'), 'setecentos e treze') self.assertEqual(num2words(1000, lang='pt_BR'), 'mil') self.assertEqual(num2words(1001, lang='pt_BR'), 'mil e um') self.assertEqual(num2words(1111, lang='pt_BR'), 'mil, cento e onze') self.assertEqual( num2words(2114, lang='pt_BR'), 'dois mil, cento e catorze' ) self.assertEqual( num2words(73421, lang='pt_BR'), 'setenta e três mil, quatrocentos e vinte e um' ) self.assertEqual(num2words(100000, lang='pt_BR'), 'cem mil') self.assertEqual( num2words(250050, lang='pt_BR'), 'duzentos e cinquenta mil e cinquenta' ) self.assertEqual( num2words(6000000, lang='pt_BR'), 'seis milhões' ) self.assertEqual( num2words(19000000000, lang='pt_BR'), 'dezenove bilhões' ) self.assertEqual( num2words(145000000002, lang='pt_BR'), 'cento e quarenta e cinco bilhões e dois' ) def test_cardinal_integer_negative(self): self.assertEqual(num2words(-1, lang='pt_BR'), 'menos um') self.assertEqual( num2words(-256, lang='pt_BR'), 'menos duzentos e cinquenta e seis' ) self.assertEqual(num2words(-1000, lang='pt_BR'), 'menos mil') self.assertEqual(num2words(-1000000, lang='pt_BR'), 'menos um milhão') self.assertEqual( num2words(-1234567, lang='pt_BR'), 'menos um milhão, duzentos e trinta e quatro mil, quinhentos e ' 'sessenta e sete' ) def test_cardinal_float(self): self.assertEqual(num2words(Decimal('1.00'), lang='pt_BR'), 'um') self.assertEqual(num2words( Decimal('1.01'), lang='pt_BR'), 'um vírgula zero um') self.assertEqual(num2words( Decimal('1.035'), lang='pt_BR'), 'um vírgula zero três cinco' ) self.assertEqual(num2words( Decimal('1.35'), lang='pt_BR'), 'um vírgula três cinco' ) self.assertEqual( num2words(Decimal('3.14159'), lang='pt_BR'), 'três vírgula um quatro um cinco nove' ) self.assertEqual( num2words(Decimal('101.22'), lang='pt_BR'), 'cento e um vírgula dois dois' ) self.assertEqual( num2words(Decimal('2345.75'), lang='pt_BR'), 'dois mil, trezentos e quarenta e cinco vírgula sete cinco') def test_cardinal_float_negative(self): self.assertEqual( num2words(Decimal('-2.34'), lang='pt_BR'), 'menos dois vírgula três quatro' ) self.assertEqual( num2words(Decimal('-9.99'), lang='pt_BR'), 'menos nove vírgula nove nove' ) self.assertEqual( num2words(Decimal('-7.01'), lang='pt_BR'), 'menos sete vírgula zero um' ) self.assertEqual( num2words(Decimal('-222.22'), lang='pt_BR'), 'menos duzentos e vinte e dois vírgula dois dois' ) def test_ordinal(self): self.assertEqual(num2words(1, lang='pt_BR', ordinal=True), 'primeiro') self.assertEqual(num2words(2, lang='pt_BR', ordinal=True), 'segundo') self.assertEqual(num2words(3, lang='pt_BR', ordinal=True), 'terceiro') self.assertEqual(num2words(4, lang='pt_BR', ordinal=True), 'quarto') self.assertEqual(num2words(5, lang='pt_BR', ordinal=True), 'quinto') self.assertEqual(num2words(6, lang='pt_BR', ordinal=True), 'sexto') self.assertEqual(num2words(7, lang='pt_BR', ordinal=True), 'sétimo') self.assertEqual(num2words(8, lang='pt_BR', ordinal=True), 'oitavo') self.assertEqual(num2words(9, lang='pt_BR', ordinal=True), 'nono') self.assertEqual(num2words(10, lang='pt_BR', ordinal=True), 'décimo') self.assertEqual( num2words(11, lang='pt_BR', ordinal=True), 'décimo primeiro' ) self.assertEqual( num2words(12, lang='pt_BR', ordinal=True), 'décimo segundo' ) self.assertEqual( num2words(13, lang='pt_BR', ordinal=True), 'décimo terceiro' ) self.assertEqual( num2words(14, lang='pt_BR', ordinal=True), 'décimo quarto' ) self.assertEqual( num2words(15, lang='pt_BR', ordinal=True), 'décimo quinto' ) self.assertEqual( num2words(16, lang='pt_BR', ordinal=True), 'décimo sexto' ) self.assertEqual( num2words(17, lang='pt_BR', ordinal=True), 'décimo sétimo' ) self.assertEqual( num2words(18, lang='pt_BR', ordinal=True), 'décimo oitavo' ) self.assertEqual( num2words(19, lang='pt_BR', ordinal=True), 'décimo nono' ) self.assertEqual( num2words(20, lang='pt_BR', ordinal=True), 'vigésimo' ) self.assertEqual( num2words(21, lang='pt_BR', ordinal=True), 'vigésimo primeiro' ) self.assertEqual( num2words(22, lang='pt_BR', ordinal=True), 'vigésimo segundo' ) self.assertEqual( num2words(35, lang='pt_BR', ordinal=True), 'trigésimo quinto' ) self.assertEqual( num2words(99, lang='pt_BR', ordinal=True), 'nonagésimo nono' ) self.assertEqual( num2words(100, lang='pt_BR', ordinal=True), 'centésimo' ) self.assertEqual( num2words(101, lang='pt_BR', ordinal=True), 'centésimo primeiro' ) self.assertEqual( num2words(128, lang='pt_BR', ordinal=True), 'centésimo vigésimo oitavo' ) self.assertEqual( num2words(713, lang='pt_BR', ordinal=True), 'septigentésimo décimo terceiro' ) self.assertEqual( num2words(1000, lang='pt_BR', ordinal=True), 'milésimo' ) self.assertEqual( num2words(1001, lang='pt_BR', ordinal=True), 'milésimo primeiro' ) self.assertEqual( num2words(1111, lang='pt_BR', ordinal=True), 'milésimo centésimo décimo primeiro' ) self.assertEqual( num2words(2114, lang='pt_BR', ordinal=True), 'segundo milésimo centésimo décimo quarto' ) self.assertEqual( num2words(73421, lang='pt_BR', ordinal=True), 'septuagésimo terceiro milésimo quadrigentésimo vigésimo primeiro' ) self.assertEqual( num2words(100000, lang='pt_BR', ordinal=True), 'centésimo milésimo' ) self.assertEqual( num2words(250050, lang='pt_BR', ordinal=True), 'ducentésimo quinquagésimo milésimo quinquagésimo' ) self.assertEqual( num2words(6000000, lang='pt_BR', ordinal=True), 'sexto milionésimo' ) self.assertEqual( num2words(19000000000, lang='pt_BR', ordinal=True), 'décimo nono bilionésimo' ) self.assertEqual( num2words(145000000002, lang='pt_BR', ordinal=True), 'centésimo quadragésimo quinto bilionésimo segundo' ) def test_currency_integer(self): self.assertEqual(self.n2w.to_currency(1), 'um real') self.assertEqual(self.n2w.to_currency(2), 'dois reais') self.assertEqual(self.n2w.to_currency(3), 'três reais') self.assertEqual(self.n2w.to_currency(4), 'quatro reais') self.assertEqual(self.n2w.to_currency(5), 'cinco reais') self.assertEqual(self.n2w.to_currency(6), 'seis reais') self.assertEqual(self.n2w.to_currency(7), 'sete reais') self.assertEqual(self.n2w.to_currency(8), 'oito reais') self.assertEqual(self.n2w.to_currency(9), 'nove reais') self.assertEqual(self.n2w.to_currency(10), 'dez reais') self.assertEqual(self.n2w.to_currency(11), 'onze reais') self.assertEqual(self.n2w.to_currency(12), 'doze reais') self.assertEqual(self.n2w.to_currency(13), 'treze reais') self.assertEqual(self.n2w.to_currency(14), 'catorze reais') self.assertEqual(self.n2w.to_currency(15), 'quinze reais') self.assertEqual(self.n2w.to_currency(16), 'dezesseis reais') self.assertEqual(self.n2w.to_currency(17), 'dezessete reais') self.assertEqual(self.n2w.to_currency(18), 'dezoito reais') self.assertEqual(self.n2w.to_currency(19), 'dezenove reais') self.assertEqual(self.n2w.to_currency(20), 'vinte reais') self.assertEqual(self.n2w.to_currency(21), 'vinte e um reais') self.assertEqual(self.n2w.to_currency(22), 'vinte e dois reais') self.assertEqual(self.n2w.to_currency(35), 'trinta e cinco reais') self.assertEqual(self.n2w.to_currency(99), 'noventa e nove reais') self.assertEqual(self.n2w.to_currency(100), 'cem reais') self.assertEqual(self.n2w.to_currency(101), 'cento e um reais') self.assertEqual( self.n2w.to_currency(128), 'cento e vinte e oito reais' ) self.assertEqual(self.n2w.to_currency(713), 'setecentos e treze reais') self.assertEqual(self.n2w.to_currency(1000), 'mil reais') self.assertEqual(self.n2w.to_currency(1001), 'mil e um reais') self.assertEqual(self.n2w.to_currency(1111), 'mil, cento e onze reais') self.assertEqual( self.n2w.to_currency(2114), 'dois mil, cento e catorze reais' ) self.assertEqual( self.n2w.to_currency(73421), 'setenta e três mil, quatrocentos e vinte e um reais' ) self.assertEqual(self.n2w.to_currency(100000), 'cem mil reais') self.assertEqual( self.n2w.to_currency(250050), 'duzentos e cinquenta mil e cinquenta reais' ) self.assertEqual( self.n2w.to_currency(6000000), 'seis milhões de reais' ) self.assertEqual( self.n2w.to_currency(19000000000), 'dezenove bilhões de reais' ) self.assertEqual( self.n2w.to_currency(145000000002), 'cento e quarenta e cinco bilhões e dois reais' ) def test_currency_integer_negative(self): self.assertEqual(self.n2w.to_currency(-1), 'menos um real') self.assertEqual( self.n2w.to_currency(-256), 'menos duzentos e cinquenta e seis reais' ) self.assertEqual(self.n2w.to_currency(-1000), 'menos mil reais') self.assertEqual( self.n2w.to_currency(-1000000), 'menos um milhão de reais' ) self.assertEqual( self.n2w.to_currency(-1234567), 'menos um milhão, duzentos e trinta e quatro mil, quinhentos e ' 'sessenta e sete reais' ) def test_currency_float(self): self.assertEqual(self.n2w.to_currency(Decimal('1.00')), 'um real') self.assertEqual( self.n2w.to_currency(Decimal('1.01')), 'um real e um centavo' ) self.assertEqual( self.n2w.to_currency(Decimal('1.03')), 'um real e três centavos' ) self.assertEqual( self.n2w.to_currency(Decimal('1.35')), 'um real e trinta e cinco centavos' ) self.assertEqual( self.n2w.to_currency(Decimal('3.14')), 'três reais e catorze centavos' ) self.assertEqual( self.n2w.to_currency(Decimal('101.22')), 'cento e um reais e vinte e dois centavos' ) self.assertEqual( self.n2w.to_currency(Decimal('2345.75')), 'dois mil, trezentos e quarenta e cinco reais e setenta e cinco ' 'centavos' ) def test_currency_float_negative(self): self.assertEqual( self.n2w.to_currency(Decimal('-2.34')), 'menos dois reais e trinta e quatro centavos' ) self.assertEqual( self.n2w.to_currency(Decimal('-9.99')), 'menos nove reais e noventa e nove centavos' ) self.assertEqual( self.n2w.to_currency(Decimal('-7.01')), 'menos sete reais e um centavo' ) self.assertEqual( self.n2w.to_currency(Decimal('-222.22')), 'menos duzentos e vinte e dois reais e vinte e dois centavos' ) def test_year(self): self.assertEqual(self.n2w.to_year(1001), 'mil e um') self.assertEqual( self.n2w.to_year(1789), 'mil, setecentos e oitenta e nove' ) self.assertEqual( self.n2w.to_year(1942), 'mil, novecentos e quarenta e dois' ) self.assertEqual( self.n2w.to_year(1984), 'mil, novecentos e oitenta e quatro' ) self.assertEqual(self.n2w.to_year(2000), 'dois mil') self.assertEqual(self.n2w.to_year(2001), 'dois mil e um') self.assertEqual(self.n2w.to_year(2016), 'dois mil e dezesseis') def test_year_negative(self): self.assertEqual(self.n2w.to_year(-30), 'trinta antes de Cristo') self.assertEqual( self.n2w.to_year(-744), 'setecentos e quarenta e quatro antes de Cristo' ) self.assertEqual(self.n2w.to_year(-10000), 'dez mil antes de Cristo') num2words-0.5.6/tests/test_ru.py000066400000000000000000000157711320535062200166740ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from unittest import TestCase from num2words import num2words class Num2WordsRUTest(TestCase): def test_cardinal(self): self.assertEqual(num2words(100, lang='ru'), "сто") self.assertEqual(num2words(101, lang='ru'), "сто один") self.assertEqual(num2words(110, lang='ru'), "сто десять") self.assertEqual(num2words(115, lang='ru'), "сто пятнадцать") self.assertEqual(num2words(123, lang='ru'), "сто двадцать три") self.assertEqual(num2words(1000, lang='ru'), "одна тысяча") self.assertEqual(num2words(1001, lang='ru'), "одна тысяча один") self.assertEqual(num2words(2012, lang='ru'), "две тысячи двенадцать") self.assertEqual( num2words(12519.85, lang='ru'), "двенадцать тысяч пятьсот девятнадцать запятая восемьдесят пять") self.assertEqual( num2words(1234567890, lang='ru'), "один миллиард двести тридцать четыре миллиона пятьсот " "шестьдесят семь тысяч восемьсот девяносто") self.assertEqual( num2words(215461407892039002157189883901676, lang='ru'), "двести пятнадцать нониллионов четыреста шестьдесят один " "октиллион четыреста семь септиллионов восемьсот девяносто " "два секстиллиона тридцать девять квинтиллионов два квадриллиона " "сто пятьдесят семь триллионов сто восемьдесят девять миллиардов " "восемьсот восемьдесят три миллиона девятьсот одна тысяча " "шестьсот семьдесят шесть") self.assertEqual( num2words(719094234693663034822824384220291, lang='ru'), "семьсот девятнадцать нониллионов девяносто четыре октиллиона " "двести тридцать четыре септиллиона шестьсот девяносто три " "секстиллиона шестьсот шестьдесят три квинтиллиона тридцать " "четыре квадриллиона восемьсот двадцать два триллиона восемьсот " "двадцать четыре миллиарда триста восемьдесят четыре миллиона " "двести двадцать тысяч двести девяносто один") self.assertEqual(num2words(5, lang='ru'), "пять") self.assertEqual(num2words(15, lang='ru'), "пятнадцать") self.assertEqual(num2words(154, lang='ru'), "сто пятьдесят четыре") self.assertEqual( num2words(1135, lang='ru'), "одна тысяча сто тридцать пять" ) self.assertEqual( num2words(418531, lang='ru'), "четыреста восемнадцать тысяч пятьсот тридцать один" ) self.assertEqual( num2words(1000139, lang='ru'), "один миллион сто тридцать девять" ) def test_floating_point(self): self.assertEqual(num2words(5.2, lang='ru'), "пять запятая два") self.assertEqual( num2words(561.42, lang='ru'), "пятьсот шестьдесят один запятая сорок два" ) def test_to_ordinal(self): # @TODO: implement to_ordinal with self.assertRaises(NotImplementedError): num2words(1, lang='ru', to='ordinal') def test_to_currency(self): self.assertEqual( num2words(1.0, lang='ru', to='currency', currency='EUR'), 'один евро, ноль центов' ) self.assertEqual( num2words(1.0, lang='ru', to='currency', currency='RUB'), 'один рубль, ноль копеек' ) self.assertEqual( num2words(1234.56, lang='ru', to='currency', currency='EUR'), 'одна тысяча двести тридцать четыре евро, пятьдесят шесть центов' ) self.assertEqual( num2words(1234.56, lang='ru', to='currency', currency='RUB'), 'одна тысяча двести тридцать четыре рубля, пятьдесят шесть копеек' ) self.assertEqual( num2words(10111, lang='ru', to='currency', currency='EUR', seperator=' и'), 'сто один евро и одиннадцать центов' ) self.assertEqual( num2words(10121, lang='ru', to='currency', currency='RUB', seperator=' и'), 'сто один рубль и двадцать одна копейка' ) self.assertEqual( num2words(10122, lang='ru', to='currency', currency='RUB', seperator=' и'), 'сто один рубль и двадцать две копейки' ) self.assertEqual( num2words(10121, lang='ru', to='currency', currency='EUR', seperator=' и'), 'сто один евро и двадцать один цент' ) self.assertEqual( num2words(-1251985, lang='ru', to='currency', currency='EUR', cents=False), 'минус двенадцать тысяч пятьсот девятнадцать евро, 85 центов' ) self.assertEqual( num2words('38.4', lang='ru', to='currency', seperator=' и', cents=False, currency='EUR'), "тридцать восемь евро и 40 центов" ) num2words-0.5.6/tests/test_sl.py000066400000000000000000000054251320535062200166570ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from unittest import TestCase from num2words import num2words class Num2WordsDETest(TestCase): def test_ordinal_less_than_twenty(self): self.assertEqual(num2words(2, ordinal=True, lang='sl'), "drugi") self.assertEqual(num2words(4, ordinal=True, lang='sl'), "četrti") self.assertEqual(num2words(7, ordinal=True, lang='sl'), "sedmi") self.assertEqual(num2words(8, ordinal=True, lang='sl'), "osmi") self.assertEqual(num2words(12, ordinal=True, lang='sl'), "dvanajsti") self.assertEqual(num2words(17, ordinal=True, lang='sl'), "sedemnajsti") def test_ordinal_more_than_twenty(self): self.assertEqual( num2words(81, ordinal=True, lang='sl'), "enainosemdeseti" ) def test_ordinal_at_crucial_number(self): self.assertEqual(num2words(100, ordinal=True, lang='sl'), "stoti") self.assertEqual(num2words(1000, ordinal=True, lang='sl'), "tisoči") self.assertEqual( num2words(4000, ordinal=True, lang='sl'), "štiritisoči" ) self.assertEqual( num2words(2000000, ordinal=True, lang='sl'), "dvemiljonti" ) self.assertEqual( num2words(5000000000, ordinal=True, lang='sl'), "petmiljardti" ) def test_cardinal_at_some_numbers(self): self.assertEqual(num2words(2, lang='sl'), "dve") self.assertEqual(num2words(4000, lang='sl'), "štiri tisoč") self.assertEqual(num2words(2000000, lang='sl'), "dva miljona") self.assertEqual(num2words(4000000000, lang='sl'), "štiri miljarde") def test_cardinal_for_decimal_number(self): self.assertEqual(num2words(3.48, lang='sl'), "tri celih štiri osem") def test_ordinal_for_negative_numbers(self): self.assertRaises(TypeError, num2words, -12, ordinal=True, lang='sl') def test_ordinal_for_floating_numbers(self): self.assertRaises(TypeError, num2words, 2.453, ordinal=True, lang='sl') num2words-0.5.6/tests/test_tr.py000066400000000000000000000217431320535062200166670ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # Copyright (c) 2017, Tufan Kaynak, Framras. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from unittest import TestCase from num2words import num2words class Num2WordsTRTest(TestCase): def test_tr(self): # ref https://github.com/savoirfairelinux/num2words/issues/8 self.assertEqual(num2words(1, True, "tr"), u"birinci") self.assertEqual(num2words(2, True, "tr"), u"ikinci") self.assertEqual(num2words(9, True, "tr"), u"dokuzuncu") self.assertEqual(num2words(10, True, "tr"), u"onuncu") self.assertEqual(num2words(11, True, "tr"), u"onbirinci") self.assertEqual(num2words(44, True, "tr"), u"kırkdördüncü") self.assertEqual(num2words(100, True, "tr"), u"yüzüncü") self.assertEqual(num2words(101, True, "tr"), u"yüzbirinci") self.assertEqual(num2words(103, True, "tr"), u"yüzüçüncü") self.assertEqual(num2words(110, True, "tr"), u"yüzonuncu") self.assertEqual(num2words(111, True, "tr"), u"yüzonbirinci") self.assertEqual(num2words(1000, True, "tr"), u"bininci") self.assertEqual(num2words(1001, True, "tr"), u"binbirinci") self.assertEqual(num2words(1010, True, "tr"), u"binonuncu") self.assertEqual(num2words(1011, True, "tr"), u"binonbirinci") self.assertEqual(num2words(1100, True, "tr"), u"binyüzüncü") self.assertEqual(num2words(1110, True, "tr"), u"binyüzonuncu") self.assertEqual( num2words(2341, True, "tr"), u"ikibinüçyüzkırkbirinci" ) self.assertEqual(num2words(10000, True, "tr"), u"onbininci") self.assertEqual(num2words(10010, True, "tr"), u"onbinonuncu") self.assertEqual(num2words(10100, True, "tr"), u"onbinyüzüncü") self.assertEqual(num2words(10110, True, "tr"), u"onbinyüzonuncu") self.assertEqual(num2words(11000, True, "tr"), u"onbirbininci") self.assertEqual(num2words(35000, True, "tr"), u"otuzbeşbininci") self.assertEqual( num2words(116331, True, "tr"), u"yüzonaltıbinüçyüzotuzbirinci" ) self.assertEqual( num2words(116330, True, "tr"), u"yüzonaltıbinüçyüzotuzuncu" ) self.assertEqual(num2words(100000, True, "tr"), u"yüzbininci") self.assertEqual(num2words(501000, True, "tr"), u"beşyüzbirbininci") self.assertEqual( num2words(1000111, True, "tr"), u"birmilyonyüzonbirinci" ) self.assertEqual( num2words(111000111, True, "tr"), u"yüzonbirmilyonyüzonbirinci" ) self.assertEqual( num2words(111001111, True, "tr"), u"yüzonbirmilyonbinyüzonbirinci" ) self.assertEqual( num2words(111111111, True, "tr"), u"yüzonbirmilyonyüzonbirbinyüzonbirinci" ) self.assertEqual(num2words(100001000, True, "tr"), u"yüzmilyonbininci") self.assertEqual( num2words(100001001, True, "tr"), u"yüzmilyonbinbirinci" ) self.assertEqual( num2words(100010000, True, "tr"), u"yüzmilyononbininci" ) self.assertEqual( num2words(100010001, True, "tr"), u"yüzmilyononbinbirinci" ) self.assertEqual( num2words(100011000, True, "tr"), u"yüzmilyononbirbininci" ) self.assertEqual( num2words(100011001, True, "tr"), u"yüzmilyononbirbinbirinci" ) self.assertEqual( num2words(101011001, True, "tr"), u"yüzbirmilyononbirbinbirinci" ) self.assertEqual( num2words(101011010, True, "tr"), u"yüzbirmilyononbirbinonuncu" ) self.assertEqual( num2words(1101011010, True, "tr"), u"birmilyaryüzbirmilyononbirbinonuncu" ) self.assertEqual( num2words(101101011010, True, "tr"), u"yüzbirmilyaryüzbirmilyononbirbinonuncu" ) self.assertEqual( num2words(1000000000001, True, "tr"), u"birtrilyonbirinci" ) self.assertEqual(num2words(1, False, "tr"), u"bir") self.assertEqual(num2words(2, False, "tr"), u"iki") self.assertEqual(num2words(9, False, "tr"), u"dokuz") self.assertEqual(num2words(10, False, "tr"), u"on") self.assertEqual(num2words(11, False, "tr"), u"onbir") self.assertEqual(num2words(44, False, "tr"), u"kırkdört") self.assertEqual(num2words(100, False, "tr"), u"yüz") self.assertEqual(num2words(101, False, "tr"), u"yüzbir") self.assertEqual(num2words(103, False, "tr"), u"yüzüç") self.assertEqual(num2words(110, False, "tr"), u"yüzon") self.assertEqual(num2words(111, False, "tr"), u"yüzonbir") self.assertEqual(num2words(1000, False, "tr"), u"bin") self.assertEqual(num2words(1001, False, "tr"), u"binbir") self.assertEqual(num2words(1010, False, "tr"), u"binon") self.assertEqual(num2words(1011, False, "tr"), u"binonbir") self.assertEqual(num2words(1100, False, "tr"), u"binyüz") self.assertEqual(num2words(1110, False, "tr"), u"binyüzon") self.assertEqual(num2words(2341, False, "tr"), u"ikibinüçyüzkırkbir") self.assertEqual(num2words(10000, False, "tr"), u"onbin") self.assertEqual(num2words(10010, False, "tr"), u"onbinon") self.assertEqual(num2words(10100, False, "tr"), u"onbinyüz") self.assertEqual(num2words(10110, False, "tr"), u"onbinyüzon") self.assertEqual(num2words(11000, False, "tr"), u"onbirbin") self.assertEqual(num2words(35000, False, "tr"), u"otuzbeşbin") self.assertEqual( num2words(116331, False, "tr"), u"yüzonaltıbinüçyüzotuzbir" ) self.assertEqual( num2words(116330, False, "tr"), u"yüzonaltıbinüçyüzotuz" ) self.assertEqual(num2words(500000, False, "tr"), u"beşyüzbin") self.assertEqual(num2words(501000, False, "tr"), u"beşyüzbirbin") self.assertEqual(num2words(1000111, False, "tr"), u"birmilyonyüzonbir") self.assertEqual( num2words(111000111, False, "tr"), u"yüzonbirmilyonyüzonbir" ) self.assertEqual( num2words(111001111, False, "tr"), u"yüzonbirmilyonbinyüzonbir" ) self.assertEqual( num2words(111111111, False, "tr"), u"yüzonbirmilyonyüzonbirbinyüzonbir" ) self.assertEqual(num2words(100001000, False, "tr"), u"yüzmilyonbin") self.assertEqual(num2words(100001001, False, "tr"), u"yüzmilyonbinbir") self.assertEqual(num2words(100010000, False, "tr"), u"yüzmilyononbin") self.assertEqual( num2words(100010001, False, "tr"), u"yüzmilyononbinbir" ) self.assertEqual( num2words(100011000, False, "tr"), u"yüzmilyononbirbin" ) self.assertEqual( num2words(100011001, False, "tr"), u"yüzmilyononbirbinbir" ) self.assertEqual( num2words(101011001, False, "tr"), u"yüzbirmilyononbirbinbir" ) self.assertEqual( num2words(101011010, False, "tr"), u"yüzbirmilyononbirbinon" ) self.assertEqual( num2words(1101011010, False, "tr"), u"birmilyaryüzbirmilyononbirbinon" ) self.assertEqual( num2words(101101011010, False, "tr"), u"yüzbirmilyaryüzbirmilyononbirbinon" ) self.assertEqual( num2words(1000000000001, False, "tr"), u"birtrilyonbir" ) self.assertEqual(num2words(0.01, False, "tr"), u"sıfırvirgülbir") self.assertEqual(num2words(0.1, False, "tr"), u"sıfırvirgülon") self.assertEqual(num2words(0.21, False, "tr"), u"sıfırvirgülyirmibir") self.assertEqual(num2words(1.01, False, "tr"), u"birvirgülbir") self.assertEqual(num2words(1.1, False, "tr"), u"birvirgülon") self.assertEqual(num2words(1.21, False, "tr"), u"birvirgülyirmibir") self.assertEqual( num2words(101101011010.02, False, "tr"), u"yüzbirmilyaryüzbirmilyononbirbinonvirgüliki" ) self.assertEqual( num2words(101101011010.2, False, "tr"), u"yüzbirmilyaryüzbirmilyononbirbinonvirgülyirmi" ) num2words-0.5.6/tests/test_uk.py000066400000000000000000000157361320535062200166660ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from unittest import TestCase from num2words import num2words class Num2WordsUKTest(TestCase): def test_to_cardinal(self): self.maxDiff = None self.assertEqual(num2words(100, lang='uk'), 'сто') # self.assertEqual(num2words(101, lang='uk'), 'сто один') self.assertEqual(num2words(110, lang='uk'), 'сто десять') self.assertEqual(num2words(115, lang='uk'), "сто п'ятнадцять") self.assertEqual(num2words(123, lang='uk'), 'сто двадцять три') self.assertEqual(num2words(1000, lang='uk'), 'одна тисяча') # self.assertEqual(num2words(1001, lang='uk'), 'одна тисяча один') self.assertEqual(num2words(2012, lang='uk'), 'двi тисячi дванадцять') self.assertEqual( num2words(12519.85, lang='uk'), "дванадцять тисяч п'ятсот дев'ятнадцять кома вiсiмдесят п'ять") # self.assertEqual( # num2words(1234567890, lang='uk'), # "мiльярд двiстi тридцать чотири мiльйона п'ятсот шiстдесят сiмь " # "тисяч вiсiмсот дев'яносто") # self.assertEqual( # num2words(215461407892039002157189883901676, lang='uk'), # "двiстi п'ятнадцять нонiльйонiв чотириста шiстдесят один " # "октильйон чотириста сiм септильйонiв вiсiмсот дев'яносто " # "два секстильйони тридцять дев'ять квiнтильйонiв два " # "квадрильйони сто п'ятдесят сiм трильйонiв сто вiсiмдесят " # "дев'ять мiльярдiв вiсiмсот вiсiмдесят три мiльйона " # "дев'ятсот одна тисяча шiстсот " # "сiмдесят шiсть") # self.assertEqual( # num2words(719094234693663034822824384220291, lang='uk'), # "сiмсот дев'ятнадцять нонiльйонiв дев'яносто чотири октильйони " # "двiстi тридцять чотири септильйони шiстсот дев'яносто три " # "секстильйони шiстсот шiстдесят три квiнтильйони тридцять " # "чотири квадрильйони вiсiмсот двадцять два трильйони вiсiмсот " # "двадцять чотири мiльярди триста вiсiмдесят чотири мiльйона " # "двiстi двадцять тисяч двiстi дев'яносто один") def test_and_join_199(self): self.assertEqual(num2words(187, lang='uk'), "сто вiсiмдесят сiм") def test_cardinal_for_float_number(self): self.assertEqual( num2words(12.40, lang='uk'), "дванадцять кома чотири" ) self.assertEqual( num2words(17.31, lang='uk'), "сiмнадцять кома тридцять одна" ) self.assertEqual( num2words(14.13, lang='uk'), "чотирнадцять кома тринадцять" ) self.assertEqual( num2words(12.31, lang='uk'), "дванадцять кома тридцять одна" ) def test_to_ordinal(self): # @TODO: implement to_ordinal with self.assertRaises(NotImplementedError): num2words(1, lang='uk', to='ordinal') def test_to_currency(self): # self.assertEqual( # num2words(1.0, lang='uk', to='currency', currency='EUR'), # "один евро, нуль центiв" # ) self.assertEqual( num2words(1.0, lang='uk', to='currency', currency='UAH'), "одна гривня, нуль копiйок" ) self.assertEqual( num2words(1234.56, lang='uk', to='currency', currency='EUR'), "одна тисяча двiстi тридцять чотири евро, п'ятдесят шiсть центiв" ) self.assertEqual( num2words(1234.56, lang='uk', to='currency', currency='UAH'), "одна тисяча двiстi тридцять чотири гривнi, п'ятдесят шiсть " "копiйок" ) # self.assertEqual( # num2words(10111, lang='uk', to='currency', currency='EUR', # seperator=u' та'), # "сто один евро та одинадцять центiв" # ) self.assertEqual( num2words(10121, lang='uk', to='currency', currency='UAH', seperator=u' та'), "сто одна гривня та двадцять одна копiйка" ) self.assertEqual( num2words(10121, lang='uk', to='currency', currency='UAH', seperator=u' та'), "сто одна гривня та двадцять одна копiйка" ) self.assertEqual( num2words(10122, lang='uk', to='currency', currency='UAH', seperator=u' та'), "сто одна гривня та двадцять двi копiйки" ) # self.assertEqual( # num2words(10121, lang='uk', to='currency', currency='EUR', # seperator=u' та'), # "сто один евро та двадцять один цент" # ) self.assertEqual( num2words(-1251985, lang='uk', to='currency', currency='EUR', cents=False), "мiнус дванадцять тисяч п'ятсот дев'ятнадцять евро, 85 центiв" ) self.assertEqual( num2words('38.4', lang='uk', to='currency', seperator=' и', cents=False, currency='EUR'), "тридцять вiсiм евро и 40 центiв" ) num2words-0.5.6/tests/test_vn.py000066400000000000000000000140721320535062200166620ustar00rootroot00000000000000# -*- encoding: utf-8 -*- # Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved. # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA from __future__ import unicode_literals from unittest import TestCase from num2words import num2words class Num2WordsVNTest(TestCase): def test_0(self): self.assertEqual(num2words(0, lang="vi_VN"), "không") def test_1_to_10(self): self.assertEqual(num2words(1, lang="vi_VN"), "một") self.assertEqual(num2words(2, lang="vi_VN"), "hai") self.assertEqual(num2words(7, lang="vi_VN"), "bảy") self.assertEqual(num2words(10, lang="vi_VN"), "mười") def test_11_to_19(self): self.assertEqual(num2words(11, lang="vi_VN"), "mười một") self.assertEqual(num2words(13, lang="vi_VN"), "mười ba") self.assertEqual(num2words(14, lang="vi_VN"), "mười bốn") self.assertEqual(num2words(15, lang="vi_VN"), "mười lăm") self.assertEqual(num2words(16, lang="vi_VN"), "mười sáu") self.assertEqual(num2words(19, lang="vi_VN"), "mười chín") def test_20_to_99(self): self.assertEqual(num2words(20, lang="vi_VN"), "hai mươi") self.assertEqual(num2words(23, lang="vi_VN"), "hai mươi ba") self.assertEqual(num2words(28, lang="vi_VN"), "hai mươi tám") self.assertEqual(num2words(31, lang="vi_VN"), "ba mươi mốt") self.assertEqual(num2words(40, lang="vi_VN"), "bốn mươi") self.assertEqual(num2words(66, lang="vi_VN"), "sáu mươi sáu") self.assertEqual(num2words(92, lang="vi_VN"), "chín mươi hai") def test_100_to_999(self): self.assertEqual(num2words(100, lang="vi_VN"), "một trăm") self.assertEqual(num2words(150, lang="vi_VN"), "một trăm năm mươi") self.assertEqual( num2words(196, lang="vi_VN"), "một trăm chín mươi sáu" ) self.assertEqual(num2words(200, lang="vi_VN"), "hai trăm") self.assertEqual(num2words(210, lang="vi_VN"), "hai trăm mười") def test_1000_to_9999(self): self.assertEqual(num2words(1000, lang="vi_VN"), "một nghìn") self.assertEqual(num2words(1500, lang="vi_VN"), "một nghìn năm trăm") self.assertEqual( num2words(7378, lang="vi_VN"), "bảy nghìn ba trăm bảy mươi tám" ) self.assertEqual(num2words(2000, lang="vi_VN"), "hai nghìn") self.assertEqual(num2words(2100, lang="vi_VN"), "hai nghìn một trăm") self.assertEqual( num2words(6870, lang="vi_VN"), "sáu nghìn tám trăm bảy mươi" ) self.assertEqual(num2words(10000, lang="vi_VN"), "mười nghìn") self.assertEqual(num2words(100000, lang="vi_VN"), "một trăm nghìn") self.assertEqual( num2words(523456, lang="vi_VN"), "năm trăm hai mươi ba nghìn bốn trăm năm mươi sáu" ) def test_big(self): self.assertEqual(num2words(1000000, lang="vi_VN"), "một triệu") self.assertEqual( num2words(1200000, lang="vi_VN"), "một triệu hai trăm nghìn" ) self.assertEqual(num2words(3000000, lang="vi_VN"), "ba triệu") self.assertEqual( num2words(3800000, lang="vi_VN"), "ba triệu tám trăm nghìn" ) self.assertEqual(num2words(1000000000, lang="vi_VN"), "một tỷ") self.assertEqual(num2words(2000000000, lang="vi_VN"), "hai tỷ") self.assertEqual( num2words(2000001000, lang="vi_VN"), "hai tỷ một nghìn" ) self.assertEqual( num2words(1234567890, lang="vi_VN"), "một tỷ hai trăm ba mươi bốn triệu năm trăm sáu mươi bảy nghìn " "tám trăm chín mươi" ) def test_decimal_number(self): self.assertEqual( num2words(1000.11, lang="vi_VN"), "một nghìn phẩy mười một" ) self.assertEqual( num2words(1000.21, lang="vi_VN"), "một nghìn phẩy hai mươi mốt" ) def test_special_number(self): """ Some number will have some specail rule """ self.assertEqual(num2words(21, lang="vi_VN"), "hai mươi mốt") self.assertEqual(num2words(25, lang="vi_VN"), "hai mươi lăm") # >100 self.assertEqual(num2words(101, lang="vi_VN"), "một trăm lẻ một") self.assertEqual(num2words(105, lang="vi_VN"), "một trăm lẻ năm") self.assertEqual(num2words(701, lang="vi_VN"), "bảy trăm lẻ một") self.assertEqual(num2words(705, lang="vi_VN"), "bảy trăm lẻ năm") # >1000 self.assertEqual(num2words(1001, lang="vi_VN"), "một nghìn lẻ một") self.assertEqual(num2words(1005, lang="vi_VN"), "một nghìn lẻ năm") self.assertEqual( num2words(98765, lang="vi_VN"), "chín mươi tám nghìn bảy trăm sáu mươi lăm" ) # > 1000000 self.assertEqual(num2words(3000005, lang="vi_VN"), "ba triệu lẻ năm") self.assertEqual(num2words(1000007, lang="vi_VN"), "một triệu lẻ bảy") # > 1000000000 self.assertEqual( num2words(1000000017, lang="vi_VN"), "một tỷ lẻ mười bảy" ) self.assertEqual( num2words(1000101017, lang="vi_VN"), "một tỷ một trăm lẻ một nghìn lẻ mười bảy" ) num2words-0.5.6/tox.ini000066400000000000000000000005301320535062200147710ustar00rootroot00000000000000[tox] envlist = flake8, isort, py27,py34,py35,py36 [testenv] passenv = TRAVIS TRAVIS_* deps = -r{toxinidir}/requirements-test.txt commands = flake8 isort --check-only --recursive --diff num2words tests coverage erase coverage run -m unittest discover coverage report --fail-under=75 --omit=.tox/*,/usr/* coveralls