Skip to content

Commit ad9a511

Browse files
committed
Fix return value for getConfiguredLanguages method that would cause an
exception in some instances. Fluency now boots the translation engine outside of the admin in case $fluency is used outside of the admin. Fix link rendering issue. Update CHANGELOG.md
1 parent 3aae420 commit ad9a511

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Fluency for ProcessWire Changelog
22

3+
## 1.0.5 2023-12-22
4+
5+
### _Critical update_, Bugfix upgrade recommended for all users.
6+
7+
- Fix return type error when Fluency attempts to get configured languages in some instances credit
8+
to @jacmaes for finding and reporting. Closes [issue 3](https://github.com/SkyLundy/Fluency/issues/3).
9+
- Fix bug where rendering langauge links appended an extra divider after list if a divider was
10+
passed to the method
11+
312
## 1.0.4 2023-12-19
413

514
### Enhancement, Documentation

Fluency.info.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
$info = [
88
'title' => 'Fluency',
9-
'version' => '103',
9+
'version' => '105',
1010
'href' => 'https://processwire.com/talk/topic/24567-fluency-integrated-deepl-powered-content-translation',
1111
'icon' => 'language',
1212
'summary' => 'The complete translation enhancement suite for ProcessWire.',

Fluency.module.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,19 @@ public function ready() {
119119
$this->fluencyConfig = (new FluencyConfig())->getConfigData();
120120
$this->translationCache = new TranslationCache();
121121
$this->engineLanguagesCache = new EngineLanguagesCache();
122+
$this->initializeTranslationEngine();
122123

123-
if (!$this->moduleShouldInit()) {
124+
if (!$this->moduleShouldInitInAdmin()) {
124125
return false;
125126
}
126127

127-
$this->initializeTranslationEngine();
128-
$this->insertPageAssets();
128+
$this->insertAdminAssets();
129129
}
130130

131131
/**
132132
* Determine if module should initialize
133133
*/
134-
private function moduleShouldInit(): bool {
134+
private function moduleShouldInitInAdmin(): bool {
135135
return $this->page->name !== 'login' && $this->userIsAuthorized();
136136
}
137137

@@ -159,7 +159,7 @@ private function userIsAuthorized(): bool {
159159
/**
160160
* Inserts required assets into admin pages on load.
161161
*/
162-
private function insertPageAssets(): void {
162+
private function insertAdminAssets(): void {
163163
if ($this->page->rootParent->id !== 2 ) {
164164
return;
165165
}
@@ -286,7 +286,9 @@ public function getConfiguredLanguages(): AllConfiguredLanguagesData {
286286
$engineInfo = $this->translationEngineInfo;
287287

288288
if (!$engineInfo?->configId) {
289-
return [];
289+
return AllConfiguredLanguagesData::fromArray([
290+
'languages' => []
291+
]);
290292
}
291293

292294
if (!is_null($this->configuredLanguages)) {
@@ -308,11 +310,7 @@ public function getConfiguredLanguages(): AllConfiguredLanguagesData {
308310

309311
$processWireLanguages = array_values($this->languages->getIterator()->getArray());
310312

311-
$languages = array_reduce(
312-
$processWireLanguages,
313-
$createConfiguredLanguage,
314-
[]
315-
);
313+
$languages = array_reduce($processWireLanguages, $createConfiguredLanguage, []);
316314

317315
// Create an array of Fluency configured language object from an array of ProcessWire languages
318316
return $this->configuredLanguages = AllConfiguredLanguagesData::fromArray([
@@ -411,7 +409,7 @@ public function getUnconfiguredLanguages(): array {
411409
*
412410
* #pw-group-Fluency-Module-Configuration-Data
413411
*
414-
* @return array Array with all data needed by client UI scripts.
412+
* @return stdClass All data needed by client UI scripts.
415413
*/
416414
public function getClientData(): stdClass {
417415
return (object) [
@@ -587,6 +585,7 @@ public function renderLanguageLinks(
587585
string $languageSource = 'fluency',
588586
): string {
589587
$languages = $this->getLanguagesForMarkup($languageSource);
588+
$divider && $divider = Markup::li(content: $divider, classes: 'divider');
590589

591590
$items = array_reduce($languages, function($tags, $language) use ($activeClass, $divider) {
592591
$tags[] = Markup::li(
@@ -597,7 +596,7 @@ classes: $language->isCurrentLanguage ? $activeClass : null,
597596
)
598597
);
599598

600-
$divider && $tags[] = Markup::li(content: $divider, classes: 'divider');
599+
$divider && $tags[] = $divider;
601600

602601
return $tags;
603602
}, []);

0 commit comments

Comments
 (0)