Repository navigation
fix: improve lingui configuration - #1388
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
Caution Review failedThe pull request is closed. WalkthroughThe changes in this pull request involve the removal and modification of translation management workflows and scripts within the repository. The Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
Thank you for following the naming conventions for pull request titles! 💚🚀 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (4)
apps/marketing/package.json (2)
8-8: Approve changes to build script with considerationsThe modification to the build script aligns well with the PR objectives by integrating translation extraction and compilation into the build process. This change should help prevent merge conflicts caused by compiled translation files and ensure that the latest translations are always included in the build.
However, please consider the following impacts:
- The build time may increase due to the additional translation steps.
- CI/CD pipelines may need to be updated to ensure they have the necessary dependencies for translation tasks.
- Developers should be informed that translations are now handled during the build process, not separately.
To mitigate potential issues:
- Consider caching translation artifacts in CI/CD pipelines to improve build times.
- Update documentation to reflect this new build process for the marketing app.
- Ensure that all necessary translation dependencies are correctly specified in the project.
Compiled Translation Files Still Present in Repository
Several
.pofiles remain in the repository and.gitignoredoes not exclude them. Please remove these files from version control and update.gitignoreto prevent future commits of compiled translation files.
Files to Remove:
packages/lib/translations/de/common.popackages/lib/translations/de/marketing.popackages/lib/translations/de/web.popackages/lib/translations/en/common.popackages/lib/translations/en/marketing.popackages/lib/translations/en/web.popackages/lib/translations/fr/common.popackages/lib/translations/fr/marketing.popackages/lib/translations/fr/web.popackages/lib/translations/ro/common.popackages/lib/translations/ro/marketing.popackages/lib/translations/ro/web.poUpdate
.gitignore:/packages/lib/translations/**/*.po🔗 Analysis chain
Line range hint
1-55: Verify removal of compiled translation files from version controlWhile the changes to the build script address part of the PR objectives, it's important to ensure that compiled translation files are no longer being committed to the repository.
Let's verify this by checking for any lingering translation files that should be removed or added to .gitignore:
Please review the results of this script and ensure that:
- No compiled JS translation files are present in the locale directories.
- The .gitignore file has been updated to exclude compiled translation files.
- Any .po files that should not be in version control have been removed.
If any issues are found, please update the PR to address them.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for compiled translation files that might need to be removed or ignored # Test 1: Look for .js translation files in the locale directories echo "Checking for compiled JS translation files:" fd -e js -p 'locale/.*\.js$' # Test 2: Check if .gitignore has been updated to exclude compiled translation files echo "Checking .gitignore for translation file exclusions:" grep -E '(locale/.*\.js|.*\.po)' .gitignore # Test 3: Look for .po files that might need to be removed echo "Checking for .po files:" fd -e poLength of output: 824
.github/workflows/translations-upload.yml (1)
Line range hint
41-44: LGTM: Improved error handling for compilation step.The addition of the
idandcontinue-on-errorflags enhances the workflow's robustness. This change allows the workflow to proceed even if compilation fails, which is then used to trigger the upload of missing translations.Consider adding a comment explaining why we allow this step to fail and continue. This would improve the workflow's maintainability.
🧰 Tools
🪛 actionlint
26-26: description is required in metadata of "Setup node and cache node_modules" action at "/cache/22/14bd4d0c-589d-41e8-9ea7-a24bb36527ee/home/jailuser/git/.github/actions/node-install/action.yml"
(action)
packages/lib/utils/i18n.ts (1)
13-13: Consider adding error handling for dynamic import.While the dynamic import is more flexible, it might benefit from error handling to gracefully manage cases where the translation file is missing or fails to load.
Consider wrapping the import in a try-catch block:
- const { messages } = await import(`../translations/${locale}/${context}.${extension}`); + try { + const { messages } = await import(`../translations/${locale}/${context}.${extension}`); + i18nInstance.loadAndActivate({ locale, messages }); + } catch (error) { + console.error(`Failed to load translations for ${locale}/${context}.${extension}:`, error); + // Fallback behavior, e.g., load default language or show an error message + } - i18nInstance.loadAndActivate({ locale, messages });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (17)
- .github/workflows/translations-extract.yml (0 hunks)
- .github/workflows/translations-upload.yml (1 hunks)
- .husky/pre-commit (0 hunks)
- apps/marketing/package.json (1 hunks)
- apps/web/package.json (1 hunks)
- packages/lib/client-only/providers/i18n.server.tsx (1 hunks)
- packages/lib/translations/.gitignore (1 hunks)
- packages/lib/translations/de/marketing.js (0 hunks)
- packages/lib/translations/de/web.js (0 hunks)
- packages/lib/translations/en/marketing.js (0 hunks)
- packages/lib/translations/en/web.js (0 hunks)
- packages/lib/translations/fr/marketing.js (0 hunks)
- packages/lib/translations/fr/web.js (0 hunks)
- packages/lib/translations/ro/marketing.js (0 hunks)
- packages/lib/translations/ro/web.js (0 hunks)
- packages/lib/utils/i18n.ts (1 hunks)
- turbo.json (2 hunks)
💤 Files with no reviewable changes (10)
- .github/workflows/translations-extract.yml
- .husky/pre-commit
- packages/lib/translations/de/marketing.js
- packages/lib/translations/de/web.js
- packages/lib/translations/en/marketing.js
- packages/lib/translations/en/web.js
- packages/lib/translations/fr/marketing.js
- packages/lib/translations/fr/web.js
- packages/lib/translations/ro/marketing.js
- packages/lib/translations/ro/web.js
✅ Files skipped from review due to trivial changes (1)
- packages/lib/translations/.gitignore
🧰 Additional context used
🔇 Additional comments (12)
.github/workflows/translations-upload.yml (2)
28-29: LGTM: New step for extracting translations.This new step aligns with the PR objective of modifying the workflow for translation extraction. The command
npm run translate:extractis clear and concise, focusing solely on the extraction process.
Line range hint
1-62: Summary: Workflow improvements align well with PR objectives.The changes to this workflow file effectively address the PR's goals:
- Extraction and compilation steps are now separate, allowing for more granular control.
- The compilation step can now fail without stopping the entire workflow, enabling the upload of missing translations when needed.
- These changes should help reduce merge conflicts related to compiled translation files.
Overall, these modifications improve the flexibility and robustness of the translation management process.
🧰 Tools
🪛 actionlint
26-26: description is required in metadata of "Setup node and cache node_modules" action at "/cache/22/14bd4d0c-589d-41e8-9ea7-a24bb36527ee/home/jailuser/git/.github/actions/node-install/action.yml"
(action)
packages/lib/client-only/providers/i18n.server.tsx (4)
18-18: Approve dynamic file extension determinationThe use of different file extensions for development and production environments is a good practice. It allows for easier debugging in development (using
.pofiles) while optimizing for performance in production (using compiled.jsfiles).
21-21: Approve updated import statementThe new import statement correctly uses the dynamically determined
extensionandcontextvariables. This change supports the PR objective of improving the translation configuration and should reduce merge conflicts by eliminating the need to commit compiled translation files.
18-21: Verify build process compatibilityThe changes to the
loadCatalogfunction align well with the PR objectives of improving the translation configuration and reducing merge conflicts. The dynamic file extension and context determination should make the code more flexible and environment-aware.To ensure full compatibility:
- Verify that the build process generates the necessary
.jsfiles for production use.- Confirm that the
IS_APP_WEBconstant is consistently used across the codebase for context determination.- Test the translation loading in both development and production environments to ensure smooth functionality.
Let's check the build scripts for translation compilation:
#!/bin/bash # Description: Check build scripts for translation compilation # Test: Search for translation-related build commands in package.json files rg --type json 'build.*lingui' packages/*/package.json
19-19: Verify the impact of context determinationThe introduction of the
contextvariable based onIS_APP_WEBaligns with the PR objective of improving the configuration. However, we should ensure that this change is consistent across the codebase.Let's verify the usage of
IS_APP_WEB:✅ Verification successful
Translation scripts are properly defined
The "translate:extract" and "translate:compile" scripts are present in both
turbo.jsonand the relevantpackage.jsonfiles, ensuring they are correctly set up for the build process.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the existence of translation scripts in Turborepo configuration # Test: Search for translate:extract and translate:compile in turbo.json files echo "Searching for translation scripts in turbo.json files:" fd turbo.json --exec grep -H -E "translate:(extract|compile)" # Test: Search for translate:extract and translate:compile in package.json files echo "Searching for translation scripts in package.json files:" fd package.json --exec grep -H -E '"translate:(extract|compile)"'Length of output: 822
packages/lib/utils/i18n.ts (2)
10-13: Improved flexibility in translation file handling.The changes to the
dynamicActivatefunction enhance the flexibility of handling translation files:
- The
extensionvariable allows for different file types in development (.po) and production (.js) environments.- The
contextvariable separates translations for web and marketing, aligning with the application structure.- The dynamic import path construction supports the PR's objective of modifying the translation workflow.
These improvements should help reduce merge conflicts and streamline the translation process as intended.
Line range hint
1-114: Summary: Changes align well with PR objectivesThe modifications to the
dynamicActivatefunction in this file support the PR's goal of improving the lingui configuration and reducing merge conflicts. By dynamically determining the file extension and context, the changes allow for a more flexible handling of translation files during different stages of development and deployment.These changes, combined with the removal of compiled translation files from the repository (as mentioned in the PR objectives), should help streamline the translation workflow and reduce the likelihood of merge conflicts.
To ensure the full success of these changes:
- Verify that the build process correctly generates both .po and .js translation files.
- Consider implementing error handling for the dynamic import to gracefully manage potential issues.
- Update any related documentation or team guidelines to reflect the new translation file handling process.
turbo.json (2)
37-39: LGTM: Addition oftranslate:extracttask aligns with PR objectives.The new
translate:extracttask withcache: falseis a good addition that aligns with the PR objectives. This configuration ensures that translation extraction will always run during the build process, without relying on cached results. This change supports the goal of moving translation extraction out of the commit process and into the build process, which should help reduce merge conflicts related to compiled translation files.
Line range hint
1-139: Verify integration with existing pipeline tasks.The addition of the
translate:extracttask looks good. To ensure smooth integration with the existing build process, please verify:
- If any existing tasks (e.g.,
build,prebuild) need to depend ontranslate:extract.- If
translate:compileshould depend ontranslate:extract.- Whether any changes are needed in the
globalDependenciesorglobalEnvsections to support the new translation extraction process.This verification will help ensure that the new translation workflow integrates seamlessly with the existing build pipeline.
| const extension = process.env.NODE_ENV === 'development' ? 'po' : 'js'; | ||
| const context = IS_APP_WEB ? 'web' : 'marketing'; | ||
|
|
||
| const { messages } = await import(`../translations/${locale}/${context}.${extension}`); |
There was a problem hiding this comment.
💡 Codebase verification
Missing .js Translation Files in Production
The build process does not generate .js translation files as expected for production.
- No
.jsfiles found inpackages/lib/translations.
🔗 Analysis chain
Verify the existence of both .po and .js translation files.
The new implementation assumes the existence of both .po and .js translation files. It's crucial to ensure that the build process generates both file types as expected.
Let's verify the existence of these files:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for the existence of .po and .js translation files
# Test: Check for .po files in development context
echo "Checking for .po files:"
fd -e po . packages/lib/translations
# Test: Check for .js files in production context
echo "Checking for .js files:"
fd -e js . packages/lib/translations
# Note: If either command returns no results, it might indicate a potential issue with the translation file generation process.
Length of output: 659
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (1)
docker/Dockerfile (1)
Incomplete Lingui Workflow Implementation
The
lingui.config.jsfile is referenced in thedocker/Dockerfilebut is not found in the repository. Please ensure that the configuration file is added to the appropriate directory or generated during the build process to fully implement the Lingui workflow.
- Verify the presence of
lingui.config.jsin the repository.- Ensure that the build process correctly generates or includes
lingui.config.jsif it’s intended to be created dynamically.🔗 Analysis chain
Line range hint
1-124: Verify complete implementation of new lingui workflowThe addition of the
lingui.config.jsfile to the installer stage is a good start. However, to ensure that the new lingui workflow is fully implemented, it might be worth verifying if any other stages or commands in the Dockerfile need to be updated.For example:
- Are there any lingui-related commands that need to be added to the build process?
- Does the runner stage need any additional files or configurations related to lingui?
To help with this verification, you can run the following script:
This script will help identify any existing lingui-related commands in the Dockerfile and npm scripts in package.json files, which can guide further modifications if needed.
To address the issues encountered, please run the following script to accurately search for lingui-related commands and handle any malformed
package.jsonfiles:shell
#!/bin/bashDescription: Improved script to check for lingui-related commands and handle malformed package.json files
Search for lingui-related commands in the Dockerfile
echo "Searching for lingui-related commands in Dockerfile:"
rg 'lingui|translation' Dockerfileecho ""
Find all package.json files
echo "Finding all package.json files:"
PACKAGE_JSON_FILES=$(fd package.json)
echo "$PACKAGE_JSON_FILES"
echo ""Iterate over each package.json file to check for lingui-related scripts
echo "Checking for lingui-related npm scripts:"
for file in $PACKAGE_JSON_FILES; do
echo "Inspecting $file:"
jq -e '.scripts | to_entries[] | select(.key | contains("lingui") or contains("translation")) | "(.key): (.value)"' "$file" 2>/dev/null
if [ $? -ne 0 ]; then
echo " Error: Malformed JSON in $file"
fi
echo ""
done
To further verify the complete implementation of the lingui workflow and ensure all related configurations are correctly set up, please run the following script:
This script performs the following actions:
- Validates all
package.jsonfiles to ensure there are no malformed JSON files that could interfere with script execution.- Searches for lingui-related dependencies in both
dependenciesanddevDependenciessections of eachpackage.json.- Checks for the existence of
lingui.config.jsin the repository root, which is essential for the lingui workflow.- Looks for any lingui-related commands or configurations in the
Dockerfileand other configuration files (e.g.,*.config.js).By running this script, you will obtain detailed information about the presence and correct setup of the lingui workflow within the codebase.
To address the issues encountered in the previous script, please run the following revised script. This script corrects the search paths and ensures comprehensive verification of the lingui workflow implementation:
Explanation of the Revised Script:
Validation of
package.jsonFiles:
- Ensures all
package.jsonfiles are well-formed JSON.Search for Lingui-Related Dependencies:
- Looks for any dependencies or devDependencies that include "lingui" in their names across all
package.jsonfiles.Check for
lingui.config.js:
- Specifies potential locations where
lingui.config.jsmight reside, such as the repository root,apps/web/, orpackages/ui/.- Reports the presence or absence of the configuration file in each location.
Search for Lingui-Related Commands in Configuration Files:
- Correctly targets
docker/Dockerfileto search for lingui-related commands.- Recursively searches all
.config.jsfiles for any mentions of "lingui" or "translation".By running this revised script, you will obtain more accurate and comprehensive information regarding the implementation and configuration of the lingui workflow within the codebase. This will help in determining whether the initial review comment's concerns are fully addressed or if further modifications are necessary.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for lingui-related commands and configurations in the Dockerfile # Search for lingui-related commands in the Dockerfile echo "Searching for lingui-related commands:" rg --type dockerfile 'lingui|translation' docker/Dockerfile # Check if there are any lingui-related npm scripts in package.json files echo "Checking for lingui-related npm scripts:" fd package.json | xargs jq -r '.scripts | to_entries[] | select(.key | contains("lingui") or contains("translation")) | "\(.key): \(.value)"'Length of output: 489
Script:
#Length of output: 0
Script:
# #!/bin/bash # Description: Comprehensive script to verify lingui workflow implementation echo "### Validating all package.json files ###" # Find and validate all package.json files PACKAGE_JSON_FILES=$(fd package.json) for file in $PACKAGE_JSON_FILES; do echo "Validating $file:" if jq empty "$file" 2>/dev/null; then echo " - Valid JSON." else echo " - Error: Malformed JSON in $file" fi done echo "" echo "### Searching for lingui-related dependencies in package.json ###" # Search for lingui dependencies for file in $PACKAGE_JSON_FILES; do echo "Checking $file for lingui dependencies:" jq -r '.dependencies, .devDependencies | to_entries[] | select(.key | contains("lingui")) | "\(.key): \(.value)"' "$file" 2>/dev/null || echo " - No lingui dependencies found or unable to parse." done echo "" echo "### Checking for lingui.config.js ###" # Check for the existence of lingui.config.js if [ -f "lingui.config.js" ]; then echo "lingui.config.js found in the repository root." else echo "lingui.config.js not found in the repository root." fi echo "" echo "### Searching for lingui-related commands in Dockerfile and other configuration files ###" # Search for lingui-related commands in Dockerfile and other relevant files rg 'lingui|translation' Dockerfile rg 'lingui|translation' *.config.jsLength of output: 11592
Script:
# #!/bin/bash # Description: Revised comprehensive script to verify lingui workflow implementation with corrected paths echo "### Validating all package.json files ###" # Find and validate all package.json files PACKAGE_JSON_FILES=$(fd package.json) for file in $PACKAGE_JSON_FILES; do echo "Validating $file:" if jq empty "$file" 2>/dev/null; then echo " - Valid JSON." else echo " - Error: Malformed JSON in $file" fi done echo "" echo "### Searching for lingui-related dependencies in package.json ###" # Search for lingui dependencies for file in $PACKAGE_JSON_FILES; do echo "Checking $file for lingui dependencies:" jq -r '.dependencies, .devDependencies | to_entries[] | select(.key | contains("lingui")) | "\(.key): \(.value)"' "$file" 2>/dev/null || echo " - No lingui dependencies found or unable to parse." done echo "" echo "### Checking for lingui.config.js ###" # Define potential locations for lingui.config.js POTENTIAL_CONFIG_LOCATIONS=("lingui.config.js" "apps/web/lingui.config.js" "packages/ui/lingui.config.js") for config_path in "${POTENTIAL_CONFIG_LOCATIONS[@]}"; do if [ -f "$config_path" ]; then echo "$config_path found." else echo "$config_path not found." fi done echo "" echo "### Searching for lingui-related commands in Dockerfile and other configuration files ###" # Search for lingui-related commands in the correct Dockerfile path echo "Searching in docker/Dockerfile:" rg 'lingui|translation' docker/Dockerfile || echo " - No lingui-related commands found in docker/Dockerfile." echo "" # Recursively search for lingui-related commands in all .config.js files echo "Searching in all .config.js files:" rg 'lingui|translation' --glob '*.config.js' || echo " - No lingui-related commands found in .config.js files."Length of output: 12483
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- docker/Dockerfile (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
docker/Dockerfile (1)
61-62: LGTM: Appropriate addition of lingui configurationThe addition of these lines to copy the
lingui.config.jsfile from the builder stage to the installer stage is a good change. This ensures that the lingui configuration is available during the build process, which is crucial for the new workflow of handling translations as described in the PR objectives.This change aligns well with the goal of improving the lingui configuration and modifying the translation extraction and compilation process.
Description
Currently merge conflicts arise due to the compiled JS and PO translation files.
This PR is a rework on how we handle extracting and compiling translations to streamline PRs and merging branches.
Changes Made
Summary by CodeRabbit
.gitignorefile to manage ignored files in translations.