Skip to content

Instantly share code, notes, and snippets.

@gerardreches
Created January 18, 2018 10:41
Show Gist options
  • Save gerardreches/ed0a2d14c6638f3fdfc1bb3190afd490 to your computer and use it in GitHub Desktop.
Save gerardreches/ed0a2d14c6638f3fdfc1bb3190afd490 to your computer and use it in GitHub Desktop.
# 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