New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for Portuguese (Portugal) (PT) #198
Conversation
.gitignore
Outdated
@@ -4,3 +4,4 @@ dist | |||
.idea/ | |||
*.egg-info | |||
/.tox | |||
venv/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be part of your .git/info/exclude, not in tree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry, I'll remove it
num2words/lang_PT.py
Outdated
|
||
if self.MEGA_SUFFIX: | ||
self.cards[10 ** (n - 3)] = word + self.MEGA_SUFFIX | ||
if self.cards[10 ** (n - 3)] == 'milião': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't make any sense, if you are implementing set_high_numwords
just set the suffixes you, no need to use class props
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just used the set_high_numwords from lang_EU but I needed to correct the "milião".
Is it better if I correct it in merge? Like:
if ntext == 'milião':
ntext = 'milhão'
This seems really bad d1370be#diff-48c05b2e89d4eb8299b0f502c3707165R224 |
removed venv/ from .gitignore. correction from "milião" to "milhão" done on merge function. removed hack for negword, creating a backup of the original one.
Regarding the "hack" I did not understood if I need to correct anything. |
Pull Request Test Coverage Report for Build 520
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Olos Thanks a lot for taking the time to make this contribution.
There is a lot of duplicated code between pt
and pt_BR
. So these are my questions because I don't know Portuguese :
- Which are the difference in the way
pt
andpt_BR
write numbers? - If there are differences, could
pt_BR
class be refactored so it extendspt
and we avoid code duplication?
Please also check https://github.com/savoirfairelinux/num2words/pull/99/files it was a PR to add the same feature but without any tests, so never merged it.
.gitignore
Outdated
@@ -3,4 +3,4 @@ build | |||
dist | |||
.idea/ | |||
*.egg-info | |||
/.tox |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you remove the empty line at the end of the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must have been when I deleted the venv/ line.
Sorry. I will add it again.
Regarding the differences between the way pt-pt and pt-br write the numbers:
Do you think it can be expanded with these issues? The other pt-pt PR does not solve, if I analysed it correctly, the issues I stated above. |
@Olos You don't have to necessarily use pt-pt class as inheritance base, just refactor it so you can reuse what is common and get rid of obvious duplication |
@shulcsm @erozqba
If my previous assumptions are correct I can use pt-br for:
As they are all the same verbatim. Is this it? Thank you. |
@Olos yes, but you keep redefining huge dictionaries in it. For start move them into module constants and import them in your implementation. |
Sorry for not updating this yet but some things got in the way. |
Could I just use PT_pt as base for PT_br? I know pt-br was created first here but it makes more sense (at least to me) to do it like this. |
I'm ok with it @Olos, go ahead unless someone else has an inconvenient with it. |
@erozqba |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Olos thanks a lot! This looks good to me.
I have one question, could you clarify?
@@ -132,7 +72,7 @@ def merge(self, curr, next): | |||
return (ctext + ntext, cnum * nnum) | |||
|
|||
def to_cardinal(self, value): | |||
result = super(Num2Word_PT_BR, self).to_cardinal(value) | |||
result = lang_PT.Num2Word_EU.to_cardinal(self, value) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is really better to use the to_cardinal()
implementation on Num2Word_EU
instead of that the one on Num2Word_PT
? They are so different the cardinal numbers between pt
and pt_BR
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both of them use the Num2Word_EU
implementation and then change the output based on a regex.
I kept the original regex on pt_BR
but the regex on pt
is a little different.
In order for everything to work i thought it was better to continue to use Num2Word_EU
for both of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Olos is good for me then! I see you still have the PR marked as Work In Progress. If you have finished, change the status, please. Also, I will really appreciate if you can check the missed lines on the coverage by the tests and add some tests for this lines, so we increase the coverage to the maximum, https://coveralls.io/builds/19469219/source?filename=num2words%2Flang_PT.py#L134.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@erozqba Added new tests for those lines.
Pull Request Test Coverage Report for Build 546
💛 - Coveralls |
Fixes # by...
Changes proposed in this pull request:
Status
How to verify this change
Additional notes