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

More realistic test env for translations #12489

Merged
merged 2 commits into from
May 30, 2024

Conversation

mkllnk
Copy link
Member

@mkllnk mkllnk commented May 17, 2024

What? Why?

Most production servers don't use the source locale en. Even if the default language is English, they use a local variant like en_AU or en_GB to customise some of the translations.

However the environment is configured, the app should always fallback to en if no other translation is available.

I was hoping to cover a recent bug with this change:

Unfortunately, the missing translation wasn't covered by any spec and this didn't help. But it may prevent other bugs in the future. Fallback translations are now used in tests and dev.

What should we test?

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

@mkllnk mkllnk self-assigned this May 17, 2024
@mkllnk mkllnk added the technical changes only These pull requests do not contain user facing changes and are grouped in release notes label May 17, 2024
@mkllnk mkllnk marked this pull request as ready for review May 22, 2024 04:25
Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

I was expecting this to be a no-brainer, but it raised some questions.

What do you think of just setting it in .env.test?

I'm not even sure about that though, and wondered if we can test the fallback another way. Maybe create a test.yml locale file and make that the default for .env.test. It just needs one key to test the translation, then we can test any other key for the fallback.

@@ -10,10 +10,10 @@ TIMEZONE="Melbourne"
DEFAULT_COUNTRY_CODE="AU"

# Locale for translation.
LOCALE="en"
LOCALE="en_AU"
Copy link
Member

Choose a reason for hiding this comment

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

As this affects all environments, I had a think:

  • It shouldn't matter for servers, they would all have config to override this.
  • It shouldn't affect devs much, because any new translation keys can still be added in en.yml, and the fallback will work. But what if they're confused and add new translations to en_AU?
  • Apparently it didn't affect specs. I would have thought some differences would pop up. Maybe they would in the future.

It seems strange that en_AU is the default instead of en. I can imagine someone changing it back again just because it looks wrong.

🤔 If en_AU is the default for dev/test, then en.yml is sort of redundant. Of course it still functions as the fallback, and is the source of truth for Transifex.

Copy link
Member Author

Choose a reason for hiding this comment

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

If en_AU is the default for dev/test, then en.yml is sort of redundant.

en_AU is still a production locale which is edited in Transifex while en.yml is the one locale changed by devs.

We could introduce a test locale which would be a bit more robust. At the moment, the Australian team could change something that breaks specs. It would be less realistic though. 🤔

Okay, what do you think about this proposal:

  • en_AU in .env.development, it's more realistic and we got other Australian data like default country and currency already.
  • en_TEST in .env.test.

Copy link
Member

Choose a reason for hiding this comment

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

That sounds good 👍

I guess en_TEST may be empty to begin with, until we add a specific test for it.

Copy link
Contributor

Choose a reason for hiding this comment

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

So, just to make sure I understood this correctly: the use-case here for specs is to have the empty file, so we can select it for a give system spec, and assert that no error is there, which demonstrates the fall-back to en.yml works correctly.

I guess en_TEST may be empty to begin with, until we add a specific test for it.

As for this, having valid keys and translations would be useful to test that the default selection works correctly in the test environment.

So, if I get this right, we could add two new test scenarios to translations 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, you got that right. It would be good to also test that the current locale is actually used and not just the fallback. 😉

Most production servers don't use the source locale `en`. Even if the
default language is English, they use a local variant like `en_AU` or
`en_GB` to customise some of the translations.

However the environment is configured, the app should always fallback to
`en` if no other translation is available.
So hopefully we'll notice if our fallback mechanism fails.
Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Cool, thanks!

Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

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

Great !

@filipefurtad0 filipefurtad0 self-assigned this May 30, 2024
@filipefurtad0 filipefurtad0 added pr-staged-fr staging.coopcircuits.fr pr-staged-au staging.openfoodnetwork.org.au labels May 30, 2024
@filipefurtad0
Copy link
Contributor

filipefurtad0 commented May 30, 2024

Hey @mkllnk ,

I've staged the PR and could verify that despite the missing translation files, #12429 remains fixed. For example, for the key
remaining_in_stock: "Only %{quantity} left" (missing in en_AU.yml), correctly falls back to en, and triggers no error:

image

For admin.order_cycles.status.open:
image

Looks good to me. Merging!

@filipefurtad0 filipefurtad0 removed pr-staged-au staging.openfoodnetwork.org.au pr-staged-fr staging.coopcircuits.fr labels May 30, 2024
@filipefurtad0 filipefurtad0 merged commit 9eaf6c3 into openfoodfoundation:master May 30, 2024
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
technical changes only These pull requests do not contain user facing changes and are grouped in release notes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants