Created
January 18, 2018 10:41
-
-
Save gerardreches/ed0a2d14c6638f3fdfc1bb3190afd490 to your computer and use it in GitHub Desktop.
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
# HEAD.BLADE.PHP | |
<script> | |
<?php | |
// copy all translations from /resources/lang/CURRENT_LOCALE/* to global JS variable | |
$lang_files = File::files(resource_path() . '/lang/' . App::getLocale()); | |
$exclude_files = ['changelog']; | |
$translations = []; | |
foreach ($lang_files as $f) | |
{ | |
$filename = pathinfo($f)['filename']; | |
if(in_array($filename, $exclude_files)){ | |
continue; | |
} | |
$translations[$filename] = trans($filename); | |
} | |
?> | |
window.translations = {!! json_encode($translations) !!}; | |
</script> | |
# APP.JS | |
// Put that before your components registration. | |
Vue.mixin({ | |
methods: { | |
__: function (key) { | |
return _.get(window.translations, key, key); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment