Skip to content

Commit

Permalink
use baselocale for missal and decrees data
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRDOrazio committed Nov 28, 2024
1 parent 8727076 commit 1c56573
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/Params/EventsParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class EventsParams
public int $Year;
public bool $EternalHighPriest = false;
public ?string $Locale = null;
public ?string $baseLocale = null;
public ?string $NationalCalendar = null;
public ?string $DiocesanCalendar = null;
private array $SupportedNationalCalendars = [];
Expand Down Expand Up @@ -78,6 +79,7 @@ public function __construct(array $DATA = [])
} else {
$this->Locale = LitLocale::LATIN;
}
$this->baseLocale = \Locale::getPrimaryLanguage($this->Locale);

$this->calendarsMetadata = json_decode(file_get_contents(API_BASE_PATH . Route::CALENDARS->value))->litcal_metadata;
$this->SupportedDiocesanCalendars = $this->calendarsMetadata->diocesan_calendars_keys;
Expand Down Expand Up @@ -111,6 +113,7 @@ public function setData(array $DATA): bool
case "locale":
$this->Locale = \Locale::canonicalize($this->Locale);
$this->Locale = LitLocale::isValid($value) ? $value : LitLocale::LATIN;
$this->baseLocale = \Locale::getPrimaryLanguage($this->Locale);
break;
case "national_calendar":
if (false === in_array(strtoupper($value), $this->SupportedNationalCalendars)) {
Expand Down
32 changes: 16 additions & 16 deletions src/Paths/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ private function loadNationalAndWiderRegionData(): void
|| !in_array($this->EventsParams->Locale, self::$NationalData->metadata->locales)
) {
$this->EventsParams->Locale = self::$NationalData->metadata->locales[0];
$this->EventsParams->baseLocale = \Locale::getPrimaryLanguage($this->EventsParams->Locale);
}
}
if (property_exists(self::$NationalData, "metadata") && property_exists(self::$NationalData->metadata, "wider_region")) {
Expand All @@ -278,7 +279,7 @@ private function loadNationalAndWiderRegionData(): void
JsonData::WIDER_REGIONS_I18N_FILE,
[
'{wider_region}' => self::$NationalData->metadata->wider_region,
'{locale}' => $this->EventsParams->Locale
'{locale}' => $this->EventsParams->baseLocale
]
);
if (file_exists($widerRegionI18nFile)) {
Expand Down Expand Up @@ -313,23 +314,22 @@ private function loadNationalAndWiderRegionData(): void
*/
private function setLocale(): void
{
$baseLocale = \Locale::getPrimaryLanguage($this->EventsParams->Locale);
$localeArray = [
$this->EventsParams->Locale . '.utf8',
$this->EventsParams->Locale . '.UTF-8',
$this->EventsParams->Locale,
$baseLocale . '_' . strtoupper($baseLocale) . '.utf8',
$baseLocale . '_' . strtoupper($baseLocale) . '.UTF-8',
$baseLocale . '_' . strtoupper($baseLocale),
$baseLocale . '.utf8',
$baseLocale . '.UTF-8',
$baseLocale
$this->EventsParams->baseLocale . '_' . strtoupper($this->EventsParams->baseLocale) . '.utf8',
$this->EventsParams->baseLocale . '_' . strtoupper($this->EventsParams->baseLocale) . '.UTF-8',
$this->EventsParams->baseLocale . '_' . strtoupper($this->EventsParams->baseLocale),
$this->EventsParams->baseLocale . '.utf8',
$this->EventsParams->baseLocale . '.UTF-8',
$this->EventsParams->baseLocale
];
setlocale(LC_ALL, $localeArray);
bindtextdomain("litcal", "i18n");
textdomain("litcal");
self::$LitGrade = new LitGrade($baseLocale);
self::$LitCommon = new LitCommon($baseLocale);
self::$LitGrade = new LitGrade($this->EventsParams->baseLocale);
self::$LitCommon = new LitCommon($this->EventsParams->baseLocale);
}

/**
Expand Down Expand Up @@ -389,11 +389,11 @@ private function processMissalData(): void
// There may or may not be a related translation file; if there is, we get the translated name from here
$I18nPath = RomanMissal::getSanctoraleI18nFilePath($LatinMissal);
if ($I18nPath !== false) {
if (false === file_exists($I18nPath . "/" . $this->EventsParams->Locale . ".json")) {
if (false === file_exists($I18nPath . "/" . $this->EventsParams->baseLocale . ".json")) {
echo self::produceErrorResponse(StatusCode::NOT_FOUND, "Could not find resource $I18nPath");
die();
}
$NAME = json_decode(file_get_contents($I18nPath . "/" . $this->EventsParams->Locale . ".json"), true);
$NAME = json_decode(file_get_contents($I18nPath . "/" . $this->EventsParams->baseLocale . ".json"), true);
if (json_last_error() !== JSON_ERROR_NONE) {
echo self::produceErrorResponse(StatusCode::SERVICE_UNAVAILABLE, json_last_error_msg());
die();
Expand Down Expand Up @@ -425,7 +425,7 @@ private function processMissalData(): void
private function processPropriumDeTemporeData(): void
{
$DataFile = 'jsondata/sourcedata/missals/propriumdetempore/propriumdetempore.json';
$I18nFile = 'jsondata/sourcedata/missals/propriumdetempore/i18n/' . $this->EventsParams->Locale . ".json";
$I18nFile = 'jsondata/sourcedata/missals/propriumdetempore/i18n/' . $this->EventsParams->baseLocale . ".json";
if (!file_exists($DataFile) || !file_exists($I18nFile)) {
echo self::produceErrorResponse(
StatusCode::NOT_FOUND,
Expand Down Expand Up @@ -481,7 +481,7 @@ private function processPropriumDeTemporeData(): void
private function processMemorialsFromDecreesData(): void
{
$DataFile = 'jsondata/sourcedata/decrees/decrees.json';
$I18nFile = 'jsondata/sourcedata/decrees/i18n/' . $this->EventsParams->Locale . ".json";
$I18nFile = 'jsondata/sourcedata/decrees/i18n/' . $this->EventsParams->baseLocale . ".json";
if (!file_exists($DataFile) || !file_exists($I18nFile)) {
echo self::produceErrorResponse(StatusCode::NOT_FOUND, "Could not find resource file $DataFile or resource file $I18nFile");
die();
Expand All @@ -504,8 +504,8 @@ private function processMemorialsFromDecreesData(): void
self::$FestivityCollection[ $key ][ "name" ] = $NAME[ $key ];
if (array_key_exists("locales", $festivity[ "metadata" ])) {
$decreeURL = sprintf($festivity[ "metadata" ][ "url" ], 'LA');
if (array_key_exists($this->EventsParams->Locale, $festivity[ "metadata" ][ "locales" ])) {
$decreeLang = $festivity[ "metadata" ][ "locales" ][ $this->EventsParams->Locale ];
if (array_key_exists($this->EventsParams->baseLocale, $festivity[ "metadata" ][ "locales" ])) {
$decreeLang = $festivity[ "metadata" ][ "locales" ][ $this->EventsParams->baseLocale ];
$decreeURL = sprintf($festivity[ "metadata" ][ "url" ], $decreeLang);
}
} else {
Expand Down

0 comments on commit 1c56573

Please sign in to comment.