In what formats, such as JSON or YAML, could text be stored instead of PHP code for language translation in PHP websites?
To store text for language translation in PHP websites without using PHP code, text can be stored in formats such as JSON or YAML. These formats allow for easy organization of language translations and can be easily parsed and accessed in PHP.
// Example of storing language translations in a JSON file
// translations.json
{
"hello": {
"en": "Hello",
"fr": "Bonjour",
"es": "Hola"
},
"goodbye": {
"en": "Goodbye",
"fr": "Au revoir",
"es": "Adiós"
}
}
// PHP code to access translations
$translations = json_decode(file_get_contents('translations.json'), true);
echo $translations['hello']['en']; // Output: Hello
echo $translations['goodbye']['fr']; // Output: Au revoir
Keywords
Related Questions
- How can the PHP code be modified to handle the case where no option is selected in the dropdown menu?
- How can base64 encoding be utilized in PHP to properly save and handle email attachments?
- How can server settings in PHP/Apache2 affect the functionality of the "required" attribute in input fields, particularly in different versions of Internet Explorer?