Translate website that is already developed [closed]

0

I have a website of a client that is already developed and running normally, but now the client wants the site in English and Spanish, here comes the doubt, roughly, I could duplicate the files and translate the whole site, but this is very archaic.

Here's the question, is there any easy way to translate this site? The backend is in PHP with no framework.

Note: I already have all the content in English and Spanish

    
asked by anonymous 17.09.2015 / 16:01

2 answers

2

You can use a file that contains a array() containing the content in the respective languages.

Example

$varArray = [

   'pt'     => [
       'titulo' => 'Produtos',
   ];

   'en'     => [
       'titulo' => 'Products',
   ];

   'en'     => [
       'titulo' => 'Produtos',
   ];

]

On the page you will have to have the language in session and the include of the file.

include "traducao.php";
$idioma = $_SESSION['idioma']; # pt, en ou es

From here on you will translate:

<h2>
    <?php 
        echo $varArray[$idioma]['titulo'];
    ?>
</h2>
    
17.09.2015 / 16:12
5

You can do this in two ways

The hard work: Create a sheet with all possible variables in a library and translate the content using an .ini file and use parse_ini_file() : link

An example usage: translate.ini

;arquivo de traduções
[pt-br]
;tradução português
title = 'Olá Mundo'
text = 'Seu texto entra aqui'
data_formato = 'd/m/Y'
[en]
;english translate
title = 'Hello World'
text = 'Your text enter here'
data_formato = 'm/d/Y'
[es]
;traducion español
title = 'Hola Mundo';
text = 'Su texto va aquí'
data_formato = 'd/m/Y'

In PHP:

<?php
    $translate = parse_ini_file('translate.ini', true);

    $lang = 'pt-br';

    $titulo = $translate[$lang]['title'];
    $texto = $translate[$lang]['text'];
?>

Quick: use the Google API:
link
link
RESTful: link

    
17.09.2015 / 16:24