Created
July 15, 2019 08:34
-
-
Save renalpha/1aed0252f38ba90c8f07271976b34202 to your computer and use it in GitHub Desktop.
Vuejs with localisation
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
const _ = require('lodash'); | |
Vue.prototype.trans = string => _.get(window.i18n, string); | |
const app = new Vue({ | |
el: '#app', | |
}); |
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
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