1
I have a website on PHP and I’m translating it as follows:
<?php
require_once("includes/translate.php");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?php echo $site_title ?></title>
</head>
<body>
<div id="welcome"><?php echo $div_welcome; ?></div>
</body>
</html>
The require
contains the file translate.php
:
<?php
$language = $_GET['lang'];
if ($language == "pt") {
insira o código aqui
$site_title = "Blog do Antonny";
$div_welcome = "Seja bem-vindo(a) no meu Blog";
}
if ($language == "es") {
$site_title = "Blog de Antonny";
$div_welcome = "Bienvenido a mi Blog";
}
if ($language == "en") {
$site_title = "Antonny's Blog";
$div_welcome = "Welcome to my Blog";
}
?>
And in the translate.php
all variables are configured with the translations for each language. This was the most dynamic way I could think of, is there anything that can make this translation more dynamic? This is an incorrect way of doing?
Have you seen this question here on the website? How to translate a website into PHP
– Raizant
If it’s a few words, I don’t see any drawbacks, but if this Translate.php file gets huge I would create 3 files, langPT.php, Langes.php and Langen.php. Hence if ($language == "pt") { require_once("includes/langPT.php"); } elseif ($language == "es"){require_once("includes/Langes.php"); .....
– user60252
Possible duplicate of How to translate a website into PHP?
– rubStackOverflow