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

🐛 Fix translations failing #3830

Merged

Conversation

MikesGlitch
Copy link
Contributor

@MikesGlitch MikesGlitch commented Nov 13, 2024

Translations aren't working in the lootcore server files. It'll be because they run in a worker process and aren't setup with the json.

Related to: #3829 #3827

Copy link

netlify bot commented Nov 13, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit a3b7ed8
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/673532692bebac000832fa08
😎 Deploy Preview https://deploy-preview-3830.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.

Copy link
Contributor

github-actions bot commented Nov 13, 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
9 5.35 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
static/js/workbox-window.prod.es5.js 5.69 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/narrow.js 82.76 kB 0%
static/js/AppliedFilters.js 21.3 kB 0%
static/js/wide.js 242.64 kB 0%
static/js/ReportRouter.js 1.49 MB 0%
static/js/index.js 3.37 MB 0%

Copy link
Contributor

github-actions bot commented Nov 13, 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 → 1.31 MB (-117 B) -0.01%
Changeset
File Δ Size
packages/loot-core/src/server/main.ts 📉 -86 B (-0.13%) 62.55 kB → 62.47 kB
packages/loot-core/src/server/sheet.ts 📉 -37 B (-0.54%) 6.75 kB → 6.71 kB
packages/loot-core/src/server/budget/cleanup-template.ts 📉 -101 B (-0.76%) 12.97 kB → 12.87 kB
packages/loot-core/src/server/mutators.ts 📉 -32 B (-0.83%) 3.77 kB → 3.74 kB
packages/loot-core/src/server/budget/goaltemplates.ts 📉 -77 B (-0.98%) 7.68 kB → 7.6 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

Asset File Size % Changed
kcab.worker.js 1.32 MB → 1.31 MB (-117 B) -0.01%

Unchanged

No assets were unchanged

@MikesGlitch
Copy link
Contributor Author

MikesGlitch commented Nov 13, 2024

@awaisalee Can you update the spreadsheet with this reversion? There's some setup needed before we can get the translations working with the server files in loot-core.

@MikesGlitch MikesGlitch changed the title Fix translations failing 🐛 Fix translations failing Nov 13, 2024
@MikesGlitch MikesGlitch marked this pull request as ready for review November 13, 2024 23:00
@MikesGlitch MikesGlitch mentioned this pull request Nov 13, 2024
Copy link
Contributor

coderabbitai bot commented Nov 13, 2024

Walkthrough

The pull request introduces changes across multiple files in the loot-core package, primarily focusing on the removal of the t function from the i18next library, which was used for internationalization. This change affects how warning and error messages are constructed, replacing the translation function with direct string concatenation or template literals. Specific messages related to budget management, error handling, and template processing have been modified to use plain strings instead of translations. The overall logic and control flow of the affected functions remain unchanged, with no alterations to the parameters or return types of exported functions. The changes are cosmetic, aimed at simplifying message handling and reducing dependencies on the translation library.

Possibly related PRs

Suggested labels

::sparkles: Merged

Suggested reviewers

  • youngcw

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/loot-core/src/server/sheet.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.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 352dbbe and a3b7ed8.

📒 Files selected for processing (1)
  • packages/loot-core/src/server/sheet.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/loot-core/src/server/sheet.ts

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 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: 3

🧹 Outside diff range and nitpick comments (6)
packages/loot-core/src/server/budget/goaltemplates.ts (3)

197-199: Ensure consistent error message formatting

The error message structure using pre field for formatted text is maintained, which is good for consistency. However, consider extracting these error messages to a centralized location for better maintainability.

Consider creating an error constants file:

+// error-messages.ts
+export const TEMPLATE_ERRORS = {
+  TEMPLATE_UP_TO_DATE: 'Everything is up to date',
+  TEMPLATE_PARSING_ERROR: 'There were errors interpreting some templates:'
+};

-      message: 'There were errors interpreting some templates:',
+      message: TEMPLATE_ERRORS.TEMPLATE_PARSING_ERROR,

248-248: Type-safe template string usage

The template literal is correctly used for dynamic content. However, consider adding type safety for the catObjects.length interpolation.

Add type assertion or validation:

-    message: `Successfully applied templates to ${catObjects.length} categories`,
+    message: `Successfully applied templates to ${catObjects.length.toString()} categories`,

Line range hint 1-1: Consider removing @ts-strict-ignore

The file uses TypeScript but bypasses strict type checking. Consider addressing type safety issues to remove the @ts-strict-ignore directive.

Key areas to address:

  1. Add proper type annotations for function parameters
  2. Handle potential null/undefined values explicitly
  3. Define interfaces for template and category objects
packages/loot-core/src/server/budget/cleanup-template.ts (2)

323-335: Standardize notification message structure

The notification messages in this block and throughout the function could benefit from a more structured approach:

  1. Consider using an enum or constant for message types
  2. Create a centralized message catalog that can support future internationalization

Example structure:

enum NotificationType {
  ERROR = 'error',
  WARNING = 'warning',
  MESSAGE = 'message'
}

interface NotificationMessage {
  type: NotificationType;
  messageKey: string;
  params?: Record<string, any>;
}

const MESSAGES = {
  TEMPLATE_ERRORS: 'There were errors interpreting some templates:',
  FUNDS_NOT_AVAILABLE: 'Global: Funds not available:',
  CATEGORIES_UPDATED: 'All categories were up to date.'
} as const;

345-351: Improve template string handling

The template string construction is correct, but consider extracting the pluralization logic into a helper function for better maintainability and future internationalization support.

Example:

function pluralize(count: number, singular: string, plural: string): string {
  return count === 1 ? singular : plural;
}

const applied = `Successfully returned funds from ${num_sources} ${
  pluralize(num_sources, 'source', 'sources')
} and funded ${num_sinks} sinking ${
  pluralize(num_sinks, 'fund', 'funds')
}.`;
packages/loot-core/src/server/main.ts (1)

1096-1097: Consider adding error code for better error handling.

While removing the translation function is correct, consider adding an error code to this generic error message to help with troubleshooting and potential future internationalization.

     message:
-      'There was an internal error. Please get in touch https://actualbudget.org/contact for support.',
+      { code: 'INTERNAL_SYNC_ERROR', message: 'There was an internal error. Please get in touch https://actualbudget.org/contact for support.' },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d08be58 and 352dbbe.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/3830.md is excluded by !**/*.md
📒 Files selected for processing (5)
  • packages/loot-core/src/server/budget/cleanup-template.ts (5 hunks)
  • packages/loot-core/src/server/budget/goaltemplates.ts (2 hunks)
  • packages/loot-core/src/server/main.ts (1 hunks)
  • packages/loot-core/src/server/mutators.ts (1 hunks)
  • packages/loot-core/src/server/sheet.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/loot-core/src/server/mutators.ts
🧰 Additional context used
📓 Learnings (1)
packages/loot-core/src/server/main.ts (1)
Learnt from: matt-fidd
PR: actualbudget/actual#3581
File: packages/loot-core/src/client/actions/account.ts:180-194
Timestamp: 2024-11-10T16:45:25.627Z
Learning: In `packages/loot-core/src/client/actions/account.ts`, within the `syncAccounts` function, the batch sync request for SimpleFin accounts handles errors by returning error objects instead of throwing exceptions. Therefore, wrapping this block in a try-catch is unnecessary.
🔇 Additional comments (5)
packages/loot-core/src/server/sheet.ts (1)

135-137: Verify impact of removing translations

The removal of translations for these breadcrumb messages aligns with the PR objectives to fix translation issues. However, we should verify that these messages are intended for debugging/monitoring only and don't need to be user-facing or localized.

Also applies to: 165-167

✅ Verification successful

Breadcrumb messages are for server-side debugging only

Based on the code context, these breadcrumb messages are strictly server-side debugging/monitoring messages:

  • They are captured in the server-side code (server/sheet.ts)
  • The messages are only used with captureBreadcrumb for error tracking with category: 'server'
  • There are no exports or UI components consuming these messages
  • They are logged during spreadsheet loading/initialization process, which is a server-side operation

The removal of translations for these messages is appropriate since they are not user-facing.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if these messages are used in any UI components or user-facing contexts

# Search for any UI components that might use these messages
rg -l "loading spreadsheet|loaded spreadsheet" --type ts --type tsx

# Check if these breadcrumb messages are used anywhere else
ast-grep --pattern 'captureBreadcrumb({
  message: $_,
  category: "server"
})'

Length of output: 179


Script:

#!/bin/bash
# Search for any UI components that might use these messages, fixing the file type flags
rg -l "loading spreadsheet|loaded spreadsheet" -t typescript -t javascriptreact -t typescriptreact

# Check for breadcrumb usage in server code
rg -B2 -A2 "captureBreadcrumb.*category.*server" -t typescript -t javascript

# Look for any imports or exports of these messages that might indicate UI usage
rg "export.*loading.*spreadsheet|import.*loading.*spreadsheet" -t typescript -t javascript

Length of output: 377


Script:

#!/bin/bash
# Search for any UI components that might use these messages
rg -l "loading spreadsheet|loaded spreadsheet"

# Check for breadcrumb usage in server code
rg -B2 -A2 "captureBreadcrumb.*category.*server"

# Look for any imports or exports of these messages that might indicate UI usage
rg "export.*loading.*spreadsheet|import.*loading.*spreadsheet"

# Check the specific file for context around these breadcrumbs
cat packages/loot-core/src/server/sheet.ts

Length of output: 7241

packages/loot-core/src/server/budget/goaltemplates.ts (1)

191-191: Consider maintaining internationalization support

While removing the translation function resolves the immediate issue, this change might impact future internationalization needs. Consider implementing a centralized message handling system that can support translations when needed.

Let's check if other files still use translations:

packages/loot-core/src/server/budget/cleanup-template.ts (1)

Line range hint 1-391: Implement proper translation infrastructure

The current changes remove translations entirely, which is a temporary fix for the translation failures. Based on the PR objectives, a more appropriate solution would be to:

  1. Set up proper JSON-based translations in the worker process
  2. Implement a translation service that works within the server context
  3. Maintain internationalization support for all user-facing messages

This would provide a more maintainable and user-friendly solution than removing translations entirely.

Let's check for any translation-related configuration or implementation:

packages/loot-core/src/server/main.ts (2)

1090-1091: Template literal replacement looks good.

The replacement of the t function with a template literal maintains the same functionality while removing the translation dependency. The error message format is preserved correctly.


1090-1097: Verify error handling consistency.

The removal of translations from error messages should be consistent across all sync-related error handling. Let's verify this:

✅ Verification successful

Let me gather more information about error message patterns in the codebase to make a comprehensive verification.


Let me try one more search pattern to find error message handling patterns in the codebase.


Based on the comprehensive search results, I can now provide a final response regarding the error handling consistency.

Error handling is consistent with non-translated messages.

The codebase shows a consistent pattern of using non-translated error messages, particularly in sync and account-related functionality. The changes in the review are aligned with the broader codebase where:

  • Direct string messages are used for error handling in sync operations
  • Account-related errors use plain strings without translation wrappers
  • Internal errors consistently use direct string messages

The only exception found is in the desktop client UI component (GoCardlessExternalMsgModal.tsx) which is expected as it's a user-facing component.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for remaining translation usage in error handling

# Look for remaining translation calls in error handling code
rg "t\(['\"].*error" --type ts

# Look for similar error handling patterns
ast-grep --pattern 'message: t($$$)'

Length of output: 1386


Script:

#!/bin/bash
# Search for error message patterns in sync-related files
rg "message: ['\"].*error" --type ts packages/loot-core/src/server/sync/
rg "message: ['\"].*Error" --type ts packages/loot-core/src/server/sync/

# Search for error message patterns in account-related files
rg "message: ['\"].*error" --type ts packages/loot-core/src/server/accounts/
rg "message: ['\"].*Error" --type ts packages/loot-core/src/server/accounts/

# Look for translation usage in error messages specifically in sync and account modules
rg "message:\s*t\(['\"]" --type ts packages/loot-core/src/server/sync/
rg "message:\s*t\(['\"]" --type ts packages/loot-core/src/server/accounts/

Length of output: 469


Script:

#!/bin/bash
# Search for error message patterns more broadly
rg "message.*?['\"].*?error" -i --type ts -A 2 packages/loot-core/src/server/
rg "throw new Error\(" --type ts -A 2 packages/loot-core/src/server/

# Look for any translation usage in error contexts
rg "t\(['\"].*?(error|Error)" --type ts -A 2 packages/loot-core/src/server/

Length of output: 29200

packages/loot-core/src/server/sheet.ts Outdated Show resolved Hide resolved
packages/loot-core/src/server/sheet.ts Outdated Show resolved Hide resolved
@awaisalee
Copy link
Contributor

@awaisalee Can you update the spreadsheet with this reversion? There's some setup needed before we can get the translations working with the server files in loot-core.

@MikesGlitch I updated the spreadsheet.

@MikesGlitch MikesGlitch merged commit 58baf74 into actualbudget:master Nov 14, 2024
20 checks passed
@MikesGlitch MikesGlitch deleted the fix/translations-faililng branch November 14, 2024 08:58
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.

3 participants