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

I18n fix #4294

Merged
merged 3 commits into from
Sep 28, 2023
Merged

I18n fix #4294

merged 3 commits into from
Sep 28, 2023

Conversation

BoDonkey
Copy link
Contributor

Summary

Summarize the changes briefly, including which issue/ticket this resolves. If it closes an existing Github issue, include "Closes #[issue number]"
Currently, if an i18n folder has any files inside besides JSON translation string files, it will break the build process. For example, this can occur if a user creates a new JSON file using the Mac OS finder. The finder will leave behind a .DS_Store file. This PR fixes this issue and closes PRO-4701.

What are the specific steps to test this change?

For example:

  1. Run the website and log in as an admin
  2. Open a piece manager modal and select several pieces
  3. Click the "Archive" button on the top left of the manager and confirm that it should proceed
  4. Check that all pieces have been archived properly
  1. In testbed (or any project) create two files - modules/<some-module>/i18n/test.txt and modules/<some-module>/i18n/testNs/test.txt. The first will test without namespace, the second with. Testbed already has the structure in place for the topic module.
  2. Project build should succeed with npm run dev

What kind of change does this PR introduce?

(Check at least one)

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • Build-related changes
  • Other

Make sure the PR fulfills these requirements:

  • It includes a) the existing issue ID being resolved, b) a convincing reason for adding this feature, or c) a clear description of the bug it resolves
  • The changelog is updated
  • Related documentation has been updated
  • Related tests have been updated

If adding a new feature without an already open issue, it's best to open a feature request issue first and wait for approval before working on it.

Other information:

@BoDonkey BoDonkey requested a review from boutell September 21, 2023 16:02
@linear
Copy link

linear bot commented Sep 21, 2023

PRO-4701 Ignore dotfiles in `i18n` folder during build because Apostrophe breaks for Mac users who try to use the finder to access folders.

During a project build, an error will occur if there is an i18n folder in the project that contains a dotfile. This can easily occur on Mac OS machines as the finder will track folders using a .DS_Store file that it adds if you open a folder in the finder.

If there is any file in there, it will cause an error.

@@ -523,7 +523,15 @@ module.exports = {
self.namespaces[ns].browser = self.namespaces[ns].browser ||
(metadata[ns] && metadata[ns].browser);
const namespaceDir = path.join(localizationsDir, ns);
if (!fs.statSync(namespaceDir).isDirectory()) {
// Handle files in the namespace that aren't JSON files
Copy link
Member

Choose a reason for hiding this comment

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

Checking to make sure it's a directory makes sense, but that seems unconnected to the stated purpose in the comment, except in a limited sense.

Copy link
Contributor Author

@BoDonkey BoDonkey Sep 26, 2023

Choose a reason for hiding this comment

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

Currently, the conditional at the top of for loop checks if the current item is a JSON file and if it is skips it because it has been handled by the addDefaultResourcesForModule() method. At this point, the method is assuming that everything else is a directory, which isn't always true. Therefore, we need to a check to jump to the next item in the loop if it is a file (and since we already checked for JSON files, it would be a non-JSON file.. This would include .DS_Store that is breaking the build. I'll change the comment.
But, maybe I'm not understanding your concern.

for (const localizationFile of fs.readdirSync(namespaceDir)) {
if (!localizationFile.endsWith('.json')) {
// A JSON file for the default namespace, already handled
Copy link
Member

Choose a reason for hiding this comment

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

How would a non-json file in a namespace folder be a JSON file for the default namespace? This check makes sense but the comment has me wondering if things were transposed somehow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah - I think that copilot "helpfully" wrote that comment and I wasn't careful enough in reading it. That conditional makes sure that within the namespace folder only JSON files are being parsed. I'll change the comment.

@BoDonkey BoDonkey requested a review from boutell September 26, 2023 18:30
@BoDonkey BoDonkey merged commit 387ff30 into main Sep 28, 2023
8 checks passed
@BoDonkey BoDonkey deleted the i18n-fix branch September 28, 2023 14:55
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.

2 participants