Skip to content
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

nicer way to add new languages #30

Open
longemen3000 opened this issue Jan 15, 2021 · 3 comments
Open

nicer way to add new languages #30

longemen3000 opened this issue Jan 15, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@longemen3000
Copy link
Contributor

longemen3000 commented Jan 15, 2021

in master, the list of languages supported is hardcoded. what if we dispatch on Val{:sym}? something like:

function spelled_out(
    number::Number;
    lang::Symbol = Symbol(first(split(ENV["LANG"], '.'))),
    dict::Symbol = :modern
)
return spelled_out_impl(number,Val{lang},dict)
end
#catchall
function spelled_out_impl(number,lang,dict)
throw(error("We do not support $lang yet.  Please make an issue and someone might be able to help you, or feel free to contribute."))
end

and each impl. could just simply do:

function spelled_out_impl(number,lang::Type{Val{:ru}},dict)

the use of the type instead of building the val is because there is a cost on building the struct, that is elided completely when only using the type

as a nice consequence of using this, an external user could plug its own spelling function, or modify the output of existing ones

@jakewilliami
Copy link
Owner

This is a good idea! Do you want to make a PR or should I do this?

@longemen3000
Copy link
Contributor Author

I'm writing the Spanish support, I could add the modification in that PR

@jakewilliami
Copy link
Owner

jakewilliami commented Jan 16, 2021

That would be good, thank you Andrés.

Would it still be a keyword argument? I.e., would I be able to write

spelled_out(123467, lang = :ru)

?

And would we still be able to have aliases and equivalences?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants