Has a topical that was answered using PHP:
Step 1: Set up a folder tree structure like this:
Linguagens
-en
-lang.en.php
-fr
-lang.fr.php
-de
-lang.de.php
continue making new folders with all the other languages you want.
Step 2: Create a folder with the language files, example: linguagens/en/lang.en.php
<?php
$lang['label'] = 'Value for this label';
$lang['firstname'] = 'First Name';
$lang['lastname'] = 'Last Name';
$lang['phone'] = 'Phone';
// ETC
?>
You would repeat this to any other language, for example, linguagens/fr/lang.fr.php
. NOTE always after the $lang
the names remain the same in English.
<?php
$lang['label'] = 'Valeur pour ce label';
$lang['firstname'] = 'Prénom';
$lang['lastname'] = 'Nom de famille';
$lang['phone'] = 'Téléphone';
// ETC
?>
Step 3: Check if the user has requested a language change, using a url variable.
<?php
// Start a Session, You might start this somewhere else already.
session_start();
// What languages do we support
$available_langs = array('en','fr','de');
// Set our default language session
$_SESSION['lang'] = 'en';
if(isset($_GET['lang']) && $_GET['lang'] != ''){
// check if the language is one we support
if(in_array($_GET['lang'], $available_langs))
{
$_SESSION['lang'] = $_GET['lang']; // Set session
}
}
// Include active language
include('linguagens/'.$_SESSION['lang'].'/lang.'.$_SESSION['lang'].'.php');
?>
Step 4: You can access your language parts so and would change based on the uploaded language file.
<?php
echo $lang['firstname'];
?>
Try to give more details so that we can help you, example code you have already done or will create the site from scratch.. whether to use wordpress?
– Tmc
Have you created any code? Don’t expect anyone to code for you. Be more specific. See [tour] for more details.
– Renato Junior
Yes, I just edited the question rsrs, I’m learning to use the tool still, little by little. In editing I included the link with the code. Abs.
– Felipe Braz
@Felipebraz Put the code right here, imagine if the site you passed the link with the code is out of the air or is deleted? Ideally you put the code right here, so the site is more organized and easier for others who face the same problem.
– Renato Junior
@RORSCHACH I understand, I apologize because I couldn’t put the link here. I haven’t had time to understand all the features of Stack, but the idea is to learn and go beyond (-:
– Felipe Braz