Merge pull request #13041 from appwrite/fix/locale-fallback-en

fix(locale): always fall back to English for missing translations
This commit is contained in:
Chirag Aggarwal authored and GitHub committed 2026-07-30 08:00:00 +05:30
commit 46f7dacc3d
6 files changed
+55 -5

No files matched your search

+4 -1
View File
@@ -118,7 +118,10 @@ return function (Container $context): void {
$context->set('locale', function () {
$locale = new Locale(System::getEnv('_APP_LOCALE', 'en'));
$locale->setFallback(System::getEnv('_APP_LOCALE', 'en'));
// Always fall back to English — it is the only complete translation set.
// Using _APP_LOCALE here left missing keys as {{emails.*}} when the
// instance default was a partial locale (e.g. fr). See #12448.
$locale->setFallback('en');
return $locale;
});
@@ -61,7 +61,7 @@ class Get extends Action
$locale = $locale ?: System::getEnv('_APP_LOCALE', 'en');
$localeObj = new Locale($locale);
$localeObj->setFallback(System::getEnv('_APP_LOCALE', 'en'));
$localeObj->setFallback('en');
$response->dynamic(new Document([
'templateId' => $templateId,
@@ -73,7 +73,7 @@ class Get extends Action
// Prepare default tempaltes
$localeObj = new Locale($locale);
$localeObj->setFallback(System::getEnv('_APP_LOCALE', 'en'));
$localeObj->setFallback('en');
$defaultSubject = $localeObj->getText('emails.' . $templateId . '.subject');
$defaultMessage = $this->getDefaultMessage($templateId, $localeObj);
@@ -543,7 +543,7 @@ class Certificates extends Action
Console::warning('Cannot renew domain (' . $domain . ') on attempt no. ' . $attempt . ' certificate: ' . $errorMessage);
$locale = new Locale(System::getEnv('_APP_LOCALE', 'en'));
$locale->setFallback(System::getEnv('_APP_LOCALE', 'en'));
$locale->setFallback('en');
// Send mail to administrator mail
$template = Template::fromFile(__DIR__ . '/../../../../app/config/locale/templates/email-certificate-failed.tpl');
+1 -1
View File
@@ -978,7 +978,7 @@ class Migrations extends Action
}
$locale = new Locale(System::getEnv('_APP_LOCALE', 'en'));
$locale->setFallback(System::getEnv('_APP_LOCALE', 'en'));
$locale->setFallback('en');
$emailType = $success
? 'success'
+47
View File
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Locale;
use PHPUnit\Framework\TestCase;
use Utopia\Locale\Locale;
final class FallbackTest extends TestCase
{
protected function setUp(): void
{
$translationsDir = __DIR__ . '/../../../app/config/locale/translations';
Locale::$exceptions = false;
Locale::setLanguageFromJSON('en', $translationsDir . '/en.json');
Locale::setLanguageFromJSON('fr', $translationsDir . '/fr.json');
}
public function testIncompleteLocaleFallsBackToEnglishForMissingEmailKeys(): void
{
$locale = new Locale('fr');
$locale->setFallback('en');
$preview = $locale->getText('emails.verification.preview');
$this->assertNotSame('{{emails.verification.preview}}', $preview);
$this->assertSame(
'Verify your email to activate your {{project}} account.',
$preview
);
// Keys present in fr stay French.
$this->assertSame('Vérification du compte', $locale->getText('emails.verification.subject'));
}
public function testFallbackMatchingIncompleteLocaleLeaksRawKeys(): void
{
$locale = new Locale('fr');
// Mirrors the previous bug: fallback = _APP_LOCALE when that env is fr.
$locale->setFallback('fr');
$this->assertSame(
'{{emails.verification.preview}}',
$locale->getText('emails.verification.preview')
);
}
}