Created
June 3, 2012 10:46
-
-
Save nerdmom/2863000 to your computer and use it in GitHub Desktop.
Language Laravel Blade Extension
This file contains hidden or 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 | |
/** | |
* Compiles language strings | |
* Standalone: | |
* {{"some.string_here"}} = <?php echo \Lang::line("some.string_here")->get(); ?> | |
* Not Standalone (ie, within a function,etc) | |
* {"some.string_Here"} = \Lang::line('some.string_here')->get() | |
* @param string Template | |
* @return string Template | |
**/ | |
Blade::extend(function($value) { | |
$func = function($template,$regexed,$l=null,$r=null) { | |
$c = count($regexed[0]); | |
// 0 = matched string 1 = language line | |
for ($i=0; $i < $c; $i++) | |
{ | |
$str = '\\Lang::line('.$regexed[1][$i].')->get()'; | |
$template = str_replace($regexed[0][$i], $l.$str.$r, $template); | |
} | |
return $template; | |
}; | |
$regex = '([\"|\'].+[\"|\'])'; | |
preg_match_all('/\{\{'.$regex.'\}\}/mU', $value, $matches); | |
$value = $func($value,$matches,'{{','}}'); | |
preg_match_all('/\{'.$regex.'\}/mU', $value, $matches1); | |
$value = $func($value,$matches1); | |
return $value; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment