Skip to content

Commit

Permalink
Auto-detect user's language on PHP8.0 release page
Browse files Browse the repository at this point in the history
  • Loading branch information
takaram committed Oct 18, 2024
1 parent 45c3a94 commit 56cf5b1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
32 changes: 16 additions & 16 deletions releases/8.0/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@

include_once __DIR__ . '/../../include/prepend.inc';

const LANGUAGES = [
'en' => 'English',
'de' => 'Deutsch',
'es' => 'Español',
'fr' => 'Français',
'it' => 'Italiano',
'ja' => '日本語',
'nl' => 'Nederlands',
'pt_BR' => 'Português do Brasil',
'ru' => 'Русский',
'tr' => 'Türkçe',
'zh' => '简体中文',
'ka' => 'ქართული',
];

function common_header(string $description): void {
global $MYSITE;

Expand Down Expand Up @@ -35,21 +50,6 @@ function common_header(string $description): void {
}

function language_chooser(string $currentLang): void {
$LANGUAGES = [
'en' => 'English',
'de' => 'Deutsch',
'es' => 'Español',
'fr' => 'Français',
'it' => 'Italiano',
'ja' => '日本語',
'nl' => 'Nederlands',
'pt_BR' => 'Português do Brasil',
'ru' => 'Русский',
'tr' => 'Türkçe',
'zh' => '简体中文',
'ka' => 'ქართული',
];

// Print out the form with all the options
echo '
<form action="" method="get" id="changelang" name="changelang">
Expand All @@ -59,7 +59,7 @@ function language_chooser(string $currentLang): void {
';

$tab = ' ';
foreach ($LANGUAGES as $lang => $text) {
foreach (LANGUAGES as $lang => $text) {
$selected = ($lang === $currentLang) ? ' selected="selected"' : '';
echo $tab, "<option value='$lang'$selected>$text</option>\n";
}
Expand Down
13 changes: 10 additions & 3 deletions releases/8.0/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<?php

$_SERVER['BASE_PAGE'] = 'releases/8.0/index.php';
include __DIR__ . '/../../include/site.inc';
use phpweb\LangChooser;
use const releases\php80\LANGUAGES;

mirror_redirect('/releases/8.0/en.php');
$_SERVER['BASE_PAGE'] = 'releases/8.0/index.php';
require_once __DIR__ . '/common.php';
require_once __DIR__ . '/../../src/autoload.php';

$langChooser = new LangChooser(LANGUAGES, [], "", "");
[$lang,] = $langChooser->chooseCode("", "", $_SERVER['HTTP_ACCEPT_LANGUAGE']);

mirror_redirect("/releases/8.0/$lang.php");

0 comments on commit 56cf5b1

Please sign in to comment.