Translate PHP site with strings via require

Asked

Viewed 245 times

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?

  • 1

    Have you seen this question here on the website? How to translate a website into PHP

  • 2

    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"); .....

  • Possible duplicate of How to translate a website into PHP?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.