Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 8. Uncaught ReferenceError: Lang is not defined #155

Open
joantp opened this issue Nov 30, 2020 · 4 comments
Open

Laravel 8. Uncaught ReferenceError: Lang is not defined #155

joantp opened this issue Nov 30, 2020 · 4 comments

Comments

@joantp
Copy link

joantp commented Nov 30, 2020

I don't know where this error comes from and how to solve it.

I'have added Mariuzzo\LaravelJsLocalization\LaravelJsLocalizationServiceProvider::class in config/app.php and I am able to generate messages.js.

Please help! :)

@tebeso
Copy link

tebeso commented Sep 23, 2021

with the command php:artisan lang:js , it generates a file called messages.js in your public folder (default setting). This file does not only contain your translations, but also lang.js itself. All you have to do is include this into your layout file like this:

<script src="{{ asset('messages.js') }}"></script>

and then use it somewhere in your code like this: Lang.get('whatever.some_key');

@hasan-ozbey
Copy link

any REAL solutions??

@Mult1Hunter
Copy link

Mult1Hunter commented Jul 13, 2022

I fixed this by changing file type to json, and then running php artisan lang:js --json

In app.js you have to manually load Lang lib, and set localised json as massages:

import Lang from 'lang.js';
import translations from './vue-translations.json'; // path to your json file

let lang = new Lang();
lang.setFallback('en');
lang.setMessages(translations);

// You can optionally set different user locale based on session or url param f.e.:
lang.setLocale(window.location.href.split(/[/]/)[3].toLowerCase());

Vue.filter('trans', (...args) => {
    return lang.get(...args);
});

export default lang;

new Vue({
    router,
    lang, // <-- dont forget to include it
    store,
    render: h => h(App),
}).$mount('#app');

This is probably not the best implementation or be perfect fit for you, but it's a start. I run around 20 different languages for my Vue frontend with this config.

@AbdoulBaguiM
Copy link

@Mult1Hunter How can I implement your solution with React ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants