Skip to content

Commit cfd4494

Browse files
Install: Fix language selection flow, i18n sync, and labels
1 parent 5bda238 commit cfd4494

File tree

5 files changed

+155
-19
lines changed

5 files changed

+155
-19
lines changed

assets/vue/AppInstaller.vue

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@
248248

249249
<script setup>
250250
import { useI18n } from "vue-i18n"
251-
import { onMounted, provide, ref } from "vue"
251+
import { onMounted, provide, ref, watch } from "vue"
252252
253253
import BaseAppLink from "./components/basecomponents/BaseAppLink.vue"
254254
import BaseButton from "./components/basecomponents/BaseButton.vue"
@@ -260,8 +260,8 @@ import Step5 from "./components/installer/Step5"
260260
import Step6 from "./components/installer/Step6"
261261
import Step7 from "./components/installer/Step7"
262262
263-
const { t } = useI18n()
264-
const installerData = ref(window.installerData)
263+
const { t, locale } = useI18n()
264+
const installerData = ref(window.installerData || {})
265265
266266
if (!installerData.value.stepData) {
267267
installerData.value.stepData = {
@@ -304,15 +304,63 @@ const steps = ref([
304304
},
305305
])
306306
307+
function refreshStepTitles() {
308+
steps.value = [
309+
{ step: 1, stepTitle: t("Installation language") },
310+
{ step: 2, stepTitle: t("Requirements") },
311+
{ step: 3, stepTitle: t("License") },
312+
{ step: 4, stepTitle: t("Database settings") },
313+
{ step: 5, stepTitle: t("Config settings") },
314+
{ step: 6, stepTitle: t("Show Overview") },
315+
{ step: 7, stepTitle: t("Install") },
316+
]
317+
}
318+
319+
function normalizeLocale(iso) {
320+
if (!iso) return "en_US"
321+
const low = String(iso).toLowerCase()
322+
if (low === "es" || low.startsWith("es_")) return "es"
323+
if (low === "en" || low.startsWith("en_")) return "en_US"
324+
return iso
325+
}
326+
307327
onMounted(() => {
308-
const txtIsExecutable = document.getElementById("is_executable")
328+
const initial = normalizeLocale(
329+
installerData.value.langIso || installerData.value.languageForm
330+
)
331+
332+
installerData.value.langIso = initial
309333
310-
if (!txtIsExecutable) {
311-
return
334+
if (initial && locale.value !== initial) {
335+
locale.value = initial
336+
refreshStepTitles()
312337
}
313338
314-
document
315-
.querySelectorAll("button")
316-
.forEach((button) => button.addEventListener("click", () => (txtIsExecutable.value = button.name)))
339+
const txtIsExecutable = document.getElementById("is_executable")
340+
if (!txtIsExecutable) return
341+
342+
const form = document.getElementById("install_form")
343+
if (form) {
344+
form
345+
.querySelectorAll("button")
346+
.forEach((button) =>
347+
button.addEventListener("click", () => (txtIsExecutable.value = button.name))
348+
)
349+
}
317350
})
351+
352+
watch(
353+
() => installerData.value?.langIso,
354+
(iso) => {
355+
const next = normalizeLocale(iso)
356+
if (next && next !== iso) {
357+
installerData.value.langIso = next
358+
return
359+
}
360+
if (next && locale.value !== next) {
361+
locale.value = next
362+
refreshStepTitles()
363+
}
364+
}
365+
)
318366
</script>

assets/vue/components/installer/Step1.vue

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
</template>
7575

7676
<script setup>
77-
import { inject } from "vue"
77+
import { inject, computed } from "vue"
7878
import { useI18n } from "vue-i18n"
7979
8080
import Message from "primevue/message"
@@ -84,9 +84,28 @@ import SectionHeader from "../layout/SectionHeader.vue"
8484
8585
import languages from "../../utils/languages"
8686
87-
const availableLanguages = languages.filter((language) => ["en_US", "fr_FR", "es", "de", "nl", "ar"].includes(language.isocode))
88-
8987
const { t } = useI18n()
90-
9188
const installerData = inject("installerData")
89+
90+
const ALLOWED = ["ar", "de", "en_US", "es", "fr_FR", "he_IL", "it", "nl", "pt_BR", "sl_SI"]
91+
92+
const availableLanguages = computed(() => {
93+
const allow = new Set(ALLOWED.map((x) => x.toLowerCase()))
94+
const list = languages
95+
.filter((l) => allow.has(l.isocode.toLowerCase()))
96+
.map((l) => ({
97+
isocode: l.isocode,
98+
original_name: l.original_name || l.english_name || l.isocode,
99+
}))
100+
const iso = installerData?.value?.langIso
101+
if (iso && !list.some((l) => l.isocode.toLowerCase() === String(iso).toLowerCase())) {
102+
const found = languages.find((l) => l.isocode.toLowerCase() === String(iso).toLowerCase())
103+
list.unshift({
104+
isocode: iso,
105+
original_name: found?.original_name || found?.english_name || iso,
106+
})
107+
}
108+
109+
return list
110+
})
92111
</script>

assets/vue/utils/languages.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,6 @@ export default [
401401
english_name: "spanish",
402402
isocode: "es",
403403
available: 1,
404-
405404
format: "title last_name first_name",
406405
sort_by: "last_name",
407406
},

public/main/install/index.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@
7070
Container::$session = new HttpSession();
7171

7272
require_once 'install.lib.php';
73-
$installationLanguage = 'en_US';
74-
7573
$httpRequest = Request::createFromGlobals();
74+
$installationLanguage = 'en_US';
7675

77-
if ($httpRequest->request->get('language_list')) {
76+
$langParam = $httpRequest->get('language_list');
77+
if ($langParam !== null && $langParam !== '') {
7878
$search = ['../', '\\0'];
79-
$installationLanguage = str_replace($search, '', urldecode($httpRequest->request->get('language_list')));
79+
$installationLanguage = str_replace($search, '', urldecode($langParam));
8080
ChamiloSession::write('install_language', $installationLanguage);
8181
} elseif (ChamiloSession::has('install_language')) {
8282
$installationLanguage = ChamiloSession::read('install_language');
@@ -654,7 +654,7 @@
654654

655655
'upgradeFromVersion' => $upgradeFromVersion,
656656

657-
'langIso' => api_get_language_isocode(),
657+
'langIso' => $installationLanguage,
658658

659659
'formAction' => api_get_self().'?'.http_build_query([
660660
'running' => 1,
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/* For licensing terms, see /license.txt */
6+
7+
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
8+
9+
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
10+
use Doctrine\DBAL\Schema\Schema;
11+
12+
final class Version20250926142500 extends AbstractMigrationChamilo
13+
{
14+
public function getDescription(): string
15+
{
16+
return "Fix mis-labeled 'Português do Brasil': change isocode from pt_PT to pt_BR only when pt_PT appears twice and pt_BR doesn't exist.";
17+
}
18+
19+
public function up(Schema $schema): void
20+
{
21+
// Convert the Brazilian row from pt_PT -> pt_BR
22+
// Only do it when there are at least 2 rows with isocode 'pt_PT' and there's no existing 'pt_BR'
23+
$this->addSql("
24+
UPDATE language l
25+
JOIN (
26+
SELECT id
27+
FROM language
28+
WHERE isocode = 'pt_PT'
29+
AND (
30+
original_name = 'Português do Brasil'
31+
OR english_name LIKE '%Brazil%'
32+
OR english_name LIKE '%brazilian%'
33+
)
34+
LIMIT 1
35+
) b ON b.id = l.id
36+
SET l.isocode = 'pt_BR'
37+
WHERE
38+
(SELECT COUNT(*) FROM language WHERE isocode = 'pt_PT') > 1
39+
AND (SELECT COUNT(*) FROM language WHERE isocode = 'pt_BR') = 0
40+
");
41+
42+
// Normalize english_name for Brazilian row (optional, harmless if already set)
43+
$this->addSql("
44+
UPDATE language
45+
SET english_name = 'brazilian portuguese'
46+
WHERE isocode = 'pt_BR'
47+
AND (english_name IS NULL OR english_name = '' OR english_name LIKE '%brazil%')
48+
");
49+
}
50+
51+
public function down(Schema $schema): void
52+
{
53+
// Revert only if it looks like we performed the change (avoid clobbering a valid dataset).
54+
$this->addSql("
55+
UPDATE language l
56+
JOIN (
57+
SELECT id
58+
FROM language
59+
WHERE isocode = 'pt_BR'
60+
AND (
61+
original_name = 'Português do Brasil'
62+
OR english_name LIKE '%brazil%'
63+
)
64+
LIMIT 1
65+
) b ON b.id = l.id
66+
SET l.isocode = 'pt_PT'
67+
WHERE (SELECT COUNT(*) FROM language WHERE isocode = 'pt_PT') = 1
68+
");
69+
}
70+
}

0 commit comments

Comments
 (0)