Skip to content

Instantly share code, notes, and snippets.

@renalpha
Created July 15, 2019 08:34
Show Gist options
  • Save renalpha/1aed0252f38ba90c8f07271976b34202 to your computer and use it in GitHub Desktop.
Save renalpha/1aed0252f38ba90c8f07271976b34202 to your computer and use it in GitHub Desktop.
Vuejs with localisation
const _ = require('lodash');
Vue.prototype.trans = string => _.get(window.i18n, string);
const app = new Vue({
el: '#app',
});
Route::get('/js/lang.js', function () {
$strings = Cache::rememberForever('lang.js', function () {
$lang = config('app.locale');
$files = glob(resource_path('lang/' . $lang . '/*.php'));
$strings = [];
foreach ($files as $file) {
$name = basename($file, '.php');
$strings[$name] = require $file;
}
return $strings;
});
header('Content-Type: text/javascript');
echo('window.i18n = ' . json_encode($strings) . ';');
exit();
})->name('assets.lang');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment