Skip to content

fix(dashboard): enforce locale-specific plural forms in translations#13268

Open
radeknapora wants to merge 19 commits intomedusajs:developfrom
radeknapora:fix(dashboard)/pluralization-schema-pl
Open

fix(dashboard): enforce locale-specific plural forms in translations#13268
radeknapora wants to merge 19 commits intomedusajs:developfrom
radeknapora:fix(dashboard)/pluralization-schema-pl

Conversation

@radeknapora
Copy link
Copy Markdown
Contributor

@radeknapora radeknapora commented Aug 21, 2025

Summary

What — What changes are introduced in this PR?

This PR adds locale-aware pluralization validation to the i18n system, ensuring each language uses only its grammatically correct plural forms (zero, one, two, few, many, other) according to CLDR/i18next rules.

Why — Why are these changes relevant or necessary?

Different languages require different plural forms (English needs 2, Polish needs 4, Arabic needs 6, Chinese needs 1). Without validation, translations can have:

  • Missing required forms (e.g., Polish without few/many)
  • Unnecessary dummy keys (e.g., English with unused few/many)
  • Incorrect UI text like "2 items" instead of "2 przedmioty" in Polish

How — How have these changes been implemented?

  1. i18n Tooling:
    • Updated scripts/i18n/generate-schema.js to detect plural base keys and auto-include all 6 CLDR forms (zero|one|two|few|many|other) as optional
    • Enhanced scripts/i18n/validate-translation.js to validate translations against both the schema and per-locale plural requirements using plural-config.json
    • Added src/i18n/plural-config.json mapping locales to their required plural forms
  2. Schema:
    • Regenerated translations/$schema.json to allow all plural forms for relevant keys and adjusted required lists (removing hardcoded one/other requirements)
  3. Tests:
    • Revised translations/__tests__/validate-translations.spec.ts to check required vs extra keys and assert plural forms for en match plural-config
  4. Translations:
    • Updated translations/en.json to include explicit plural key wrongQuantity_one under orders.fulfillment.error

Testing — How have these changes been tested, or how can the reviewer test the feature?

  • Try adding incorrect plural forms to any language file (e.g., add items_few to en.json) — validation should fail
  • Try removing required plural forms from Polish translations — validation should fail
  • Verify schema generation: should create all 6 plural forms as optional

Examples

plural-config.json structure

{
  "en": ["one", "other"],
  "pl": ["one", "few", "many", "other"],
  ...
}

Validation behavior

//  Valid English translation
{
  "items_one": "{{count}} item",
  "items_other": "{{count}} items"
}

//  Invalid - English doesn't use 'few'
{
  "items_one": "{{count}} item",
  "items_few": "{{count}} items",  // Validation fails: extra key
  "items_other": "{{count}} items"
}

// Valid Polish translation
{
  "items_one": "{{count}} przedmiot",
  "items_few": "{{count}} przedmioty",
  "items_many": "{{count}} przedmiotów",
  "items_other": "{{count}} przedmiotu"
}

// Invalid - Polish requires 'few' and 'many'
{
  "items_one": "{{count}} przedmiot",
  "items_other": "{{count}} przedmiotów"  // Validation fails: missing 'few' and 'many'
}

Checklist

Please ensure the following before requesting a review:

  • I have added a changeset for this PR
    • Every non-breaking change should be marked as a patch
    • To add a changeset, run yarn changeset and follow the prompts
  • The changes are covered by relevant tests
  • I have verified the code works as intended locally
  • I have linked the related issue(s) if applicable

Additional Context

References:


Note

Adds locale-aware pluralization validation and schema support, with tests and minor English translation adjustments.

  • i18n Tooling:
    • Update scripts/i18n/generate-schema.js to detect plural base keys and expose all forms (_zero|_one|_two|_few|_many|_other).
    • Enhance scripts/i18n/validate-translation.js to validate per-locale plural requirements via src/i18n/plural-config.json and Ajv schema.
  • Schema:
    • Regenerate src/i18n/translations/$schema.json to include all plural forms for detected keys and relax hardcoded required for plural pairs.
  • Tests:
    • Revise src/i18n/translations/__tests__/validate-translations.spec.ts to assert required vs extra keys and enforce English plural forms per plural-config.json.
  • Translations:
    • Add orders.fulfillment.error.wrongQuantity_one to en.json.
  • Changeset:
    • Add patch entry describing plural-form enforcement.

Written by Cursor Bugbot for commit b65eb07. This will update automatically on new commits. Configure here.

…anguages

Extended the i18n translation schema to support 'few' and 'many' pluralization forms alongside existing 'one' and 'other' forms. This change improves support for languages with more complex pluralization rules.
@radeknapora radeknapora requested a review from a team as a code owner August 21, 2025 10:37
@vercel
Copy link
Copy Markdown

vercel bot commented Aug 21, 2025

@radeknapora is attempting to deploy a commit to the medusajs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor

@willbouch willbouch left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution! I did not know that about slavic languages so definitely learned something today 😅. For the "required or not" question, I do not believe we have something in place to add conditions but I think it could be a good idea. So, I will leave the ball into your court if that is something you want to work on. You can tag me as a reviewer of that PR if you decide to do it! For now though, it is fine to push it like this so we at least get rid of the stripping out issue

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Aug 22, 2025

🦋 Changeset detected

Latest commit: b65eb07

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 74 packages
Name Type
@medusajs/dashboard Patch
@medusajs/admin-bundler Patch
@medusajs/medusa Patch
@medusajs/test-utils Patch
@medusajs/medusa-oas-cli Patch
integration-tests-http Patch
@medusajs/analytics Patch
@medusajs/api-key Patch
@medusajs/auth Patch
@medusajs/caching Patch
@medusajs/cart Patch
@medusajs/currency Patch
@medusajs/customer Patch
@medusajs/file Patch
@medusajs/fulfillment Patch
@medusajs/index Patch
@medusajs/inventory Patch
@medusajs/link-modules Patch
@medusajs/locking Patch
@medusajs/notification Patch
@medusajs/order Patch
@medusajs/payment Patch
@medusajs/pricing Patch
@medusajs/product Patch
@medusajs/promotion Patch
@medusajs/region Patch
@medusajs/sales-channel Patch
@medusajs/settings Patch
@medusajs/stock-location Patch
@medusajs/store Patch
@medusajs/tax Patch
@medusajs/user Patch
@medusajs/workflow-engine-inmemory Patch
@medusajs/workflow-engine-redis Patch
@medusajs/draft-order Patch
@medusajs/oas-github-ci Patch
@medusajs/cache-inmemory Patch
@medusajs/cache-redis Patch
@medusajs/event-bus-local Patch
@medusajs/event-bus-redis Patch
@medusajs/analytics-local Patch
@medusajs/analytics-posthog Patch
@medusajs/auth-emailpass Patch
@medusajs/auth-github Patch
@medusajs/auth-google Patch
@medusajs/caching-redis Patch
@medusajs/file-local Patch
@medusajs/file-s3 Patch
@medusajs/fulfillment-manual Patch
@medusajs/locking-postgres Patch
@medusajs/locking-redis Patch
@medusajs/notification-local Patch
@medusajs/notification-sendgrid Patch
@medusajs/payment-stripe Patch
@medusajs/core-flows Patch
@medusajs/framework Patch
@medusajs/js-sdk Patch
@medusajs/modules-sdk Patch
@medusajs/orchestration Patch
@medusajs/types Patch
@medusajs/utils Patch
@medusajs/workflows-sdk Patch
@medusajs/cli Patch
@medusajs/deps Patch
@medusajs/telemetry Patch
@medusajs/admin-sdk Patch
@medusajs/admin-shared Patch
@medusajs/admin-vite-plugin Patch
@medusajs/icons Patch
@medusajs/toolbox Patch
@medusajs/ui-preset Patch
create-medusa-app Patch
medusa-dev-cli Patch
@medusajs/ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@radeknapora
Copy link
Copy Markdown
Contributor Author

Sounds good 👍

Then let’s keep it like this for now to avoid the stripping issue. I’ll look into creating a follow-up PR that introduces conditional requirements for plural forms when I get a chance. I’ll make sure to tag you as a reviewer on that one.

@willbouch
Copy link
Copy Markdown
Contributor

willbouch commented Aug 22, 2025

Sounds good 👍

Then let’s keep it like this for now to avoid the stripping issue. I’ll look into creating a follow-up PR that introduces conditional requirements for plural forms when I get a chance. I’ll make sure to tag you as a reviewer on that one.

if you can also add a changeset before merging! Sorry I forgot

@radeknapora
Copy link
Copy Markdown
Contributor Author

Sure, I’ve already added a changeset 👍 thanks for the reminder!

@radeknapora
Copy link
Copy Markdown
Contributor Author

Updated the changeset to follow the convention, is it okay now?

Copy link
Copy Markdown
Contributor

@adrien2p adrien2p left a comment

Choose a reason for hiding this comment

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

thank you for your contribution 💪 @olivermrbl how do we want to handle this one?

@willbouch
Copy link
Copy Markdown
Contributor

Bump @olivermrbl

@willbouch
Copy link
Copy Markdown
Contributor

@radeknapora There seems to still be issues with unit tests at the moment. Any chance you can take a look at this?

@willbouch
Copy link
Copy Markdown
Contributor

Hi @radeknapora :) Are you able to take a look at the unit tests for this PR?

@radeknapora
Copy link
Copy Markdown
Contributor Author

Hi @willbouch sorry I missed your earlier message. I'm currently on holiday and don’t have time to look into the unit tests right now. I’ll take a look at this PR once I’m back.

cursor[bot]

This comment was marked as outdated.

PROBLEM WE'RE TRYING TO SOLVE

Current i18n validation requires ALL languages to have identical keys. This breaks
when different languages need different plural forms:

- English needs: _one, _other (2 forms)
- Polish needs: _one, _few, _many, _other (4 forms)
- Arabic needs: _zero, _one, _two, _few, _many, _other (6 forms)

When Polish adds _few/_many, tests fail because English doesn't have them.
This violates i18next/CLDR best practices.

PROPOSED SOLUTION (WIP)

This is a working but incomplete implementation of language-aware validation:

What Works:
- Schema merges keys from ALL translation files (not just English)
- Plural forms marked as optional in schema
- Each language validated against its CLDR plural requirements
- Tests pass with warnings for incomplete translations

What's Missing:
- NO IDE WARNINGS - VS Code won't warn about missing _few in Polish files
  because they're optional in the shared schema
- Could generate per-language schemas ($schema-pl.json, etc.) but requires
  maintaining 29+ schema files

CHANGES

New:
- scripts/i18n/plural-rules.js - CLDR plural rules for all 29 languages

Modified:
- scripts/i18n/generate-schema.js - Merges all languages, marks plurals optional
- src/i18n/translations/__tests__/validate-translations.spec.ts - Language-aware validation
- src/i18n/translations/$schema.json - Regenerated

QUESTIONS FOR TEAM

1. Is this approach acceptable? (Tests pass but with warnings)
2. Should we generate per-language schemas for IDE support?
3. Better ideas for validating language-specific plural forms?

Note: This unblocks Polish translations but needs team discussion on the
best long-term solution.
cursor[bot]

This comment was marked as outdated.

@radeknapora
Copy link
Copy Markdown
Contributor Author

radeknapora commented Oct 8, 2025

WIP: Proposed Solution for CLDR-Compliant i18n Pluralization

Status: Working but incomplete - seeking team feedback

Problem

Current i18n validation requires ALL languages to have identical keys. This doesn't work because different languages have different plural rules:

  • English: 2 forms (_one, _other)
  • Polish: 4 forms (_one, _few, _many, _other)
  • Arabic: 6 forms (_zero, _one, _two, _few, _many, _other)
  • Chinese: 1 form (_other only)

When Polish translations add _few and _many (required by CLDR grammar rules), tests fail because English doesn't have these keys. This violates i18next and Unicode CLDR best practices.

Proposed Solution

This PR implements language-aware validation based on CLDR standards.

What works

  1. Schema merges ALL languages - Generated from all translation files, not just English
  2. Plural forms are optional - Different languages can have different plural keys
  3. Language-specific validation - Tests check each language against its CLDR requirements
  4. Tests pass - With informational warnings for incomplete translations

What's missing

  1. No IDE warnings for missing plural forms
  2. VS Code won't warn when a Polish file is missing _few or _many because they're optional in the shared schema. This is the main limitation.

Possible solutions:

  1. Generate per-language schemas ($schema-pl.json, etc.) - requires maintaining 29+ files
  2. Use ESLint plugin for i18n validation
  3. Accept warnings in tests only (current approach)

Files Changed

New:

  • scripts/i18n/plural-rules.js - CLDR plural rules mapping for all 29 supported languages

Modified:

  • scripts/i18n/generate-schema.js - Merges all languages, marks plural forms as optional
  • src/i18n/translations/__tests__/validate-translations.spec.ts - Language-aware validation
  • src/i18n/translations/$schema.json - Regenerated with all plural forms

How It Works Now

Before (broken):

  • Polish adds items_few: "{{count}} przedmioty"
  • Tests fail: "English missing items_few"
  • Must add dummy keys to English that are never used

After (this PR):

  • Polish has: items_one, items_few, items_many, items_other
  • English has: items_one, items_other
  • Tests pass - each language has what it needs

Test output shows warnings for incomplete plural forms - these are informational only and don't fail the build.

Questions for Team

  1. Is this approach acceptable? Tests pass but we lose IDE validation for plural forms
  2. Should we generate per-language schemas? Gives IDE warnings but adds maintenance burden
  3. Better alternatives? Open to suggestions

References


Note: This unblocks Polish translation work but needs team discussion on the best long-term solution for IDE validation of language-specific plural forms.

@willbouch
Copy link
Copy Markdown
Contributor

@radeknapora radeknapora changed the title fix(dashboard): add support for plural forms (few/many) in Polish and other Slavic languages fix(dashboard): enforce locale-specific plural forms in translations Nov 11, 2025
@radeknapora
Copy link
Copy Markdown
Contributor Author

Hi @willbouch!

I've updated the PR:

  • Changed title and description to accurately reflect the final implementation
  • Cleaned up the PR structure
  • Updated the changeset to match the actual changes

Everything should now be clearer for review. Let me know if you'd like any adjustments!

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

"uk": ["one", "few", "many", "other"],
"vi": ["other"],
"zh": ["other"]
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Missing language entries in plural configuration

The plural-config.json file is missing entries for several languages that have translation files: el, ro, mk, mn, zhCN, lt, and id. The validation script at scripts/i18n/validate-translation.js requires every language to have an entry in plural-config.json and exits with an error if not found (line 20-23). This means validation will fail for these seven languages, preventing their translation files from being validated or used.

Fix in Cursor Fix in Web

@radeknapora
Copy link
Copy Markdown
Contributor Author

radeknapora commented Dec 9, 2025

Bump @willbouch @olivermrbl @NicolasGorga

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 9, 2026

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@NicolasGorga
Copy link
Copy Markdown
Contributor

@claude review this

@claude
Copy link
Copy Markdown

claude bot commented Jan 13, 2026

PR Review: Locale-Aware Pluralization Validation

Thank you for this well-structured PR! The implementation of locale-specific plural form validation is a valuable addition to the i18n system. Here's my detailed review:


Strengths

  1. Well-Defined Problem & Solution: The PR clearly addresses a real i18n issue with proper CLDR-compliant pluralization rules.

  2. Good Architecture: Separating concerns between schema generation, validation, and configuration is clean and maintainable.

  3. Comprehensive Testing: Test coverage is solid with both unit tests and integration validation.

  4. Documentation: The PR description is excellent with clear examples and testing instructions.

  5. Proper Changeset: Correctly marked as a patch with descriptive message.


🔍 Code Quality Observations

1. Schema Generation Logic (generate-schema.js)

Issue: Missing base key handling in the schema generation

// Current code processes plural keys but doesn't add the base key itself
Object.entries(obj).forEach(([key, value]) => {
  if (getBaseKey(key)) return  // Skips plural form keys
  
  properties[key] = generateSchemaFromObject(value)
  required.push(key)
})

// Then adds all plural forms as optional
localPluralBaseKeys.forEach((baseKey) => {
  ALL_PLURAL_FORMS.forEach((form) => {
    properties[`${baseKey}_${form}`] = { type: "string" }
  })
})

Concern: The base key (e.g., items) should never exist alongside plural forms (items_one, items_other). Consider:

  • Should the schema explicitly forbid the base key when plural forms are present?
  • Add validation to ensure users don't accidentally define both items and items_one?

Recommendation: Add a check in validate-translation.js to error if both base key and plural forms exist:

pluralGroups.forEach(({ path, baseKey }) => {
  const parent = getNestedValue(translations, path)
  if (parent?.[baseKey]) {
    errors.push({
      type: 'conflict',
      instancePath,
      message: `Base key "${baseKey}" conflicts with plural forms. Remove the base key.`
    })
  }
})

2. Validation Logic (validate-translation.js)

Performance Consideration: The code traverses the translation object multiple times:

  1. Once to find all plural keys (findAllPluralKeys)
  2. Once to validate schema (validateSchema)
  3. Once to group and validate plural forms

For large translation files, consider combining traversals or caching results.

Minor Style: The regex pattern is duplicated:

// Line 36
if (/_(?:zero|one|two|few|many|other)$/.test(key)) {

Recommendation: Extract to a constant at the top:

const PLURAL_FORM_PATTERN = /_(?:zero|one|two|few|many|other)$/
const ALL_PLURAL_FORMS = ["zero", "one", "two", "few", "many", "other"]

3. Error Messages

Current:

console.error(`  Missing required plural key: "${key}" at ${location}`)
console.error(`  Unexpected plural key: "${key}" at ${location}`)

Suggestion: Make error messages more actionable:

console.error(`  Missing required plural key: "${key}" at ${location}`)
console.error(`    → English requires: ${requiredForms.join(', ')}`)

console.error(`  Unexpected plural key: "${key}" at ${location}`)
console.error(`    → ${langCode} only supports: ${requiredForms.join(', ')}`)

4. plural-config.json Completeness

Question: How will new languages be added? Consider:

  • Adding a comment or documentation reference in the file header
  • Including a link to CLDR plural rules
  • Validating that the locale codes match CLDR standards

Suggestion: Add a header comment:

{
  "_comment": "Plural forms per CLDR rules: https://cldr.unicode.org/index/cldr-spec/plural-rules",
  "en": ["one", "other"],
  ...
}

🐛 Potential Bugs

1. Edge Case: Empty Plural Groups

If a base key is detected but no plural forms are found in the translation, the validation might not catch it properly.

Test case:

{
  "items_one": "removed"  // What if someone deletes this key?
}

The pluralGroups.forEach will still check for required forms, which is good, but ensure the error message is clear.


2. Nested Object Handling

The getNestedValue function looks solid, but ensure it handles edge cases:

  • Empty path strings
  • Non-existent paths
  • Array values (though not expected in i18n)

Current implementation looks safe, but consider adding a null check:

function getNestedValue(obj, path) {
  if (\!path) return obj
  return path.split(".").reduce((current, key) => current?.[key], obj)
}

✅ Already using optional chaining - good!


🧪 Test Coverage

The test updates in validate-translations.spec.ts look comprehensive, but I'd recommend adding:

  1. Test for invalid plural forms:
test("should reject extra plural forms for locale", () => {
  // Test that 'en.json' with 'items_few' fails validation
})
  1. Test for missing required forms:
test("should require all plural forms for locale", () => {
  // Test that 'pl.json' without 'items_few' fails validation
})
  1. Test plural-config.json completeness:
test("plural-config should cover all translation files", () => {
  const translationFiles = fs.readdirSync(translationsDir)
    .filter(f => f.endsWith('.json') && f \!== '$schema.json')
  const configuredLocales = Object.keys(pluralConfig)
  // Assert all locales are configured
})

🔒 Security Considerations

No security concerns identified. The validation scripts:

  • ✅ Don't execute user input
  • ✅ Don't make network requests
  • ✅ Use safe file system operations
  • ✅ Properly handle JSON parsing errors

📊 Performance Considerations

Schema Size: The generated schema will be significantly larger with all 6 plural forms for each base key. This is acceptable for:

  • ✅ Build-time validation (not runtime)
  • ✅ Development tooling

Validation Speed: The validation script is reasonably efficient, but for very large translation files (1000+ keys), consider:

  • Early exit on first error (optional flag)
  • Parallel validation of multiple locale files

📝 Documentation Suggestions

  1. Add inline code comments in generate-schema.js explaining the plural form detection logic
  2. Document the validation script usage in a README or CONTRIBUTING guide
  3. Add JSDoc comments to helper functions like getBaseKey, findAllPluralKeys

Example:

/**
 * Extracts the base key from a plural form key.
 * @param {string} key - The key to check (e.g., "items_one")
 * @returns {string|null} - The base key (e.g., "items") or null if not a plural form
 */
function getBaseKey(key) {
  for (const form of ALL_PLURAL_FORMS) {
    if (key.endsWith(`_${form}`)) {
      return key.slice(0, -(form.length + 1))
    }
  }
  return null
}

🎯 Recommendations Summary

Critical:

  • ✅ Add validation to prevent base key + plural forms conflicts

High Priority:

  • Add more comprehensive test cases for edge scenarios
  • Improve error messages with actionable guidance

Medium Priority:

  • Extract magic regex patterns to constants
  • Add JSDoc comments to key functions
  • Consider performance optimizations for large files

Low Priority:

  • Add header comment to plural-config.json
  • Consider early-exit flag for validation script

Overall Assessment

This is a solid, well-thought-out PR that addresses a real problem in i18n management. The code quality is good, the approach is sound, and the testing is adequate. With the minor improvements suggested above, this will be an excellent addition to the codebase.

Recommendation: ✅ Approve with minor suggestions

The CI failure appears to be unrelated to this change (Module Integration Tests failing on shards 1-4 seem to be a broader infrastructure issue, not related to i18n validation which passed).

Great work! 🚀

@github-actions
Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Feb 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This PR was closed because it has been stalled for 5 days with no activity.

@github-actions github-actions bot closed this Feb 20, 2026
@NicolasGorga NicolasGorga reopened this Mar 23, 2026
@cursor
Copy link
Copy Markdown

cursor bot commented Mar 23, 2026

You have used all of your free Bugbot PR reviews.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@github-actions github-actions bot removed the Stale label Mar 28, 2026
@radeknapora
Copy link
Copy Markdown
Contributor Author

Any updates on this? @NicolasGorga

@medusa-os-bot
Copy link
Copy Markdown

medusa-os-bot bot commented Apr 9, 2026

Thank you for your contribution! 🎉

After an initial review, this PR looks good to us. Here's a summary:

✅ PR template is complete
✅ Follows contribution guidelines
✅ Tests included and updated
✅ Changeset present

A team member will do a final review before this is merged. We appreciate your patience!


Notes:

  • Locale code coverage in plural-config.json — The translation files use compound locale codes like ptBR, ptPT, zhCN, and zhTW (matching the filenames in src/i18n/translations/). Please confirm that plural-config.json uses these exact codes rather than shortened variants like zh or pt. If there is a mismatch, plural validation will silently skip those locales (or error) when validate-translation.js strips the .json extension and looks up the config entry. If the validate script already normalises codes before the lookup, please add a brief comment explaining this.

  • No linked issue — For contributions of this scope we typically ask for a pre-existing issue. Given the extensive back-and-forth with the team in this PR, this is a soft note rather than a blocker.

@@ -20,12 +31,28 @@ function generateSchemaFromObject(obj) {

const properties = {}
const required = []
const localPluralBaseKeys = new Set()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
const localPluralBaseKeys = new Set()
const localePluralBaseKeys = new Set()

Comment on lines +36 to 48
Object.keys(obj).forEach((key) => {
const baseKey = getBaseKey(key)
if (baseKey) {
localPluralBaseKeys.add(baseKey)
}
})

Object.entries(obj).forEach(([key, value]) => {
if (getBaseKey(key)) return

properties[key] = generateSchemaFromObject(value)
required.push(key)
})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

q: why aren't we doing this in a single loop?

Comment on lines +50 to +54
localPluralBaseKeys.forEach((baseKey) => {
ALL_PLURAL_FORMS.forEach((form) => {
properties[`${baseKey}_${form}`] = { type: "string" }
})
})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

suggestion: similarly, I think this can be part of the same loop.

"uk": ["one", "few", "many", "other"],
"vi": ["other"],
"zh": ["other"]
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add newly added languages so that the validation doesn't fail.

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.

5 participants