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