Translate site that is already developed

Asked

Viewed 143 times

0

I have a site 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, however this is very archaic.

Is there any easy way to translate this site? The backend is in PHP and no framework.

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

  • 2

    is too wide. without seeing the system is impossible to opine anything.

2 answers

5

You can do it two ways

The laborious: Create a sheet with all possible variables in a library and translate the contents using a file of type . ini and use parse_ini_file(): http://php.net/manual/en/function.parse-ini-file.php

An example of use: 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'];
?>

The quick: use the Google API:
https://cloud.google.com/translate/docs
https://translate.google.com/manager/website/
Restful: https://cloud.google.com/translate/docs/reference/rest

  • Po vlww I’ll take a look here =D

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 archive.

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

Hence in the place you will translate:

<h2>
    <?php 
        echo $varArray[$idioma]['titulo'];
    ?>
</h2>
  • 1

    Thank you very much!!! I’ll try here =D

Browser other questions tagged

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