1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-28 01:32:41 +01:00

Add fallback languages for locale files

Summary: Upstream version of https://gerrit.wikimedia.org/r/c/phabricator/translations/+/1047593

Test Plan:
Set any languages and observe untranslated strings display proper PLURAL rules

With the downstream "translations" extension installed, set the language to traditional Chinese and see Simplified Chinese rather than English translations if they exist, like "Foo added/removed a project"

Reviewers: O1 Blessed Committers, avivey

Reviewed By: O1 Blessed Committers, avivey

Subscribers: avivey, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Differential Revision: https://we.phorge.it/D25695
This commit is contained in:
Pppery 2024-06-19 15:54:09 -04:00
parent f7fcf31c7e
commit 0af89f7d32
6 changed files with 42 additions and 1 deletions

View file

@ -30,11 +30,14 @@ abstract class PhutilLocale extends Phobject {
* For locales like "English (Great Britain)", missing translations can be * For locales like "English (Great Britain)", missing translations can be
* sourced from "English (US)". * sourced from "English (US)".
* *
* Languages with no other fallback use en_US because that's better
* than proto-English for untranslated strings.
*
* @return string|null Locale code of fallback locale, or null if there is * @return string|null Locale code of fallback locale, or null if there is
* no fallback locale. * no fallback locale.
*/ */
public function getFallbackLocaleCode() { public function getFallbackLocaleCode() {
return null; return 'en_US';
} }

View file

@ -13,4 +13,13 @@ final class PhutilPortugueseBrazilLocale extends PhutilLocale {
return pht('Portuguese (Brazil)'); return pht('Portuguese (Brazil)');
} }
public function getFallbackLocaleCode() {
// Phabricator does not support bidirectional
// fallbacks (pt_BR -> pt and pt -> pt_BR simultaneously)
// since Translatewiki calls pt_PT "Portugese" without a country
// it makes slightly more sense to fall back in this direction
// than the other one
return 'pt_PT';
}
} }

View file

@ -13,4 +13,14 @@ final class PhutilPortuguesePortugalLocale extends PhutilLocale {
return pht('Portuguese (Portugal)'); return pht('Portuguese (Portugal)');
} }
public function getFallbackLocaleCode() {
// Ideally this would be pt_BR but Phabricator does not support
// bidirectional fallbacks (pt_BR -> pt and pt -> pt_BR simultaneously)
// since Translatewiki calls pt_PT "Portugese" without a country
// it makes slightly more sense to fall back in the other direction
// In the mean time return `en_US` so users don't see Proto-English
// unncecessarily
return 'en_US';
}
} }

View file

@ -13,4 +13,13 @@ final class PhutilSimplifiedChineseLocale extends PhutilLocale {
return pht('Chinese (Simplified)'); return pht('Chinese (Simplified)');
} }
public function getFallbackLocaleCode() {
// Ideally this would be zh_Hant but Phabricator does not support
// bidirectional fallbacks
// (zh_Hant -> zh_Hans and zh_Hans -> zh_Hant simultaneously)
// arbitrarily choose to fall back in the other direction instead
// In the mean time return `en_US` so users don't see Proto-English
return 'en_US';
}
} }

View file

@ -13,4 +13,8 @@ final class PhutilTraditionalChineseLocale extends PhutilLocale {
return pht('Chinese (Traditional)'); return pht('Chinese (Traditional)');
} }
public function getFallbackLocaleCode() {
return 'zh_Hans';
}
} }

View file

@ -13,4 +13,10 @@ final class PhutilUSEnglishLocale extends PhutilLocale {
return pht('English (US)'); return pht('English (US)');
} }
public function getFallbackLocaleCode() {
// The default fallback is en_US, explicitly return null here
// to avoid a fallback loop
return null;
}
} }