xiCO2k / laravel-vue-i18n

Allows to connect your `Laravel` Framework translation files with `Vue`.
MIT License
598 stars 49 forks source link

change locale(question) #54

Closed merkBalevor closed 2 years ago

merkBalevor commented 2 years ago

Good day, i try change locale like this: import { loadLanguageAsync } from 'laravel-vue-i18n';

<template>
    <div>{{ $t('Welcome!') }}</div>
    <button @click="loadLanguageAsync('pt')">Change to Portuguese Language</button>
</template>

And i recive this error: Uncaught TypeError: _ctx.loadLanguageAsync is not a function Can you please tell me how to change the language?

xiCO2k commented 2 years ago

Hey @merkBalevor cant find any issue with that code, can you share more info on that file code?

Thanks

merkBalevor commented 2 years ago

I'm studying Vue and trying to make a multilingual application, I can't figure out how to do the language change? The documentation says it:

import { loadLanguageAsync } from 'laravel-vue-i18n';

<template>
    <div>{{ $t('Welcome!') }}</div>
    <button @click="loadLanguageAsync('pt')">Change to Portuguese Language</button>
</template>

, but I don't understand how use it, What code to use in the method? I will be very grateful to you if you show an example of a method for changing the language.

My app.blade.php

<html lang="{{str_replace('_', '-', app()->getLocale())}}">
My langs: en.json | en.json

My vue.js

@click="switchLanguageTo('en')"
import {i18nVue, loadLanguageAsync} from 'laravel-vue-i18n';
methods: {
    switchLanguageTo(lang) {
        // here i dont understand 
        loadLanguageAsync(lang);
        //  here i dont understand 
    },
},
xiCO2k commented 2 years ago

Hey @merkBalevor, you can check out this repo: https://github.com/xiCO2k/laravel-vue-i18n-webpack-app

I just commited an example of the change lang, any more help let me know.

merkBalevor commented 2 years ago

Thanks, you very help me, its work! I will be 10 times more grateful if it is possible not to reset the language after reloading the page, i.e. save to local storage

xiCO2k commented 2 years ago

So for that you can have a method to switch the locale and then on there you can save to the localStorage and also run the loadLanguageAsync.

I would basically do that.

On Thu, Aug 11, 2022 at 7:34 PM merkBalevor @.***> wrote:

Thanks, you very help me, its work! I will be 10 times more grateful if it is possible not to reset the language after reloading the page, i.e. save to local storage

— Reply to this email directly, view it on GitHub https://github.com/xiCO2k/laravel-vue-i18n/issues/54#issuecomment-1212352497, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGI6MH5MCMK4DWJIHNJXRDVYVBSVANCNFSM56CXPSRQ . You are receiving this because you modified the open/close state.Message ID: @.***>