-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
add Swedish locale #4451
Conversation
WalkthroughA 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 ( Changes
Poem
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit 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. Note ⚡️ Faster reviews with cachingCodeRabbit 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 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🔇 Additional comments (1)
✨ Finishing Touches🧪 Generate Unit Tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
📒 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 errorsGood 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 goodSimple utility to retrieve sizing info. Clean implementation.
16-37
: Type parsing looks solidThe
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 goodThe translations for invalid_type and invalid_value cases are clear and follow similar patterns to other locales.
79-85
: Size validation messages look goodNice handling of inclusive vs exclusive boundaries with the proper conditional adjustments.
105-118
: Remaining error cases handled wellAll the remaining validation cases are covered with clear Swedish messages.
120-126
: Module exports look goodFollows 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.
There was a problem hiding this 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 dictionaryThe 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 nowNice job fixing the typo from "måsta" to "måste"! The error message reads correctly now.
86-93
: Sizing fallback handling looks goodI 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
📒 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 solidThe sizing utility with different units for strings, files, arrays, and sets is well-implemented and uses appropriate Swedish terms.
16-37
: Type parsing looks correctThe 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 implementationThe 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.
packages/zod/src/v4/locales/sv.ts
Outdated
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()}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
There was a problem hiding this 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
📒 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 localizationThe 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.
if (sizing) { | ||
return `För lite(t): förväntade ${issue.origin ?? "värdet"} att ha ${adj}${issue.minimum.toString()} ${sizing.unit}`; | ||
} |
There was a problem hiding this comment.
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.
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.
Thank you!! |
Add Swedish locale for Swedish translation for error messages
Summary by CodeRabbit