[PHP-WEBMASTER] [web-php] master: Auto-detect user's language on PHP8.0-8.3 release pages (#1098)

Author: Takuya Aramaki (takaram)
Committer: GitHub (web-flow)
Pusher: saundefined
Date: 2024-10-18T17:50:53+03:00

Commit: Auto-detect user's language on PHP8.0-8.3 release pages (#1098) · php/web-php@a20418e · GitHub
Raw diff: https://github.com/php/web-php/commit/a20418eb354aff795e3d53775e70eca5f3c2ae96.diff

Auto-detect user's language on PHP8.0-8.3 release pages (#1098)

Changed paths:
  M releases/8.0/common.php
  M releases/8.0/index.php
  M releases/8.1/common.php
  M releases/8.1/index.php
  M releases/8.2/common.php
  M releases/8.2/index.php
  M releases/8.3/common.php
  M releases/8.3/index.php

Diff:

diff --git a/releases/8.0/common.php b/releases/8.0/common.php
index fd44ea02db..47fbe8d9c2 100644
--- a/releases/8.0/common.php
+++ b/releases/8.0/common.php
@@ -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;

@@ -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">
@@ -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";
     }
diff --git a/releases/8.0/index.php b/releases/8.0/index.php
index 6dc7567c99..b9084dd9e0 100644
--- a/releases/8.0/index.php
+++ b/releases/8.0/index.php
@@ -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");
diff --git a/releases/8.1/common.php b/releases/8.1/common.php
index ac4a1ad5c1..eca60d7508 100644
--- a/releases/8.1/common.php
+++ b/releases/8.1/common.php
@@ -6,6 +6,17 @@

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

+const LANGUAGES = [
+ 'en' => 'English',
+ 'es' => 'Español',
+ 'de' => 'Deutsch',
+ 'pt_BR' => 'Português do Brasil',
+ 'ru' => 'Русский',
+ 'zh' => '简体中文',
+ 'ka' => 'ქართული',
+ 'ja' => '日本語',
+];
+
function common_header(string $description): void {
     global $MYSITE;

@@ -35,17 +46,6 @@ function common_header(string $description): void {
}

function language_chooser(string $currentLang): void {
- $LANGUAGES = [
- 'en' => 'English',
- 'es' => 'Español',
- 'de' => 'Deutsch',
- 'pt_BR' => 'Português do Brasil',
- 'ru' => 'Русский',
- 'zh' => '简体中文',
- 'ka' => 'ქართული',
- 'ja' => '日本語',
- ];
-
     // Print out the form with all the options
     echo '
       <form action="" method="get" id="changelang" name="changelang">
@@ -55,7 +55,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";
     }
diff --git a/releases/8.1/index.php b/releases/8.1/index.php
index 6119a964c4..2b07496775 100644
--- a/releases/8.1/index.php
+++ b/releases/8.1/index.php
@@ -1,6 +1,13 @@
<?php

- $_SERVER['BASE_PAGE'] = 'releases/8.1/index.php';
-include __DIR__ . '/../../include/site.inc';
+use phpweb\LangChooser;
+use const releases\php81\LANGUAGES;

-mirror_redirect('/releases/8.1/en.php');
+$_SERVER['BASE_PAGE'] = 'releases/8.1/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.1/$lang.php");
diff --git a/releases/8.2/common.php b/releases/8.2/common.php
index a1bafdc434..77ea2b8b57 100644
--- a/releases/8.2/common.php
+++ b/releases/8.2/common.php
@@ -6,6 +6,17 @@

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

+const LANGUAGES = [
+ 'en' => 'English',
+ 'es' => 'Español',
+ 'de' => 'Deutsch',
+ 'fr' => 'Français',
+ 'pt_BR' => 'Português do Brasil',
+ 'ru' => 'Russian',
+ 'ja' => '日本語',
+ 'zh' => '简体中文',
+];
+
function common_header(string $description): void {
     global $MYSITE;

@@ -35,17 +46,6 @@ function common_header(string $description): void {
}

function language_chooser(string $currentLang): void {
- $LANGUAGES = [
- 'en' => 'English',
- 'es' => 'Español',
- 'de' => 'Deutsch',
- 'fr' => 'Français',
- 'pt_BR' => 'Português do Brasil',
- 'ru' => 'Russian',
- 'ja' => '日本語',
- 'zh' => '简体中文',
- ];
-
     // Print out the form with all the options
     echo '
       <form action="" method="get" id="changelang" name="changelang">
@@ -55,7 +55,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";
     }
diff --git a/releases/8.2/index.php b/releases/8.2/index.php
index 4c6a52ae1d..8c63625ee2 100644
--- a/releases/8.2/index.php
+++ b/releases/8.2/index.php
@@ -1,6 +1,13 @@
<?php

- $_SERVER['BASE_PAGE'] = 'releases/8.2/index.php';
-include __DIR__ . '/../../include/site.inc';
+use phpweb\LangChooser;
+use const releases\php82\LANGUAGES;

-mirror_redirect('/releases/8.2/en.php');
+$_SERVER['BASE_PAGE'] = 'releases/8.2/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.2/$lang.php");
diff --git a/releases/8.3/common.php b/releases/8.3/common.php
index 9c7256bcb4..f0d3a552b9 100644
--- a/releases/8.3/common.php
+++ b/releases/8.3/common.php
@@ -6,6 +6,17 @@

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

+const LANGUAGES = [
+ 'en' => 'English',
+ 'es' => 'Español',
+ 'de' => 'Deutsch',
+ 'ru' => 'Russian',
+ 'zh' => '简体中文',
+ 'pt_BR' => 'Português do Brasil',
+ 'ja' => '日本語',
+ 'uk' => 'Українська',
+];
+
function common_header(string $description): void {
     global $MYSITE;

@@ -35,17 +46,6 @@ function common_header(string $description): void {
}

function language_chooser(string $currentLang): void {
- $LANGUAGES = [
- 'en' => 'English',
- 'es' => 'Español',
- 'de' => 'Deutsch',
- 'ru' => 'Russian',
- 'zh' => '简体中文',
- 'pt_BR' => 'Português do Brasil',
- 'ja' => '日本語',
- 'uk' => 'Українська',
- ];
-
     // Print out the form with all the options
     echo '
       <form action="" method="get" id="changelang" name="changelang">
@@ -55,7 +55,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";
     }
diff --git a/releases/8.3/index.php b/releases/8.3/index.php
index 3b56a21417..cd5c031a11 100644
--- a/releases/8.3/index.php
+++ b/releases/8.3/index.php
@@ -1,6 +1,13 @@
<?php

- $_SERVER['BASE_PAGE'] = 'releases/8.3/index.php';
-include __DIR__ . '/../../include/site.inc';
+use phpweb\LangChooser;
+use const releases\php83\LANGUAGES;

-mirror_redirect('/releases/8.3/en.php');
+$_SERVER['BASE_PAGE'] = 'releases/8.3/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.3/$lang.php");