Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ const locales: (LocaleObjectData | (Omit<LocaleObjectData, 'code'> & { code: str
file: 'bn-IN.json',
name: 'বাংলা',
},
{
code: 'bg-BG',
file: 'bg-BG.json',
name: 'Български',
pluralRule: createPluralRule('bg-BG', { zero: 1, one: 0, two: 1, few: 1, many: 1, other: 1 }),
},
Comment on lines +124 to +129
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 | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, find the Vue i18n version and look at the Bulgarian message file
find . -type f -name "package.json" | head -5

Repository: npmx-dev/npmx.dev

Length of output: 114


🏁 Script executed:

# Look for the Bulgarian message file
find . -type f -name "bg-BG.json"

Repository: npmx-dev/npmx.dev

Length of output: 113


🏁 Script executed:

# Check the createPluralRule implementation to understand how it works
rg -A 10 "createPluralRule" --type ts

Repository: npmx-dev/npmx.dev

Length of output: 3958


🏁 Script executed:

# Look at the i18n.ts file structure to understand context
head -150 config/i18n.ts | tail -50

Repository: npmx-dev/npmx.dev

Length of output: 1275


🏁 Script executed:

# Check the Bulgarian message file for plural strings
cat i18n/locales/bg-BG.json | head -100

Repository: npmx-dev/npmx.dev

Length of output: 4242


🏁 Script executed:

# Use Python to check what plural categories Intl.PluralRules returns for Bulgarian
# and understand the CLDR plural rules for Bulgarian
node <<'EOF'
// Check what plural categories Intl.PluralRules returns for Bulgarian
const pr = new Intl.PluralRules('bg-BG');
const testNumbers = [0, 1, 2, 3, 4, 5, 10, 21, 22, 100, 101, 102];
const categories = new Set();

console.log("Bulgarian plural categories for test numbers:");
testNumbers.forEach(n => {
  const cat = pr.select(n);
  categories.add(cat);
  console.log(`  ${n} → ${cat}`);
});

console.log("\nDistinct categories:", Array.from(categories).sort());
console.log("Available categories:", pr.resolvedOptions().pluralCategories);
EOF

Repository: npmx-dev/npmx.dev

Length of output: 339


🏁 Script executed:

# Search for plural strings in the Bulgarian file (strings with pipe separators)
rg '\|' i18n/locales/bg-BG.json | head -20

Repository: npmx-dev/npmx.dev

Length of output: 1987


🏁 Script executed:

# Check if there's documentation about plural form conventions or other similar locales
rg -B 2 -A 2 "zero.*one.*other" config/i18n.ts | head -40

Repository: npmx-dev/npmx.dev

Length of output: 1211


🏁 Script executed:

# Look at how many forms are typically in Bulgarian strings
python <<'EOF'
import json
with open('i18n/locales/bg-BG.json', 'r', encoding='utf-8') as f:
    data = json.load(f)

def count_plural_forms(obj, path=""):
    """Recursively find strings with pipe separators and count forms"""
    results = []
    if isinstance(obj, dict):
        for key, value in obj.items():
            new_path = f"{path}.{key}" if path else key
            results.extend(count_plural_forms(value, new_path))
    elif isinstance(obj, str):
        if '|' in obj:
            forms = obj.split('|')
            results.append((path, len(forms), obj[:80]))
    return results

plural_strings = count_plural_forms(data)
form_counts = {}
for path, count, sample in plural_strings:
    form_counts[count] = form_counts.get(count, 0) + 1

print("Distribution of plural forms in bg-BG.json:")
for count in sorted(form_counts.keys()):
    print(f"  {count} forms: {form_counts[count]} strings")

print("\nFirst few 3-form strings:")
three_form = [(p, s) for p, c, s in plural_strings if c == 3]
for path, sample in three_form[:5]:
    print(f"  {path}: {sample}...")
EOF

Repository: npmx-dev/npmx.dev

Length of output: 504


Fix Bulgarian plural rule to support zero|one|other message variants.

The plural rule currently returns only indices 0 or 1, but the translation file contains 3 strings with three forms (zero|one|other): search.found_packages, search.found_packages_sorted, and common.vanity_downloads_hint. For count 0, Intl.PluralRules('bg-BG').select(0) returns 'other', which maps to index 1, incorrectly selecting the middle form instead of the first. Adjust the plural rule to return 0 for zero, 1 for one, and 2 for other when the message has three forms available.

Example: 3-form aware rule
   {
     code: 'bg-BG',
     file: 'bg-BG.json',
     name: 'Български',
-    pluralRule: createPluralRule('bg-BG', { zero: 1, one: 0, two: 1, few: 1, many: 1, other: 1 }),
+    pluralRule: (choice: number, choicesLength: number) => {
+      if (choicesLength >= 3 && choice === 0)
+        return 0
+      if (choice === 1)
+        return Math.min(1, choicesLength - 1)
+      return Math.min(2, choicesLength - 1)
+    },
   },
📝 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
{
code: 'bg-BG',
file: 'bg-BG.json',
name: 'Български',
pluralRule: createPluralRule('bg-BG', { zero: 1, one: 0, two: 1, few: 1, many: 1, other: 1 }),
},
{
code: 'bg-BG',
file: 'bg-BG.json',
name: 'Български',
pluralRule: (choice: number, choicesLength: number) => {
if (choicesLength >= 3 && choice === 0)
return 0
if (choice === 1)
return Math.min(1, choicesLength - 1)
return Math.min(2, choicesLength - 1)
},
},

/*{
code: 'ckb',
file: 'ckb.json',
Expand Down
Loading
Loading