Last active
April 18, 2016 18:22
-
-
Save joubertredrat/211dbd16d0194af5af17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class App { | |
/** | |
* Translates string. | |
* Examples: | |
* echo \App::translate('Páginas'); | |
* > Pages | |
* echo \App::translate('Oi %s, é Domingo! Seu e-mail %s está cheio', 'Dev', 'lol@dev.us'); | |
* > Hi Dev, is Sunday! Your mail lol@dev.us is full | |
* echo \App::translate('Boa tarde'); | |
* > Boa tarde <= hasn't been translated because they do not have a translation for this word | |
* echo \App::translate('Ontem'); | |
* > Yesterday | |
* | |
* @param string $text text to translate. | |
* @param string replaces | |
* @return string | |
* @todo This is experimental | |
*/ | |
public static function translate($text) | |
{ | |
$replace = func_get_args(); | |
unset($replace[0]); | |
$ci =& get_instance(); | |
$session = $ci->auth->get_session(); | |
$lang = $session['user_idioma']; | |
if ($lang != LANGUAGE_DEFAULT) { | |
$ci->lang->load('app', LANGUAGE_DEFAULT); | |
$key = array_search($text, $ci->lang->language); | |
$ci->lang->load('app', $lang); | |
if ($ci->lang->line($key)) | |
$text = $ci->lang->line($key); | |
} | |
if ($replace) | |
$text = vsprintf($text, $replace); | |
return $text; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$lang['pages'] = 'Páginas'; | |
$lang['saudation'] = 'Oi %s, é Domingo! Seu e-mail %s está cheio'; | |
$lang['random_index'] = 'Ontem'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$lang['pages'] = 'Pages'; | |
$lang['saudation'] = 'Hi %s, is Sunday! Your mail %s is full'; | |
$lang['random_index'] = 'Yesterday'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment