danthorpe / Money

Swift value types for working with money & currency
MIT License
933 stars 91 forks source link

Add support for localized description - i.e. use language associated with currency. #24

Closed mrdavey closed 8 years ago

mrdavey commented 8 years ago

In some countries, such as France/Germany/Italy/Spain, the Euro sign is placed after the amount. E.g. 3,50 € (note that they also use a ',' instead of '.' for sub units). More information can be found here: https://en.wikipedia.org/wiki/Euro_sign#Use

danthorpe commented 8 years ago

Hi @mrdavey thanks for the feedback. Have you seen a bug where the placement is incorrect?

mrdavey commented 8 years ago

Yes, when I use let amount = EUR(floatLiteral: money) as per our recent Twitter conversation.

It shows € 300.80 when it should be 300,80 € (if you were to follow the Euro standards currently in use).

danthorpe commented 8 years ago

Hmm. In Settings, what is your language set to?

mrdavey commented 8 years ago

Sorry for not explaining the use case properly. The app I'm creating shows multiple currencies (USD, EUR, CNY, etc) and the user can switch between the different currencies by selecting a button.

So at the moment, the simulator is set to US English. However I want users to be able to see the correct currency format and placement, no matter what language their device is set to.

It's more of a nitpick than a serious issue. :)

danthorpe commented 8 years ago

Yeah, I've considered this use case. At the moment, the implementation of CustomStringRepresentable uses standard NSNumberFormatter and NSLocale, so you get the representation of the currency in the current system language - which I think is the correct for most use cases.

To be able to display the language localized representation, without changing the language in settings is possible (I think) with NSLocale. Not immediately obvious what would be the best way to expose it on the type. Maybe as a money.localizedDescription? What do you think?

Regardless, I will update the README to make it clear at the top that those are in English language locale.

mrdavey commented 8 years ago

Yes money.localizedDescription could work well in this case. Thanks for taking the feedback on board @danthorpe . Much appreciated!

danthorpe commented 8 years ago

No props - will look into it today - look out for version 1.4.0.

danthorpe commented 8 years ago

Clearly, the tricky thing with this, is say for example EUR which is used in many countries with different languages - it might require more information to say print out the Spanish localized description, versus the French localized description...

danthorpe commented 8 years ago

See #26 for work on this.

danthorpe commented 8 years ago

Hi @mrdavey - I've merged #26 into development, if you have time, please take a look, I think your use case should now be covered. The README has been updated to include the changes.

You can use the development branch in CocoaPods by doing:

pod 'Money', :git => 'https://github.com/danthorpe/Money', :branch => 'development'

or for Carthage:

github 'danthorpe/Money' 'development'

Please get back to me here if you have any issues - I really want to make sure that the formatting is bulletproof!