-
Notifications
You must be signed in to change notification settings - Fork 0
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
number to word conception #1
Comments
It will be for ANY language in the world. Keep it in mind: ANY. 😃 |
Hey guys! Looking forward to this project. It seems really promising. Just a few thoughts about it:
If I can help somehow, please ping me on Slack or here. I'll be glad to help. |
@joubertredrat Just saw your gist and have some suggestions:
|
One more thing, my suggestion about the package usage interface: <?php
interface NumberToWord {
public function __construct(Language $language);
public function getValueInWords($valueInNumbers);
public function getValueInNumbers($valueInWords);
}
// usage
$value = new NumberToWord(new PortugueseLanguage());
$value->getValueInWords(299); // will output duzentos e noventa e nove
$value->getValueInNumbers('duzentos e noventa e nove'); // will output 299 |
The question actually is how are we going to structure this file to be generic for every language, since every language has their own specificities. Example for the number 1700:
The problem here is:
See what I mean? Each language structures numbers in a totally different ways and some even have more than one way to do this. How to structure this file? Am I overcomplicating things? |
@pedrochaves I agree with you that each language has it's own structure so it's hard to create a generic code to all. That's why I proposed a |
Guys, just made a commit with the basic structure that I said previously. I think there's several flaws on it, but it's a start. Do you guys have any idea on how to improve it? I'm quite skeptical about the Anyway, it's just a proposal. If you guys think it's good, we can move forward with it. If there's some better approaches to it, feel free to move on another direction. |
@luizpedone I thought of some alternatives (I also changed the method names, see what you guys think):
$translator = NumberToWordTranslatorFactory::createForLanguage(Language::PORTUGUESE);
$word = $translator->toWord(299);
$number $translator->toNumber('duzentos');
$translator = new NumberToWordTranslator();
// This would be the __call, setting a private attribute
$translator->loadPortuguese();
// Or another option (in this case, the parameter can be passed on constructor)
$translator->load(Language::PORTUGUESE);
$word = $translator->toWord(299);
$number = $translator->toNumber('duzentos');
$translator = new NumberToWordTranslator();
// This would have to be a singleton to avoid creating objects on every call
$word = $translator->portuguese->toWord(299);
$number = $translator->portuguese->toNumber('duzentos'); (enums would be awesome here :() |
Hi guys, For consistent language selector, we need to use RFC 3066 to set language, as in here. |
Hi guys,
This is a first conception about translate numbers to words but I have more questions.
If I have more questions I will put here. Let's talk.
The text was updated successfully, but these errors were encountered: