Skip to content

add Swedish locale #4451

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

Merged
merged 4 commits into from
May 28, 2025
Merged

add Swedish locale #4451

merged 4 commits into from
May 28, 2025

Conversation

jwanglof
Copy link
Contributor

@jwanglof jwanglof commented May 21, 2025

Add Swedish locale for Swedish translation for error messages

Summary by CodeRabbit

  • New Features
    • Added support for Swedish-language error messages in validation error outputs.
    • Updated documentation to include Swedish as an available locale option.

Copy link
Contributor

coderabbitai bot commented May 21, 2025

Walkthrough

A new Swedish locale module was added for Zod validation errors, providing localized error messages. The locales index file was updated to export the Swedish locale, making it available alongside other languages. The docs were updated to list Swedish (sv) as an available locale.

Changes

File(s) Change Summary
packages/zod/src/v4/locales/sv.ts Introduced a Swedish locale module for Zod, mapping validation errors to Swedish messages.
packages/zod/src/v4/locales/index.ts Added export for the new Swedish locale (sv) to the locales index file.
packages/docs/content/error-customization.mdx Updated the list of available locales to include Swedish (sv) before Tamil (ta).

Poem

🇸🇪
Swedish joins the Zod parade,
With errors now in native shade.
From strings too short to files too big,
Every message does a Swedish jig.
So code away, don’t be shy—
Zod says “hej!” as bugs pass by!

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 7cfa8f5 and 4002485.

📒 Files selected for processing (1)
  • packages/docs/content/error-customization.mdx (1 hunks)
🔇 Additional comments (1)
packages/docs/content/error-customization.mdx (1)

371-372: Docs: Added Swedish (sv) to the locales list
Nice work! The sv — Swedish entry is correctly inserted and keeps the list in alphabetical order between sl and ta.

✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch add-locale-sv
  • Post Copyable Unit Tests in Comment

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this 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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between c2cec4e and e6ab4fc.

📒 Files selected for processing (2)
  • packages/zod/src/v4/locales/index.ts (1 hunks)
  • packages/zod/src/v4/locales/sv.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/zod/src/v4/locales/sv.ts (1)
packages/zod/src/v4/core/errors.ts (1)
  • $ZodStringFormatIssues (127-133)
🔇 Additional comments (9)
packages/zod/src/v4/locales/sv.ts (8)

1-4: Imports look good!

Clean and simple imports, bringing in just what's needed for the locale implementation.


5-10: Nice mapping for size-related errors

Good job defining the Swedish terms for different types of objects. The Sizable record will help generate more natural-sounding error messages.


12-14: Helper function looks good

Simple utility to retrieve sizing info. Clean implementation.


16-37: Type parsing looks solid

The parsedType function handles all the basic JavaScript types and provides appropriate Swedish terms. Nice handling of the special case for NaN.


72-79: Error handling for types and values looks good

The translations for invalid_type and invalid_value cases are clear and follow similar patterns to other locales.


79-85: Size validation messages look good

Nice handling of inclusive vs exclusive boundaries with the proper conditional adjustments.


105-118: Remaining error cases handled well

All the remaining validation cases are covered with clear Swedish messages.


120-126: Module exports look good

Follows the standard pattern for locale modules, exporting both the error mapper directly and as the default export's property.

packages/zod/src/v4/locales/index.ts (1)

27-27: Perfect export addition!

The Swedish locale is added in alphabetical order, exactly where it should be.

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

♻️ Duplicate comments (3)
packages/zod/src/v4/locales/sv.ts (3)

39-70: Great job on the string format dictionary

The dictionary of Swedish terms for different string formats looks pretty comprehensive! I see you implemented the suggestion to change "regex" to "reguljärt uttryck" and "template_literal" to "mall-literal". Looks good!


96-98: Error message looks good now

Nice job fixing the typo from "måsta" to "måste"! The error message reads correctly now.


86-93: Sizing fallback handling looks good

I can see you've added the fallback for issue.origin in the "too_small" case, matching the pattern used in the "too_big" case. Good consistency!

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between e6ab4fc and e2bffb4.

📒 Files selected for processing (1)
  • packages/zod/src/v4/locales/sv.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/zod/src/v4/locales/sv.ts (1)
packages/zod/src/v4/core/errors.ts (1)
  • $ZodStringFormatIssues (127-133)
🔇 Additional comments (3)
packages/zod/src/v4/locales/sv.ts (3)

5-14: Sizing utility looks solid

The sizing utility with different units for strings, files, arrays, and sets is well-implemented and uses appropriate Swedish terms.


16-37: Type parsing looks correct

The parsedType function correctly handles different JavaScript types and translates them into Swedish equivalents. The special case handling for arrays, null, and objects with constructors is well done.


1-125: Overall good Swedish locale implementation

The Swedish locale implementation is well done overall! The translations are accurate and follow the same patterns as other locales in the project. There's just that one English phrase that needs to be translated to Swedish, but otherwise this looks ready to merge.

Comment on lines 83 to 84
return `För stor(t): förväntade ${issue.origin ?? "värdet"} att ha ${adj}${issue.maximum.toString()} ${sizing.unit ?? "element"}`;
return `För stor(t): förväntat ${issue.origin ?? "värdet"} to be ${adj}${issue.maximum.toString()}`;
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

Found a bit of English text in the Swedish translation

Hey there! I noticed there's a bit of English text that snuck into the Swedish translation:

- return `För stor(t): förväntat ${issue.origin ?? "värdet"} to be ${adj}${issue.maximum.toString()}`;
+ return `För stor(t): förväntat ${issue.origin ?? "värdet"} att vara ${adj}${issue.maximum.toString()}`;

The "to be" should be "att vara" to keep everything in Swedish.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return `För stor(t): förväntade ${issue.origin ?? "värdet"} att ha ${adj}${issue.maximum.toString()} ${sizing.unit ?? "element"}`;
return `För stor(t): förväntat ${issue.origin ?? "värdet"} to be ${adj}${issue.maximum.toString()}`;
return `För stor(t): förväntade ${issue.origin ?? "värdet"} att ha ${adj}${issue.maximum.toString()} ${sizing.unit ?? "element"}`;
return `För stor(t): förväntat ${issue.origin ?? "värdet"} att vara ${adj}${issue.maximum.toString()}`;
🤖 Prompt for AI Agents
In packages/zod/src/v4/locales/sv.ts around lines 83 to 84, replace the English
phrase "to be" in the second return statement with the Swedish equivalent "att
vara" to maintain consistent Swedish translation throughout the message.

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between e2bffb4 and 7cfa8f5.

📒 Files selected for processing (1)
  • packages/zod/src/v4/locales/sv.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/zod/src/v4/locales/sv.ts (1)
packages/zod/src/v4/core/errors.ts (1)
  • $ZodStringFormatIssues (127-133)
🔇 Additional comments (3)
packages/zod/src/v4/locales/sv.ts (3)

39-70: Nice job with the comprehensive format dictionary!

The Swedish translations for all these format types look spot on! I like how you've added specific Swedish terminology for technical terms like "base64-kodad sträng" instead of just keeping them in English. The translation of "template_literal" to "mall-literal" also looks good - nice improvement from the previous version.


83-93: Smart handling of Swedish grammatical gender!

I like the use of parentheses in "stor(t)" and "lite(t)" to handle both common and neuter gender in Swedish adjectives - that's a really elegant solution that works for different contexts without having to determine the grammatical gender of each noun. Super smooth!


1-126: Overall great Swedish localization

The translations look natural and idiomatic while maintaining technical accuracy. All the error cases are handled appropriately, and the specific formatting for different data types is well thought out. The usage of "att ha" and "att innehålla" for different contexts shows great attention to detail in the Swedish language.

Comment on lines +90 to +92
if (sizing) {
return `För lite(t): förväntade ${issue.origin ?? "värdet"} att ha ${adj}${issue.minimum.toString()} ${sizing.unit}`;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Add fallback for sizing unit in the too_small case

Hey there! I noticed a small inconsistency - in the too_big case (line 83), you've got a fallback for the sizing unit with ?? "element", but this same fallback is missing here in the too_small case. Just for consistency's sake, you might want to add it:

-  return `För lite(t): förväntade ${issue.origin ?? "värdet"} att ha ${adj}${issue.minimum.toString()} ${sizing.unit}`;
+  return `För lite(t): förväntade ${issue.origin ?? "värdet"} att ha ${adj}${issue.minimum.toString()} ${sizing.unit ?? "element"}`;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (sizing) {
return `För lite(t): förväntade ${issue.origin ?? "värdet"} att ha ${adj}${issue.minimum.toString()} ${sizing.unit}`;
}
if (sizing) {
return `För lite(t): förväntade ${issue.origin ?? "värdet"} att ha ${adj}${issue.minimum.toString()} ${sizing.unit ?? "element"}`;
}
🤖 Prompt for AI Agents
In packages/zod/src/v4/locales/sv.ts around lines 90 to 92, the error message
for the too_small case uses sizing.unit without a fallback, unlike the too_big
case at line 83 which uses ?? "element" as a fallback. Add the same fallback for
sizing.unit in the too_small case by appending ?? "element" to ensure consistent
error messages.

@colinhacks
Copy link
Owner

Thank you!!

@colinhacks colinhacks merged commit 7918973 into colinhacks:main May 28, 2025
5 checks passed
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