You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! Thanks for this library. I love using bojanz/currency for ISO-defined currencies and localizing them. However, I occasionally need to work with codes that are not in the standard ISO 4217 list, such as:
Cryptocurrencies (BTC, ETH, etc.).
Custom or test codes for internal usage.
Currently, bojanz/currency has no public API to register or define additional currency codes. If I try to do NewAmount("100", "BTC"), it fails with an “unknown currency code” error (since BTC is absent in data.go).
I’d like to request a feature that allows adding custom entries at runtime, similar to how some libraries have a Register or AddCurrency function. This could look like: Then, the code NewAmount("123.45", "BTC") would succeed, and formatter.Format would also work if I supply it with, say, a default symbol or pattern.
Rationale:
Many real-world applications mix official ISO currencies with special tokens or private codes.
A Register approach would keep the library’s built-in data intact while letting advanced users inject their own definitions.
Without it, we either have to fork data.go or maintain a separate logic for custom codes and do manual formatting.
Possible approach:
A public map or method in the package that merges user-provided data with the built-in CLDR sets.
For formatting, if a custom code is found, we use user-specified digits/symbol instead of failing.
Ideally, it could be a single currency.Register(...) method.
I realize that might require some discussion about how to handle locale-specific symbols, but even minimal support (like picking a fallback or “generic” symbol) would be extremely helpful.
Questions:
Would you be open to a PR that introduces a Register() or AddCurrency() method?
Alternatively, is there a recommended approach/pattern for working with non-ISO codes that I might have missed?
Thanks again for your great work on this library! Let me know if you need more details or if there’s another recommended solution for custom codes.
The text was updated successfully, but these errors were encountered:
dejurin
changed the title
Add a way to register custom (non-ISO) currencies at runtime
Feature Request: Add a way to register custom (non-ISO) currencies at runtime
Dec 23, 2024
dejurin
changed the title
Feature Request: Add a way to register custom (non-ISO) currencies at runtime
Feature Request: Add a way to register custom (non-ISO) currencies
Dec 23, 2024
dejurin
added a commit
to dejurin/currency
that referenced
this issue
Dec 23, 2024
Hi! Thanks for this library. I love using bojanz/currency for ISO-defined currencies and localizing them. However, I occasionally need to work with codes that are not in the standard ISO 4217 list, such as:
Currently, bojanz/currency has no public API to register or define additional currency codes. If I try to do NewAmount("100", "BTC"), it fails with an “unknown currency code” error (since BTC is absent in data.go).
I’d like to request a feature that allows adding custom entries at runtime, similar to how some libraries have a Register or AddCurrency function. This could look like: Then, the code NewAmount("123.45", "BTC") would succeed, and formatter.Format would also work if I supply it with, say, a default symbol or pattern.
Rationale:
Possible approach:
I realize that might require some discussion about how to handle locale-specific symbols, but even minimal support (like picking a fallback or “generic” symbol) would be extremely helpful.
Questions:
Thanks again for your great work on this library! Let me know if you need more details or if there’s another recommended solution for custom codes.
The text was updated successfully, but these errors were encountered: