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

Upload translations on builds of master #4002

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jfdoming
Copy link
Contributor

As it says on the tin. I also fixed some other issues with loading translations.

Copy link

netlify bot commented Dec 18, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit c68d90b
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/676252e781066b0008323924
😎 Deploy Preview https://deploy-preview-4002.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@jfdoming jfdoming force-pushed the jfdoming/translation-exports branch from 8dd4842 to 2e9a3df Compare December 18, 2024 04:05
Copy link
Contributor

github-actions bot commented Dec 18, 2024

Bundle Stats — desktop-client

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
10 5.53 MB → 5.53 MB (-377 B) -0.01%
Changeset
File Δ Size
src/i18n.ts 📈 +153 B (+21.16%) 723 B → 876 B
�vite/dynamic-import-helper.js 🔥 -530 B (-100%) 530 B → 0 B
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

Asset File Size % Changed
static/js/index.js 3.45 MB → 3.45 MB (-377 B) -0.01%

Unchanged

Asset File Size % Changed
static/js/useAccountPreviewTransactions.js 1.63 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/workbox-window.prod.es5.js 5.69 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/narrow.js 83.36 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/TransactionList.js 102.91 kB 0%
static/js/wide.js 161.25 kB 0%
static/js/ReportRouter.js 1.58 MB 0%

Copy link
Contributor

github-actions bot commented Dec 18, 2024

Bundle Stats — loot-core

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
1 1.32 MB 0%

Changeset

No files were changed

View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
kcab.worker.js 1.32 MB 0%

@jfdoming jfdoming marked this pull request as ready for review December 18, 2024 04:14
Copy link
Contributor

coderabbitai bot commented Dec 18, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/desktop-client/src/i18n.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-eslint-plugin".

(The package "eslint-plugin-eslint-plugin" was not found when loaded as a Node module from the directory "/packages/eslint-plugin-actual".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-eslint-plugin@latest --save-dev

The plugin "eslint-plugin-eslint-plugin" was referenced from the config file in "packages/eslint-plugin-actual/.eslintrc.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

Walkthrough

This pull request introduces changes related to internationalization (i18n) and project setup across multiple files. The modifications include adding a new GitHub Actions workflow for extracting and uploading i18n strings, updating the setup action to install Yarn globally, modifying the .gitignore file to exclude the locale/ directory, and adjusting the i18next parser configuration and i18n loading mechanism in the desktop client.

The new GitHub Actions workflow automates the extraction and uploading of i18n strings, triggered on pushes to the master branch and manually via workflow_dispatch. It includes steps for checking out the code, setting up the environment, configuring the i18n client, generating strings, and uploading them to Weblate. Additionally, the project's configuration has been updated to change the location of locale files and improve the dynamic loading of language resources.

Possibly related PRs

  • Marked files for translation #3752: This PR is related as it marks files for translation, which aligns with the addition of Yarn in the main PR for dependency management, potentially facilitating the translation process.
  • 🐛 Fix translations failing #3830: This PR addresses issues with translations failing, which could be relevant to the main PR's context of enhancing the setup for internationalization through the addition of Yarn.

Suggested labels

sparkles: Merged

Suggested reviewers

  • MikesGlitch

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (7)
.github/actions/setup/action.yml (2)

10-13: Consider using built-in yarn installation

The Node.js setup action (actions/setup-node) supports yarn installation directly through its cache parameter. Consider replacing the manual yarn installation with the built-in support:

    - name: Install node
      uses: actions/setup-node@v4
      with:
        node-version: 18.16.0
-    - name: Install yarn
-      run: npm install -g yarn
-      shell: bash
-      if: ${{ env.ACT }}
+        cache: 'yarn'

Line range hint 1-1: Add description to action metadata

The action is missing a description in its metadata, which is important for documentation and usability.

Add a description field:

name: Setup
+description: Sets up Node.js environment with yarn and caching for the project
.github/workflows/i18n-string-extract-master.yml (3)

30-35: Improve error handling and logging

The file existence check is good, but we can enhance the error handling and logging:

    - name: Upload i18n strings
      run: |
+        echo "Checking for translation file..."
        if [[ ! -f packages/desktop-client/locale/en.json ]]; then
          echo "File packages/desktop-client/locale/en.json not found. Ensure the file was generated correctly."
          exit 1
        fi
+        echo "Validating JSON format..."
+        if ! jq empty packages/desktop-client/locale/en.json 2>/dev/null; then
+          echo "Invalid JSON format in en.json"
+          exit 1
+        fi
+        echo "Uploading translations to Weblate..."
        wlc upload --author-name "Actual Budget" --author-email "[email protected]" --method add --input packages/desktop-client/locale/en.json
+        echo "Upload completed successfully"

3-8: Verify workflow triggers

The workflow is correctly triggered on master branch pushes and manual dispatch. However, consider adding:

  1. Path filters to only trigger on relevant file changes
  2. Concurrency control to prevent parallel uploads
on:
  push:
    branches:
      - master
+    paths:
+      - 'packages/desktop-client/src/**'
+      - 'packages/**/i18n/**'
  workflow_dispatch:

+concurrency:
+  group: ${{ github.workflow }}-${{ github.ref }}
+  cancel-in-progress: true

27-28: Add error handling for i18n generation

The generate:i18n command should have proper error handling.

    - name: Generate i18n strings
-      run: yarn generate:i18n
+      run: |
+        echo "Generating i18n strings..."
+        if ! yarn generate:i18n; then
+          echo "Failed to generate i18n strings"
+          exit 1
+        fi
packages/desktop-client/src/i18n.ts (2)

6-6: Consider using a relative path and supporting nested locales.

The current glob pattern has two potential issues:

  1. The absolute path /locale/*.json might be fragile across different environments.
  2. The pattern doesn't support nested locale structures (e.g., locale/en-US/common.json).

Consider this improvement:

-const languages = import.meta.glob('/locale/*.json');
+const languages = import.meta.glob('../locale/**/*.json');

11-13: Enhance error handling with available locales information

The error message could be more helpful by including a list of available locales.

-    console.error(`Unknown locale ${language}`);
-    throw new Error(`Unknown locale ${language}`);
+    const availableLocales = Object.keys(languages)
+      .map(path => path.match(/\/([^/]+)\.json$/)?.[1])
+      .filter(Boolean);
+    console.error(`Unknown locale "${language}". Available locales: ${availableLocales.join(', ')}`);
+    throw new Error(`Unknown locale "${language}". Available locales: ${availableLocales.join(', ')}`);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 94666a2 and 2e9a3df.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/4002.md is excluded by !**/*.md
📒 Files selected for processing (5)
  • .github/actions/setup/action.yml (1 hunks)
  • .github/workflows/i18n-string-extract-master.yml (1 hunks)
  • packages/desktop-client/.gitignore (1 hunks)
  • packages/desktop-client/i18next-parser.config.js (1 hunks)
  • packages/desktop-client/src/i18n.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/desktop-client/.gitignore
  • packages/desktop-client/i18next-parser.config.js
🧰 Additional context used
🪛 Biome (1.9.4)
packages/desktop-client/src/i18n.ts

[error] 10-10: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)

🪛 actionlint (1.7.4)
.github/workflows/i18n-string-extract-master.yml

15-15: description is required in metadata of "Setup" action at "/inmem/22/695974e7-23d0-4a25-91ab-0f3dd4a9e226/home/jailuser/git/.github/actions/setup/action.yml"

(action)

🔇 Additional comments (1)
packages/desktop-client/src/i18n.ts (1)

6-14: Verify Vite compatibility in build environment

The use of import.meta.glob requires Vite support. Let's ensure this is compatible with your build setup.

✅ Verification successful

Vite configuration is properly set up for import.meta.glob usage

The codebase has proper Vite support with:

  • Vite v5.2.14 installed as a dev dependency
  • A valid vite.config.mts configuration file
  • Build script configured to use Vite (vite build)
  • Proper module resolution and build configuration that supports dynamic imports

The import.meta.glob usage in i18n.ts is compatible with the build setup, though the locale directory appears to be missing. This is likely because it's generated during the build process or managed elsewhere.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if Vite is configured in the project
if [ -f "vite.config.ts" ] || [ -f "vite.config.js" ]; then
  echo "✓ Vite configuration found"
  cat vite.config.* | grep -A 5 "build"
else
  echo "⚠ No Vite configuration found"
  # Check package.json for build setup
  cat package.json | jq '.scripts.build, .dependencies["vite"], .devDependencies["vite"]'
fi

Length of output: 229


Script:

#!/bin/bash
# Let's check the package.json in the desktop-client directory since that's where the file is located
cat packages/desktop-client/package.json | jq '.scripts.build, .dependencies["vite"], .devDependencies["vite"]'

# Also check for vite config in the desktop-client directory
if [ -f "packages/desktop-client/vite.config.ts" ] || [ -f "packages/desktop-client/vite.config.js" ]; then
  echo "✓ Vite configuration found in desktop-client"
  cat packages/desktop-client/vite.config.* | grep -A 5 "build"
else
  echo "⚠ No Vite configuration found in desktop-client"
fi

# Let's also check what build tool is being used
cat packages/desktop-client/package.json | jq '.scripts, .devDependencies'

Length of output: 3380


Script:

#!/bin/bash
# Let's check for the vite config file with .ts or .js extension in the desktop-client directory
fd -t f "vite.config" packages/desktop-client

# Also check if there's any import.meta.glob usage in other files
rg "import\.meta\.glob" packages/desktop-client/src -A 2 -B 2

Length of output: 493


Script:

#!/bin/bash
# Let's examine the Vite config file content
cat packages/desktop-client/vite.config.mts

# Also check if the locale directory exists and contains JSON files
fd -t f ".json" packages/desktop-client/locale

Length of output: 5129

🧰 Tools
🪛 Biome (1.9.4)

[error] 10-10: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)

.github/workflows/i18n-string-extract-master.yml Outdated Show resolved Hide resolved
packages/desktop-client/src/i18n.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
.github/workflows/i18n-string-extract-master.yml (3)

3-7: Consider adding path filters to optimize workflow triggers

The workflow currently runs on every push to master. Consider adding path filters to run only when relevant files containing i18n strings are modified:

 on:
   push:
     branches:
       - master
+    paths:
+      - 'packages/desktop-client/src/**/*.{ts,tsx,js,jsx}'
+      - 'packages/**/i18n/**'

14-15: Add description to setup action metadata

The setup action at ./.github/actions/setup is missing a description in its metadata file. This description helps other developers understand the action's purpose.

Please add a description to .github/actions/setup/action.yml:

name: 'Setup'
description: 'Sets up the build environment with required dependencies'
🧰 Tools
🪛 actionlint (1.7.4)

15-15: description is required in metadata of "Setup" action at "/inmem/21/d90ae3f3-7cb6-41b8-b48d-8b106b5e052a/home/jailuser/git/.github/actions/setup/action.yml"

(action)


16-18: Enhance i18n client configuration robustness

The current setup could benefit from:

  1. Version pinning for wlc to ensure consistent behavior
  2. Verification of successful installation
 - name: Configure i18n client
   run: |
-    pip install wlc
+    pip install wlc==1.2.0
+    if ! command -v wlc &> /dev/null; then
+      echo "Error: wlc installation failed"
+      exit 1
+    fi
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2e9a3df and c68d90b.

📒 Files selected for processing (2)
  • .github/workflows/i18n-string-extract-master.yml (1 hunks)
  • packages/desktop-client/src/i18n.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/desktop-client/src/i18n.ts
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/i18n-string-extract-master.yml

15-15: description is required in metadata of "Setup" action at "/inmem/21/d90ae3f3-7cb6-41b8-b48d-8b106b5e052a/home/jailuser/git/.github/actions/setup/action.yml"

(action)

🔇 Additional comments (1)
.github/workflows/i18n-string-extract-master.yml (1)

28-35: Verify Weblate project configuration

Let's verify that the Weblate project and component are correctly configured.

✅ Verification successful

Weblate project and component configuration verified successfully

The Weblate integration is correctly configured:

  • Project "Actual Budget" exists with ID 5716
  • Component "actual" is properly set up with:
    • Correct source language (English)
    • i18nextv4 file format
    • Template file: en.json
    • Proper repository configuration pointing to actualbudget/translations
    • Correct file mask (*.json)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify Weblate project configuration
# Note: Using curl instead of wlc for verification to avoid authentication

# Check if the project exists
curl -s "https://hosted.weblate.org/api/projects/actualbudget/components/" | \
  jq -r '.results[] | select(.slug == "actual") | .name'

# Check component configuration
curl -s "https://hosted.weblate.org/api/components/actualbudget/actual/en/" | \
  jq -r '.name'

Length of output: 286


Script:

#!/bin/bash
# Let's verify the Weblate configuration more thoroughly
# First, check if the project exists and get its details
curl -s "https://hosted.weblate.org/api/projects/actualbudget/" | jq '.'

# Then check the components list
curl -s "https://hosted.weblate.org/api/projects/actualbudget/components/" | jq '.'

# Finally, check the specific component
curl -s "https://hosted.weblate.org/api/components/actualbudget/actual/" | jq '.'

Length of output: 15760

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant