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

Fix pot file generation #318

Merged
merged 8 commits into from Oct 14, 2021
Merged

Fix pot file generation #318

merged 8 commits into from Oct 14, 2021

Conversation

obulat
Copy link
Contributor

@obulat obulat commented Oct 14, 2021

Fixes

Fixes #317 by @sarayourfriend

Description

This PR replaces the recursive searching for a JSON property in the en.json file in findPath function with the code that first extracts all the full-path JSON keys ( eg. browse-page.search-form.button) and then for each of these keys saves the relevant information to the POT file.
The code for JSON manipulation (key extraction, and value extraction using the full-path JSON keys) was copied from https://github.com/coderaiser/all-object-keys and // https://github.com/coderaiser/jessy .

Previously, the recursive findPath function was finding the first available value for property specified. For example, when looking for button, it would find home.search.button and use it for any key that had button in it, even for browse-page.search-form.button. And even though recursive way of finding the property in a deeply-nested JSON was fun, it's easier to debug the current setup :)

I had some problems resolving paths and reading a json file, and also in light of #313, I replaced the js files in locales folder with mjs files. I am not sure it is correct, and would be happy if someone could improve imports/paths.

Also, I could not get the mjs tests to run :(

Testing Instructions

Try to generate the POT file using npm run i18n:generate-pot and observe that all values are saved to 'openverse.pot' file correctly. For example, now there exist two different objects for Search button: browse-page.search-form.button and home.search.button, instead of two copies of home.search.button as before.

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.

@obulat obulat added 🛠 goal: fix Bug fix 📄 aspect: text Concerns the textual material in the repository 💻 aspect: code Concerns the software code in the repository labels Oct 14, 2021
@obulat obulat requested a review from a team as a code owner October 14, 2021 07:07
@obulat obulat self-assigned this Oct 14, 2021
@dhruvkb dhruvkb added this to Needs review in Openverse PRs Oct 14, 2021
@obulat obulat removed the 📄 aspect: text Concerns the textual material in the repository label Oct 14, 2021
@zackkrida
Copy link
Member

zackkrida commented Oct 14, 2021

Is there any documentation yet on using mjs files with Nuxt 3? From Nuxt i mean, not in our repo. I'd just like to learn about it a bit more if you know of anything.

@obulat
Copy link
Contributor Author

obulat commented Oct 14, 2021

Is there any documentation yet on using mjs files with Nuxt 3? From Nuxt i mean, not in our repo. I'd just like to learn about it a bit more if you know of anything.

No, I just used whatever WebStorm advised me to do :) Let me look into it.

Intlify (the organization behind nuxt i18n) uses .mjs files for Nuxt 3: https://github.com/intlify/nuxt3#-configurations

The only thing I could find on the official documentation is the advice to 'Avoid commonjs syntax': https://v3.nuxtjs.org/getting-started/bridge#avoid-commonjs-syntax.
And the vue app inside Nuxt3 is using .mjs everywhere: https://github.com/nuxt/framework/blob/4a34c2a75be5f7bbe4c48451456fcaab274ddd67/packages/bridge/src/app.ts
Sorry for editing your comment.

@sarayourfriend
Copy link
Contributor

@obulat I think the advise to avoid commonjs syntax for Nuxt3 would only apply to anything that nuxt actually touches. Given that these are external tools that Nuxt doesn't interoperate with (as far as I understand, they're just node scripts) we don't necessarily have to do that conversion here.

If the tests ran without a problem with the new syntax it'd probably be fine to do it but considering there are other tooling considerations we can hold off converting to the mjs syntax for now.

Jest currently doesn't natively support the mjs syntax: jestjs/jest#4842

Given we could already write our unit test files with that syntax, we can just change the extension back to js and it'll be fine. If in the future we wanted to move them to mjs it'd literally just be a matter of renaming the file (as the syntax is already mjs).

Copy link
Member

@zackkrida zackkrida left a comment

Choose a reason for hiding this comment

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

Thank you for fixing this. LGTM as soon as we can, this is pretty critical. I do think we should switch to .js for now as these files aren't processed by nuxt but are run with node.

Openverse PRs automation moved this from Needs review to Reviewer approved Oct 14, 2021
@obulat obulat changed the title Fix pot file generation and convert locale scripts to mjs Fix pot file generation Oct 14, 2021
@obulat obulat merged commit 4c9c7cd into main Oct 14, 2021
Openverse PRs automation moved this from Reviewer approved to Merged! Oct 14, 2021
@obulat obulat deleted the pot_generation branch October 14, 2021 17:06
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: fix Bug fix
Projects
No open projects
Openverse PRs
  
Merged!
Development

Successfully merging this pull request may close these issues.

[Bug] POT file generation skipping path parts
3 participants