Skip to content

Instantly share code, notes, and snippets.

@mykiwi
Last active August 13, 2019 17:44
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 mykiwi/1b7cda226efdb9020551b467c702c37f to your computer and use it in GitHub Desktop.
Save mykiwi/1b7cda226efdb9020551b467c702c37f to your computer and use it in GitHub Desktop.
<?php
<<<CONFIG
packages:
- "twig/twig: ^2"
- "twig/intl-extra: 3.x-dev"
- "symfony/var-dumper: ^4"
CONFIG;
$loader = new \Twig\Loader\ArrayLoader([
'ok_fr' => "{{ 'fr'|language_name }}\n",
'ok_fr_CA' => "{{ 'fr_CA'|language_name }}\n",
'ko_fr_FR' => "{{ 'fr_FR'|language_name }}\n",
]);
$twig = new \Twig\Environment($loader);
$twig->addExtension(new \Twig\Extra\Intl\IntlExtension());
echo $twig->render('ok_fr'); // French
echo $twig->render('ok_fr_CA'); // Canadian French
try {
echo $twig->render('ko_fr_FR');
} catch (\Exception $e) {
dump($e);
}
/*
Twig\Error\RuntimeError^ {#159
-lineno: 1
-name: "ko_fr_FR"
-rawMessage: "An exception has been thrown during the rendering of a template ("Couldn't read the indices [Names][fr_FR] for the locale "en_US" in "/path/vendor/symfony/intl/Resources/data/languages". The indices also couldn't be found for the fallback locale(s) "en", "root".")."
-sourcePath: ""
-sourceCode: ""
#message: "An exception has been thrown during the rendering of a template ("Couldn't read the indices [Names][fr_FR] for the locale "en_US" in "/path/vendor/symfony/intl/Resources/data/languages". The indices also couldn't be found for the fallback locale(s) "en", "root".") in "ko_fr_FR" at line 1."
#code: 0
#file: "/path/vendor/twig/twig/src/Template.php"
#line: 421
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment