use default for missing locales

This commit is contained in:
Damodar Lohani
2023-04-17 09:10:41 +00:00
parent 8fcb199af0
commit e992814552
2 changed files with 10 additions and 8 deletions
+6 -4
View File
@@ -666,15 +666,17 @@ $locales = Config::getParam('locale-codes', []);
foreach ($locales as $locale) {
$code = $locale['code'];
$path = __DIR__ . '/config/locale/translations/' . $code . '.json';
if (!\file_exists($path)) {
$path = __DIR__ . '/config/locale/translations/' . \substr($code, 0, 2) . '.json';
$path = __DIR__ . '/config/locale/translations/' . \substr($code, 0, 2) . '.json'; // if `ar-ae` doesn't exist, look for `ar`
if(!\file_exists($path)) {
$path = __DIR__ . '/config/locale/translations/en.json'; // if none translation exists, use default from `en.json`
}
}
if (\file_exists($path)) {
Locale::setLanguageFromJSON($code, $path);
}
Locale::setLanguageFromJSON($code, $path);
}
\stream_context_set_default([ // Set global user agent and http settings
+4 -4
View File
@@ -235,7 +235,7 @@ trait LocaleBase
$response = $this->client->call(Client::METHOD_GET, '/locale/countries', [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-locale' => $lang,
'x-appwrite-locale' => $lang['code'],
]);
if (!\is_array($response['body']['countries'])) {
@@ -243,7 +243,7 @@ trait LocaleBase
}
foreach ($response['body']['countries'] as $i => $code) {
$this->assertContains($code['code'], $defaultCountries, $code['code'] . ' country should be removed from ' . $lang);
$this->assertContains($code['code'], $defaultCountries, $code['code'] . ' country should be removed from ' . $lang['code']);
}
// foreach (array_keys($defaultCountries) as $i => $code) {
@@ -256,11 +256,11 @@ trait LocaleBase
$response = $this->client->call(Client::METHOD_GET, '/locale/continents', [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-locale' => $lang,
'x-appwrite-locale' => $lang['code'],
]);
foreach ($response['body']['continents'] as $i => $code) {
$this->assertContains($code['code'], $defaultContinents, $code['code'] . ' continent should be removed from ' . $lang);
$this->assertContains($code['code'], $defaultContinents, $code['code'] . ' continent should be removed from ' . $lang['code']);
}
// foreach (array_keys($defaultContinents) as $i => $code) {