Skip to content

Commit

Permalink
Tracks loaded language files individually
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Stovell <[email protected]>
  • Loading branch information
Sesquipedalian committed Jan 29, 2024
1 parent 67301ee commit 45c2eb0
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions Sources/Lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,6 @@ public static function load(string $template_name, string $lang = '', bool $fata
$lang = User::$me->language ?? self::$default;
}

// Don't repeat this unnecessarily.
if (!$force_reload && isset(self::$already_loaded[$template_name]) && self::$already_loaded[$template_name] == $lang) {
return $lang;
}

if (empty(self::$dirs)) {
self::addDirs();
}
Expand All @@ -249,6 +244,11 @@ public static function load(string $template_name, string $lang = '', bool $fata
$template = 'General';
}

// Don't repeat this unnecessarily.
if (!$force_reload && isset(self::$already_loaded[$template]) && self::$already_loaded[$template] == $lang) {
continue;
}

$attempts = [];

foreach (self::$dirs as $dir) {
Expand All @@ -271,14 +271,6 @@ public static function load(string $template_name, string $lang = '', bool $fata

foreach ($attempts as $k => $file) {
if (file_exists($file[0] . '/' . $file[2] . '/' . $file[1] . '.php')) {
/**
* @var string $forum_copyright
* @var array $txt
* @var array $txtBirthdayEmails
* @var array $tztxt
* @var array $editortxt
* @var array $helptxt
*/

This comment has been minimized.

Copy link
@jdarwood007

jdarwood007 Jan 29, 2024

Member

I will put this back later. This fixed my IDE from complaining because we used those variables inside the code without defining them. Because they come from the file loading and then handled with ${$var} they are loaded, but it can't see them and assumes they are undefined.

This comment has been minimized.

Copy link
@Sesquipedalian

Sesquipedalian Jan 29, 2024

Author Member

Okay, fine. I have an aesthetic distaste this kind of cruft in seemingly random locations, but if you need it for your IDE to be happy, go ahead.

This comment has been minimized.

Copy link
@jdarwood007

jdarwood007 Jan 30, 2024

Member

Is there a way we can win for both? @tyrsson you have any hints for us here?

This comment has been minimized.

Copy link
@Sesquipedalian

Sesquipedalian Jan 30, 2024

Author Member

Does your IDE stop complaining if you replace the "// Load the strings into our properties" foreach loop with the following?

					self::$txt = array_merge(self::$txt, $txt ?? []);
					self::$txtBirthdayEmails = array_merge(self::$txtBirthdayEmails, $txtBirthdayEmails ?? []);
					self::$tztxt = array_merge(self::$tztxt, $tztxt ?? []);
					self::$editortxt = array_merge(self::$editortxt, $editortxt ?? []);
					self::$helptxt = array_merge(self::$helptxt, $helptxt ?? []);
// Include it!
// {DIR} / {locale} / {file} .php
require $file[0] . '/' . $file[2] . '/' . $file[1] . '.php';
Expand Down Expand Up @@ -366,10 +358,10 @@ public static function load(string $template_name, string $lang = '', bool $fata
}
$birthdayEmails = [];
}
}

// Remember what we have loaded, and in which language.
self::$already_loaded[$template_name] = $lang;
// Remember what we have loaded, and in which language.
self::$already_loaded[$template] = $lang;
}

// Return the language actually loaded.
return $lang;
Expand Down

0 comments on commit 45c2eb0

Please sign in to comment.