Skip to content

fix(locale): fall back when default translation is empty string - #15069

Merged
ChiragAgg5k merged 1 commit into
mainfrom
cursor/locale-empty-string-fallback-d446
Oct 28, 2026
Merged

ChiragAgg5k merged 1 commit into
mainfrom
cursor/locale-empty-string-fallback-d446

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Several locale JSON files define keys such as emails.recovery.subject as empty strings. Locale::getText() treated those keys as present and returned "", so password-recovery (and similar) mails were queued with an empty subject and the worker.mails job failed in Template::fromString (CLOUD-3QX0).

This change treats empty (and null) default-locale values as untranslated: use the fallback locale’s non-empty value when available, otherwise keep the existing dynamic/custom default and missing-key exception behavior. Translation files are unchanged.

Test Plan

  • Added testEmptyDefaultLocaleValueUsesFallback in packages/locale/tests/LocaleTest.php.
  • Added testRecoverySubjectFromTranslationFilesWithEmptyLocale, which loads en.json + bg.json and asserts emails.recovery.subject is non-empty with English fallback text.
  • Run bin/monorepo test locale.

Fixes CLOUD-3QX0

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?
Open in Web Open in Cursor 

Related: appwrite-labs/cloud#5938

Empty keys in locale JSON (e.g. emails.recovery.subject) were returned
as-is and caused mail workers to fail on Template::fromString. Prefer
non-empty fallback locale values instead.

Fixes CLOUD-3QX0

Co-authored-by: Chirag Aggarwal <[email protected]>
@luxor-code-review

luxor-code-review Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This change refines translation lookup in packages/locale/src/Locale.php so that an empty-string value in the active/default locale is treated as missing and falls through to the fallback locale translation instead of returning an empty string, and placeholder substitution still applies to fallback-sourced values. The exception path for keys missing in both locales is preserved when exceptions are enabled. Tests in packages/locale/tests/LocaleTest.php cover the new fallback ordering and the dynamic-key default ({{key}}) interaction with empty locale values.

Files Change
packages/locale/src/Locale.php Treat empty-string default-locale entries as missing so fallback-locale translations are used, with placeholder substitution retained
packages/locale/tests/LocaleTest.php Add regression tests for empty-string fallback ordering, exception behavior, and static-registry state cleanup

Reviewed commit: 8262340

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 28, 2026
@ghost

ghost commented Oct 28, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The changed selection logic matches the stated fallback behavior, and the regression tests cover the production recovery-subject case.

Locale::getText() now treats empty and null values in the default locale as untranslated, using a non-empty fallback translation when available and preserving the configured default otherwise. The tests cover fallback behavior and the recovery subject in the Appwrite translation files.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 2
File Change
packages/locale/src/Locale.php Prefer non-empty default translations, then non-empty fallback translations, while retaining the configured default value as the final fallback.
packages/locale/tests/LocaleTest.php Add tests for empty default values using a fallback and for the real recovery subject translation files.

Reviewed 8262340 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → cursor/locale-empty-string-fallback-d446 (after).

Metric Before After Change
🚀 Requests/sec 173.54 166.88 ⚪ -3.8%
⏱️ Latency P50 97.99 ms 102.77 ms ⚪ +4.9%
⏱️ Latency P95 227.31 ms 245.4 ms 🔴 +8%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 102.77 245.4 10,317 166.88 +18.09
Account 204.66 379.88 543 9.04 +27.47
TablesDB 98.66 186.72 5,611 92.07 +2.41
Storage 97.47 224.49 2,715 47.06 -4.07
Functions 148.72 283.51 1,448 25.98 +42.26

Top API waits (after)

API request Max wait (ms)
functions.create 561.91
account.name.update 524.31
account.prefs.update 518.62
storage.buckets.create 488.99
tablesdb.rows.create 438.83

@ChiragAgg5k
ChiragAgg5k merged commit 7df604e into main Oct 28, 2026
68 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the cursor/locale-empty-string-fallback-d446 branch October 28, 2026 21:18
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