Skip to content

Instantly share code, notes, and snippets.

@nicklasos
Last active August 29, 2015 14:00
Show Gist options
  • Save nicklasos/11252284 to your computer and use it in GitHub Desktop.
Save nicklasos/11252284 to your computer and use it in GitHub Desktop.
<?php
/**
* Depend from csv_to_array and get_in functions
* @link https://gist.github.com/nicklasos/11251754
* @link https://gist.github.com/nicklasos/9206376
*/
function t($phrase)
{
static $dictionary;
// Silex\Application instance
global $app;
if (!$dictionary) {
$file = csv_to_array(realpath(__DIR__ . "/..") . '/translations.csv');
$dictionary = [];
foreach ($file as $t) {
$dictionary[$t['en']] = $t;
}
}
$translated = get_in($dictionary, [$phrase, $app['language']], $phrase);
return strlen($translated) ? $translated : $phrase;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment