Skip to content

Use better i18n for generating tax adjustment labels#914

Merged
gmacdougall merged 1 commit intomasterfrom
unknown repository
Mar 3, 2016
Merged

Use better i18n for generating tax adjustment labels#914
gmacdougall merged 1 commit intomasterfrom
unknown repository

Conversation

@mamhoff
Copy link
Copy Markdown
Contributor

@mamhoff mamhoff commented Feb 26, 2016

The previous code for generating tax adjustment labels has several
drawbacks:

  • The i18n keys used are not namespaced
  • The i18n in place did not allow the main app to specify
    the number format, which is bad for Europe, where we often
    write numbers different than the US (1,40 Euro, anyone?)
  • The code in place did not allow the format of the label
    to be anything different from what was in Spree::TaxRate#create_label.
  • The code on place relied on MRI interpreter quirks (namely that a
    variable in an untouched if branch would become nil rather
    than raising a NoMethodError).

In the future, adjustments should IMO not actually store their translations
in the database at all, but instead create them using their own data. But
that's not something I want to tackle now.

Comment thread core/app/models/spree/tax_rate.rb Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this space. This should be in the translation, not here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case I could possible also remove the show_rate_in_label column, as that's be handled by I18n entirely, no?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup.

@tvdeyen
Copy link
Copy Markdown
Member

tvdeyen commented Feb 26, 2016

Dance

@tvdeyen
Copy link
Copy Markdown
Member

tvdeyen commented Feb 26, 2016

Shouldn't we get rid of the label column, then?

@mamhoff
Copy link
Copy Markdown
Contributor Author

mamhoff commented Feb 26, 2016

That would require quite a bit of work, also in Promotions. I think I want to see how the discussion about removing taxes from adjustments generally pans out. If you look at #904, that's how I'd like to see it done in the future.

Comment thread core/spec/models/spree/tax_rate_spec.rb Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at block body beginning.

@cbrunsdon
Copy link
Copy Markdown
Contributor

I'm cool with this, I didn't realize previously that the "refund" label could only apply to VAT transactions. Thanks martin 👍

@jhawthorn
Copy link
Copy Markdown
Contributor

👍 Much improved. Thank you.

Comment thread core/app/models/spree/tax_rate.rb Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line detected.

The previous code for generating tax adjustment labels has several
drawbacks:

* The i18n keys used are not namespaced
* The i18n in place did not allow the main app to specify
  the number format, which is bad for Europe, where we often
  write numbers different than the US (1,40 Euro, anyone?)
* The code in place did not allow the format of the label
  to be anything different from what was in Spree::TaxRate#create_label.
* The code on place relied on MRI interpreter quirks (namely that a
  variable in an untouched `if` branch would become `nil` rather
  than raising a `NoMethodError`.

In the future, adjustments should IMO not actually store their translations
in the database at all, but instead create them using their own data. But
that's not something I want to tackle now.

Additionally, I added lots of specs, becaue all of this was entirely untested.
@mamhoff
Copy link
Copy Markdown
Contributor Author

mamhoff commented Feb 29, 2016

I changed the architecture of this a little bit to give more freedom to i18n users. The general thrust of it stays the absolute same though.

In case you're wondering why there's a translation for a sales tax refund: it is algorithmically possible if someone switches out the tax calculator. And as with taxes, I've seen pigs fly, I thought I'll allow the possibility.

@tvdeyen
Copy link
Copy Markdown
Member

tvdeyen commented Feb 29, 2016

👍

gmacdougall added a commit that referenced this pull request Mar 3, 2016
…-labels

Use better i18n for generating tax adjustment labels
@gmacdougall gmacdougall merged commit 97b8f21 into solidusio:master Mar 3, 2016
@mamhoff mamhoff mentioned this pull request Mar 16, 2016
23 tasks
@mamhoff mamhoff deleted the better-i18n-for-tax-adjustment-labels branch May 24, 2016 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants