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

translation support for packages/loot-core/src/server/budget/template-nodes #3840

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AlexMuellr
Copy link

translation support for packages/loot-core/src/server/budget/template-nodes.ts

@actual-github-bot actual-github-bot bot changed the title translation support for packages/loot-core/src/server/budget/template-nodes [WIP] translation support for packages/loot-core/src/server/budget/template-nodes Nov 15, 2024
Copy link

netlify bot commented Nov 15, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 7271dbc
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/673738db9f284c0008dfdf24
😎 Deploy Preview https://deploy-preview-3840.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

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.36 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/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/resize-observer.js 18.37 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

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.31 MB → 1.33 MB (+11.03 kB) +0.82%
Changeset
File Δ Size
node_modules/react-i18next/dist/es/TransWithoutContext.js 🆕 +10.7 kB 0 B → 10.7 kB
node_modules/react/cjs/react.production.min.js 🆕 +6.75 kB 0 B → 6.75 kB
node_modules/react-i18next/dist/es/useTranslation.js 🆕 +4.39 kB 0 B → 4.39 kB
node_modules/react-i18next/dist/es/utils.js 🆕 +3.28 kB 0 B → 3.28 kB
node_modules/html-parse-stringify/dist/html-parse-stringify.module.js 🆕 +2.09 kB 0 B → 2.09 kB
node_modules/react-i18next/dist/es/context.js 🆕 +1.36 kB 0 B → 1.36 kB
node_modules/react-i18next/dist/es/withTranslation.js 🆕 +1.31 kB 0 B → 1.31 kB
node_modules/react-i18next/dist/es/useSSR.js 🆕 +1.02 kB 0 B → 1.02 kB
node_modules/react-i18next/dist/es/Trans.js 🆕 +1 kB 0 B → 1 kB
node_modules/react-i18next/dist/es/index.js 🆕 +847 B 0 B → 847 B
node_modules/react-i18next/dist/es/withSSR.js 🆕 +717 B 0 B → 717 B
node_modules/react-i18next/dist/es/unescape.js 🆕 +620 B 0 B → 620 B
node_modules/react-i18next/dist/es/defaults.js 🆕 +543 B 0 B → 543 B
node_modules/react-i18next/dist/es/I18nextProvider.js 🆕 +347 B 0 B → 347 B
node_modules/void-elements/index.js 🆕 +338 B 0 B → 338 B
node_modules/react-i18next/dist/es/Translation.js 🆕 +277 B 0 B → 277 B
node_modules/react-i18next/dist/es/initReactI18next.js 🆕 +233 B 0 B → 233 B
node_modules/react/index.js 🆕 +190 B 0 B → 190 B
node_modules/react-i18next/dist/es/i18nInstance.js 🆕 +127 B 0 B → 127 B
packages/loot-core/src/server/budget/template-notes.ts 📈 +89 B (+3.25%) 2.67 kB → 2.76 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
kcab.worker.js 1.31 MB → 1.33 MB (+11.03 kB) +0.82%

Smaller

No assets were smaller

Unchanged

No assets were unchanged

Copy link
Contributor

👋 Hi! It looks like this PR has not had any changes for a week now. Would you like someone to review this PR? If so - please remove the "[WIP]" prefix from the PR title. That will let the community know that this PR is open for a review.

@github-actions github-actions bot added the Stale label Nov 23, 2024
@AlexMuellr AlexMuellr changed the title [WIP] translation support for packages/loot-core/src/server/budget/template-nodes translation support for packages/loot-core/src/server/budget/template-nodes Nov 24, 2024
Copy link
Contributor

coderabbitai bot commented Nov 24, 2024

Walkthrough

The pull request introduces changes to the template-notes.ts file within the loot-core package. The primary modification involves enhancing the checkTemplates function to support internationalization (i18n) by integrating the useTranslation hook from the react-i18next library. This enhancement allows for the localization of error messages and success notifications. Specifically, the error message for non-existent schedules has been updated from a static string to a translatable string, facilitating adaptability for various languages. Additionally, the success message related to template validation has also been modified to utilize the translation function. An import statement for useTranslation has been added at the beginning of the file to support these changes. Overall, the modifications improve the localization capabilities of the template checking functionality.

Possibly related PRs

Suggested labels

sparkles: Merged

Suggested reviewers

  • MikesGlitch

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 (1.23.1)

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/budget/template-notes.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.


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

🧹 Outside diff range and nitpick comments (1)
packages/loot-core/src/server/budget/template-notes.ts (1)

Translation implementation needs attention

The verification reveals several issues that need to be addressed:

  • The useTranslation hook from 'react-i18next' is being used in a non-React context (server-side code)
  • The translation keys are not found in any locale files
  • The test file doesn't account for translations

Required changes:

  • Replace useTranslation with a server-side compatible translation solution
  • Add the new translation keys to the locale files
  • Update tests to handle translations
🔗 Analysis chain

Line range hint 38-69: Verify translation implementation completeness

Let's ensure all necessary parts of the translation system are in place.

Please ensure that:

  1. Translation files exist and contain the new keys
  2. All calls to checkTemplates are updated to handle the translation function parameter if you choose that approach

Let me gather more information about the translation implementation.


Let me check the actual translation files in the locale directory to verify if the new translation keys are present.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for translation key files and usage of checkTemplates
echo "Checking for translation files..."
fd -e json -e yaml "translation" -x cat {} \;

echo "Checking for checkTemplates usage..."
rg "checkTemplates\(" --type ts

Length of output: 547


Script:

#!/bin/bash
# Check the implementation of translation in related files
echo "Checking translation setup in template-notes.ts..."
rg "useTranslation|import.*i18n" packages/loot-core/src/server/budget/template-notes.ts -A 5

echo "Checking translation setup in goaltemplates.ts..."
rg "useTranslation|import.*i18n" packages/loot-core/src/server/budget/goaltemplates.ts -A 5

echo "Checking for i18n configuration..."
fd -e ts "i18n" -x cat {} \;

Length of output: 1796


Script:

#!/bin/bash
# Check translation files in locale directory
echo "Checking locale files..."
fd -e json "en.json" -x cat {} \;

# Check if the translation is used correctly in the test file
echo "Checking test implementation..."
rg -A 10 "checkTemplates" packages/loot-core/src/server/budget/template-notes.test.ts

Length of output: 975

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 670419b and 7271dbc.

📒 Files selected for processing (1)
  • packages/loot-core/src/server/budget/template-notes.ts (3 hunks)
🧰 Additional context used
🪛 GitHub Check: lint
packages/loot-core/src/server/budget/template-notes.ts

[warning] 12-12:
react-i18next import should occur before import of ../../client/state-types/notifications


[failure] 39-39:
React Hook "useTranslation" is called in function "checkTemplates" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use"

resetCategoryGoalDefsWithNoTemplates,
} from './statements';
import { Template } from './types/templates';
import { useTranslation } from 'react-i18next';
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: Incorrect usage of React hooks in server-side code

The useTranslation hook cannot be used in server-side code as it's specifically designed for React components. This will cause runtime errors since React hooks can only be used within React components or custom hooks.

Consider these alternatives for server-side translation:

  1. Use i18next directly instead of react-i18next:
-import { useTranslation } from 'react-i18next';
+import i18next from 'i18next';

 export async function checkTemplates(): Promise<Notification> {
-  const { t } = useTranslation();
+  const t = i18next.t.bind(i18next);
   // ... rest of the function
  1. Or inject the translation function as a parameter:
-import { useTranslation } from 'react-i18next';

-export async function checkTemplates(): Promise<Notification> {
+export async function checkTemplates(t: (key: string, options?: any) => string): Promise<Notification> {
-  const { t } = useTranslation();
   // ... rest of the function

Also applies to: 39-39

🧰 Tools
🪛 GitHub Check: lint

[warning] 12-12:
react-i18next import should occur before import of ../../client/state-types/notifications

@github-actions github-actions bot removed the Stale label Nov 25, 2024
@jfdoming
Copy link
Contributor

@AlexMuellr would love to merge this PR! Would you mind looking at the failing checks?

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.

2 participants