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

Fix custom translations with options #3959

Merged
merged 1 commit into from
Apr 10, 2020
Merged

Conversation

decabeza
Copy link
Collaborator

References

This PR resolves #3676.

Objectives

There was a bug when an admin user tries to change a text on the "Custom information text" section /admin/site_customization/information_texts with the keys that include some %{variable} in the text.

Screenshot

BEFORE

interpolation

AFTER

after

@decabeza decabeza added the Bug label Mar 31, 2020
@decabeza decabeza added this to Reviewing in Consul Democracy via automation Mar 31, 2020
@@ -12,7 +12,15 @@ def t(key, options = {})
i18_content = I18nContent.find_by(key: key)
translation = I18nContentTranslation.find_by(i18n_content_id: i18_content&.id,
locale: current_locale)&.value
translation.presence || translate(key, options)
if translation.present?
if options.present?
Copy link
Member

@javierm javierm Apr 5, 2020

Choose a reason for hiding this comment

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

I'm not sure this condition is necessary 🤔. What do you think about:

        if translation.present?
          translation % options
        else
          translate(key, options)
        end

We could also write translation.presence&.%(options) || translate(key, options) but IMHO it would be hard to understand it 😅.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I used the first option that seems simpler. The second one is also very hard to understand for me. 😂

@javierm javierm moved this from Reviewing to Doing in Consul Democracy Apr 5, 2020
Consul Democracy automation moved this from Doing to Testing Apr 10, 2020
Copy link
Member

@javierm javierm left a comment

Choose a reason for hiding this comment

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

Great 😄.

@javierm javierm merged commit 06bc72c into master Apr 10, 2020
Consul Democracy automation moved this from Testing to Release 1.2.0 Apr 10, 2020
@javierm javierm deleted the i18n-custom-translations branch April 10, 2020 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Translation override - variable not passed
3 participants