Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Avoid error using only local translation files #367

Merged
merged 6 commits into from
Nov 4, 2021
Merged

Conversation

krysal
Copy link
Member

@krysal krysal commented Oct 26, 2021

Fixes

Fixes #298 by @sarayourfriend

Description

This addresses the problem of the project failing to run if not all translation files are present, avoiding doing i18n:get-translations previously.

It adds a step to the dev command to generate the locales list. The downside of this approach is that it modifies the valid-locales.json file and we will need to be alert in PR changes, but do we really need to track it? Looks like it is actually not used.

Testing Instructions

  1. Delete any translation file other than the en.json
  2. Run the project in this branch: npm run dev
  3. See no errors.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@krysal krysal requested a review from a team as a code owner October 26, 2021 21:09
@krysal krysal requested review from zackkrida and obulat October 26, 2021 21:09
@zackkrida
Copy link
Member

I'm pretty sure we can add valid-locales.json to the .gitignore, I think that's worth exploring here @krysal 👍

@krysal krysal added 💻 aspect: code Concerns the software code in the repository 🧰 goal: internal improvement Improvement that benefits maintainers, not users labels Oct 26, 2021
Copy link
Member

@dhruvkb dhruvkb left a comment

Choose a reason for hiding this comment

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

LGTM! Not sure why CI is failing though.

package.json Outdated Show resolved Hide resolved
@zackkrida zackkrida self-requested a review November 4, 2021 09:38
Copy link
Contributor

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

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

LGTM. +1 to what Dhruv said. Super great to not track generated files 🙂

@krysal
Copy link
Member Author

krysal commented Nov 4, 2021

The /src/locales/scripts/valid-locales.json file is used in nuxt.config.js so it's critical that the file is present to run the tests. Adding the command to get translations solves it. Do you want to take a second look at this @zackkrida?

package.json Outdated Show resolved Hide resolved
@sarayourfriend
Copy link
Contributor

If that file is a pre-requisite for running the tests, even locally, then we should probably add it to the test scripts.

I wonder if there's a way to just add it to the jest setup though instead of having to duplicate it across all the NPM scripts.

Which brings up the other option, of using just instead of npm scripts as just has proper dependency support for each recipe and cross-environment ENV variables built in (we wouldn't need cross-env) and much easier support for overriding variables (like right now to run the app locally without audio you need to modify the package.json, with just we could just make it an argument).

But that's controversial... idk many frontend projects (if any) that don't use npm scripts.

@krysal
Copy link
Member Author

krysal commented Nov 4, 2021

Thinking again, it makes more sense to add the get-translation step in the Github action! And keep the package.json lean, in my view. Do you think the same?

Edit: You beat me for a minute. just sounds like a good alternative, though a bit overkill for what we need here (?) having npm scripts. Before adding cross-env to the dev command I was using a .env file which has the advantages of remembering your configuration, although I have not tested it on Windows. And a solution for the error of not having local translations files is here too. Seems that in the end it is a matter of preferences.

@krysal
Copy link
Member Author

krysal commented Nov 4, 2021

I remembered why I had chosen to use just the get-validated-locales node script instead of the npm i18n:get-translations... Network requests are slow! and doing it whitin every dev script run is a pain in slow connections. I'm changing that back.

@krysal krysal force-pushed the use_validated_locales branch from 7be1500 to c1bb0a6 Compare November 4, 2021 15:48
@sarayourfriend
Copy link
Contributor

I remembered why I had chosen to use just the get-validated-locales node script instead of the npm i18n:get-translations... Network requests are slow! and doing it whitin every dev script run is a pain in slow connections. I'm changing that back.

💯

@zackkrida
Copy link
Member

@krysal I would add a "i18n:get-valid-locales": "node src/locales/scripts/get-validated-locales" script, and add that to the dev script, then get this merged 👍

@krysal
Copy link
Member Author

krysal commented Nov 4, 2021

Done! Thanks for your suggestions pals 😄

@krysal krysal merged commit ac57086 into main Nov 4, 2021
@krysal krysal deleted the use_validated_locales branch November 4, 2021 16:17
rbadillap added a commit that referenced this pull request Nov 12, 2021
* main:
  Replace PDM logo (#411)
  Add playwright e2e tests (#394)
  Update breakpoints to the new Tailwind config (#408)
  Create a global audio player (amongst many smaller improvements) (#399)
  Create Skeleton components (#392)
  Tailwind breakpoints (#403)
  Avoid error using only local translation files (#367)
  Add base Button component (#372)
  Use Tailwind RTL styles everywhere (#355)
  Add a dependencies section and remove the redundant title (#379)
  🔄 Synced file(s) with WordPress/openverse (#384)
  Fix filters not being set on SSR (#386)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
💻 aspect: code Concerns the software code in the repository 🧰 goal: internal improvement Improvement that benefits maintainers, not users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Frontend fails to run if translations aren't fetched first
4 participants