Skip to content

Commit

Permalink
prefer Locale::getPrimaryLanguage to explode
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRDOrazio committed May 22, 2024
1 parent 6256cb5 commit 8f8cf67
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
35 changes: 18 additions & 17 deletions includes/LitCalAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ private function cacheFileIsAvailable() : bool {
}

private function createFormatters() : void {
$baseLocale = Locale::getPrimaryLanguage($this->LitSettings->Locale);
$baseLocale = LitLocale::$PRIMARY_LANGUAGE;
$this->dayAndMonth = IntlDateFormatter::create( $baseLocale, IntlDateFormatter::FULL, IntlDateFormatter::NONE, 'UTC', IntlDateFormatter::GREGORIAN, "d MMMM" );
$this->dayOfTheWeek = IntlDateFormatter::create( $baseLocale, IntlDateFormatter::FULL, IntlDateFormatter::NONE, 'UTC', IntlDateFormatter::GREGORIAN, "EEEE" );
$this->formatter = new NumberFormatter( $baseLocale, NumberFormatter::SPELLOUT );
Expand Down Expand Up @@ -412,7 +412,7 @@ private function dieIfBeforeMinYear() : void {
* Retrieve Higher Ranking Solemnities from Proprium de Tempore
*/
private function loadPropriumDeTemporeData() : void {
$locale = Locale::getPrimaryLanguage( $this->LitSettings->Locale );
$locale = LitLocale::$PRIMARY_LANGUAGE;
$propriumdetemporeFile = "data/propriumdetempore/{$locale}.json";
if( file_exists( $propriumdetemporeFile ) ) {
$PropriumDeTempore = json_decode( file_get_contents( $propriumdetemporeFile ), true );
Expand All @@ -431,7 +431,7 @@ private function loadPropriumDeSanctisData( string $missal ) : void {
$propriumdesanctisI18nPath = RomanMissal::getSanctoraleI18nFilePath( $missal );

if( $propriumdesanctisI18nPath !== false ) {
$locale = strtolower( explode('_', $this->LitSettings->Locale)[0] );
$locale = LitLocale::$PRIMARY_LANGUAGE;
$propriumdesanctisI18nFile = $propriumdesanctisI18nPath . $locale . ".json";
if( file_exists( $propriumdesanctisI18nFile ) ) {
$NAME = json_decode( file_get_contents( $propriumdesanctisI18nFile ), true );
Expand Down Expand Up @@ -472,7 +472,7 @@ private function loadPropriumDeSanctisData( string $missal ) : void {
private function loadMemorialsFromDecreesData() : void {
$memorialsFromDecreesFile = "data/memorialsFromDecrees/memorialsFromDecrees.json";
$memorialsFromDecreesI18nPath = "data/memorialsFromDecrees/i18n/";
$locale = strtolower( explode('_', $this->LitSettings->Locale)[0] );
$locale = LitLocale::$PRIMARY_LANGUAGE;
$memorialsFromDecreesI18nFile = $memorialsFromDecreesI18nPath . $locale . ".json";
$NAME = null;

Expand Down Expand Up @@ -526,7 +526,7 @@ private function calculateEpiphanyJan6() : void {
} else {
$nth++;
//$nthStr = $this->LitSettings->Locale === LitLocale::LATIN ? LitMessages::LATIN_ORDINAL[ $nth ] : $this->formatter->format( $nth );
$locale = strtoupper( explode('_', $this->LitSettings->Locale)[0] );
$locale = strtoupper( LitLocale::$PRIMARY_LANGUAGE );
$dayOfTheWeek = $locale === LitLocale::LATIN
? LitMessages::LATIN_DAYOFTHEWEEK[ $dateTime->format( 'w' ) ]
: ( $locale === 'IT'
Expand Down Expand Up @@ -557,7 +557,7 @@ private function calculateEpiphanyJan6() : void {
$nth++;
//$nthStr = $this->LitSettings->Locale === LitLocale::LATIN ? LitMessages::LATIN_ORDINAL[ $nth ] : $this->formatter->format( $nth );
$dateTime = LitDateTime::createFromFormat( '!j-n-Y', $i . '-1-' . $this->LitSettings->Year, new DateTimeZone( 'UTC' ) );
$locale = strtoupper( explode('_', $this->LitSettings->Locale)[0] );
$locale = strtoupper( LitLocale::$PRIMARY_LANGUAGE );
$dayOfTheWeek = $locale === LitLocale::LATIN
? LitMessages::LATIN_DAYOFTHEWEEK[ $dateTime->format( 'w' ) ]
: ( $locale === 'IT'
Expand Down Expand Up @@ -604,7 +604,7 @@ private function calculateEpiphanySunday() : void {
$nth++;
//$nthStr = $this->LitSettings->Locale === LitLocale::LATIN ? LitMessages::LATIN_ORDINAL[ $nth ] : $this->formatter->format( $nth );
$dateTime = LitDateTime::createFromFormat( '!j-n-Y', $i . '-1-' . $this->LitSettings->Year, new DateTimeZone( 'UTC' ) );
$locale = strtoupper( explode('_', $this->LitSettings->Locale)[0] );
$locale = strtoupper( LitLocale::$PRIMARY_LANGUAGE );
$dayOfTheWeek = $locale === LitLocale::LATIN
? LitMessages::LATIN_DAYOFTHEWEEK[ $dateTime->format( 'w' ) ]
: ( $locale === 'IT'
Expand Down Expand Up @@ -634,7 +634,7 @@ private function calculateEpiphanySunday() : void {
$nth++;
//$nthStr = $this->LitSettings->Locale === LitLocale::LATIN ? LitMessages::LATIN_ORDINAL[ $nth ] : $this->formatter->format( $nth );
$dateTime = LitDateTime::createFromFormat( '!j-n-Y', $i . '-1-' . $this->LitSettings->Year, new DateTimeZone( 'UTC' ) );
$locale = strtoupper( explode('_', $this->LitSettings->Locale)[0] );
$locale = strtoupper( LitLocale::$PRIMARY_LANGUAGE );
$dayOfTheWeek = $locale === LitLocale::LATIN
? LitMessages::LATIN_DAYOFTHEWEEK[ $dateTime->format( 'w' ) ]
: ( $locale === 'IT'
Expand Down Expand Up @@ -809,7 +809,7 @@ private function calculateFixedSolemnities() : void {
//and the Annunciation will be transferred to the Monday following the Second Sunday of Easter
//Notitiæ vol. 42 [ 2006 ] num. 3/4, 475-476, p. 96
//http://www.cultodivino.va/content/cultodivino/it/rivista-notitiae/indici-annate/2006/475-476.html
$locale = strtoupper( explode('_', $this->LitSettings->Locale)[0] );
$locale = strtoupper( LitLocale::$PRIMARY_LANGUAGE );
if( $row->TAG === "StJoseph" && $currentFeastDate >= $this->Cal->getFestivity("PalmSun")->date && $currentFeastDate <= $this->Cal->getFestivity("Easter")->date ){
$tempFestivity->date = LitFunc::calcGregEaster( $this->LitSettings->Year )->sub( new DateInterval( 'P8D' ) );
$this->Messages[] = sprintf(
Expand Down Expand Up @@ -962,7 +962,7 @@ private function calculateFeastsOfTheLord() : void {
}

//Holy Family is celebrated the Sunday after Christmas, unless Christmas falls on a Sunday, in which case it is celebrated Dec. 30
$locale = strtoupper( explode('_', $this->LitSettings->Locale)[0] );
$locale = strtoupper( LitLocale::$PRIMARY_LANGUAGE );
if ( self::DateIsSunday( $this->Cal->getFestivity( "Christmas" )->date ) ) {
$holyFamilyDate = LitDateTime::createFromFormat( '!j-n-Y', '30-12-' . $this->LitSettings->Year, new DateTimeZone( 'UTC' ) );
$HolyFamily = new Festivity( $this->PropriumDeTempore[ "HolyFamily" ][ "NAME" ], $holyFamilyDate, LitColor::WHITE, LitFeastType::MOBILE, LitGrade::FEAST_LORD );
Expand Down Expand Up @@ -990,7 +990,7 @@ private function calculateFeastsOfTheLord() : void {
if( $this->LitSettings->Year >= 2012 && true === $this->LitSettings->EternalHighPriest ) {
$EternalHighPriestDate = clone( $this->Cal->getFestivity( "Pentecost" )->date );
$EternalHighPriestDate->modify('next Thursday');
$locale = strtoupper( explode('_', $this->LitSettings->Locale)[0] );
$locale = strtoupper( LitLocale::$PRIMARY_LANGUAGE );
$EternalHighPriestName = $locale === LitLocale::LATIN ? 'Domini Nostri Iesu Christi Summi et Aeterni Sacerdotis' :
/**translators: You can ignore this translation if the Feast has not been inserted by the Episcopal Conference */
_( 'Our Lord Jesus Christ, The Eternal High Priest' );
Expand Down Expand Up @@ -1194,7 +1194,7 @@ private function addMissalMemorialMessage( object $row ) {
* 5. Source of the information
* 6. Requested calendar year
*/
$locale = strtoupper( explode('_', $this->LitSettings->Locale)[0] );
$locale = strtoupper( LitLocale::$PRIMARY_LANGUAGE );
$message = _( 'The %1$s \'%2$s\' has been added on %3$s since the year %4$d (%5$s), applicable to the year %6$d.' );
$this->Messages[] = sprintf(
$message,
Expand Down Expand Up @@ -1339,7 +1339,7 @@ private function handleCoincidence( stdClass $row, string $missal = RomanMissal:
* 8. Name of the festivity that is superseding
* 9. Requested calendar year
*/
$locale = strtoupper( explode('_', $this->LitSettings->Locale)[0] );
$locale = strtoupper( LitLocale::$PRIMARY_LANGUAGE );
$message = _( 'The %1$s \'%2$s\', added in the %3$s of the Roman Missal since the year %4$d (%5$s) and usually celebrated on %6$s, is suppressed by the %7$s \'%8$s\' in the year %9$d.' );
$this->Messages[] = sprintf(
$message,
Expand All @@ -1365,7 +1365,7 @@ private function handleCoincidenceDecree( object $row ) : void {
$url = str_contains( $row->Metadata->decreeURL, '%s' ) ? sprintf($row->Metadata->decreeURL, $lang) : $row->Metadata->decreeURL;
$decree = '<a href="' . $url . '">' . _( "Decree of the Congregation for Divine Worship" ) . '</a>';
$coincidingFestivity = $this->Cal->determineSundaySolemnityOrFeast( $row->Festivity->DATE, $this->LitSettings );
$locale = strtoupper( explode('_', $this->LitSettings->Locale)[0] );
$locale = strtoupper( LitLocale::$PRIMARY_LANGUAGE );
$this->Messages[] = sprintf(
/**translators:
* 1. Grade or rank of the festivity
Expand Down Expand Up @@ -1518,7 +1518,7 @@ private function createFestivityFromDecree( object $row ) : void {
} else {
$row->Festivity->DATE = LitDateTime::createFromFormat( '!j-n-Y', "{$row->Festivity->DAY}-{$row->Festivity->MONTH}-{$this->LitSettings->Year}", new DateTimeZone( 'UTC' ) );
$decree = $this->elaborateDecreeSource( $row );
$locale = strtoupper( explode('_', $this->LitSettings->Locale)[0] );
$locale = strtoupper( LitLocale::$PRIMARY_LANGUAGE );
if( $row->Festivity->GRADE === LitGrade::MEMORIAL_OPT ) {
if( $this->Cal->notInSolemnitiesFeastsOrMemorials( $row->Festivity->DATE ) ) {
$festivity = new Festivity( $row->Festivity->NAME, $row->Festivity->DATE, $row->Festivity->COLOR, LitFeastType::FIXED, $row->Festivity->GRADE, $row->Festivity->COMMON );
Expand Down Expand Up @@ -2217,7 +2217,7 @@ private function createNewRegionalOrNationalFestivity( object $row ) : void {
$infoSource = RomanMissal::getName( $row->Metadata->missal );
}

$locale = strtoupper( explode('_', $this->LitSettings->Locale)[0] );
$locale = strtoupper( LitLocale::$PRIMARY_LANGUAGE );
$formattedDateStr = $this->LitSettings->Locale === LitLocale::LATIN ? ( $row->Festivity->DATE->format( 'j' ) . ' ' . LitMessages::LATIN_MONTHS[ (int)$row->Festivity->DATE->format( 'n' ) ] ) :
( $locale === 'EN' ? $row->Festivity->DATE->format( 'F jS' ) :
$this->dayAndMonth->format( $row->Festivity->DATE->format( 'U' ) )
Expand Down Expand Up @@ -2945,7 +2945,8 @@ private function generateResponse() {
}

private function prepareL10N() : string|false {
$baseLocale = strtolower( explode( '_', $this->LitSettings->Locale )[0] );
$baseLocale = $this->LitSettings->Locale !== LitLocale::LATIN ? strtolower( Locale::getPrimaryLanguage( $this->LitSettings->Locale ) ) : strtolower( LitLocale::LATIN );
LitLocale::$PRIMARY_LANGUAGE = $baseLocale;
$localeArray = [
$this->LitSettings->Locale . '.utf8',
$this->LitSettings->Locale . '.UTF-8',
Expand Down
2 changes: 2 additions & 0 deletions includes/enums/LitLocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
class LitLocale {
const LATIN = "LA";
public static array $values = [ "LA" ];
public static string $PRIMARY_LANGUAGE = "la";

public static function isValid( $value ) {
$AllAvailableLocales = array_filter(ResourceBundle::getLocales(''), function ($value) {
return strpos($value, 'POSIX') === false;
});
return in_array( $value, self::$values ) || in_array( $value, $AllAvailableLocales ) || in_array( strtolower( $value ), $AllAvailableLocales );
}

}

0 comments on commit 8f8cf67

Please sign in to comment.