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

Override model_name.human for PaymentMethod #2107

Merged
merged 1 commit into from
Jul 25, 2017

Conversation

jhawthorn
Copy link
Contributor

Recently we started using model_name.human instead of the raw class name when displaying the names of payment methods.

Unfortunately, if there isn't an i18n key for that specific payment method, model_name.human will fall back to "Payment Method", which is not at all helpful in distinguishing it.

This commit changes PaymentMethod.model_name to return a custom ActiveModel::Name subclass, which will use exact matches for translations but doesn't fall back to "Payment Method", and instead will
use the "humanized" class name if there is no key.

Fixes #2106

@jhawthorn jhawthorn requested a review from tvdeyen July 21, 2017 22:52
# subclasses as just "PaymentMethod"
class ModelName < ActiveModel::Name
# Similar to ActiveModel::Name#human, but skips lookup_ancestors
def human(options={})

Choose a reason for hiding this comment

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

Surrounding space missing in default value assignment.

@jhawthorn jhawthorn added this to the 2.3.0 milestone Jul 21, 2017
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

Thanks, John! We should ship this with 2.3

@tvdeyen
Copy link
Member

tvdeyen commented Jul 22, 2017

Ah, you already added the milestone. Thanks

Recently we started using model_name.human instead of the raw class name
when displaying the names of payment methods.

Unfortunately, if there isn't an i18n key for that specific payment
method, model_name.human will fall back to "Payment Method", which is
not at all helpful in distinguishing it.

This commit changes PaymentMethod.model_name to return a custom
ActiveModel::Name subclass, which will use exact matches for
translations but doesn't fall back to "Payment Method", and instead will
use the "humanized" class name if there is no key.
@jhawthorn jhawthorn force-pushed the payment_method_translation branch from 18a1f80 to ef2c1b4 Compare July 24, 2017 20:53
@jhawthorn jhawthorn merged commit 5283b4c into solidusio:master Jul 25, 2017
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.

3 participants