Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created October 31, 2019 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/73c958852a98ad60827be4f8b1e9478d to your computer and use it in GitHub Desktop.
Save parzibyte/73c958852a98ad60827be4f8b1e9478d to your computer and use it in GitHub Desktop.
<?php
include_once "vendor/autoload.php";
use Symfony\Component\Translation\Loader\JsonFileLoader;
use Symfony\Component\Translation\Translator;
$idioma = "en";
$traductor = new Translator($idioma);
$traductor->addLoader("json", new JsonFileLoader());
$traductor->addResource("json", "idioma_es.json", "es");
$traductor->addResource("json", "idioma_en.json", "en");
$traductor->setFallbackLocales(["es"]); // Si no se encuentra el idioma, utilizamos es por defecto
$saludoTraducido = $traductor->trans("saludo");
echo $saludoTraducido;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment