How do you structure `en.js` or `ja.js` files for lazy loading in vue-i18n?

What is the correct format for lazy loading en.js or ja.js? The code below is not working:

// en.js
export default
    {
        title: 'Title',
        greeting: 'How are you'
    };

and

import Vue from 'vue';
import InventoryList from "./components/InventoryList";
import VueI18n from 'vue-i18n';
import messages from 'lang/fa';

Vue.use(VueI18n);

const i18n = new VueI18n({
    locale: 'en',
    fallbackLocale: 'en',
    messages
});

Vue.component('inventory-list', InventoryList);

const app = new Vue({
    i18n,
    el: '#app',
});

Could you please advise on the correct approach?

Answer №1

To properly set up your VueI18n instance, make sure you import all language files and assign them to the appropriate key in the initialization call.

Here's an example of how to do it:

import french from './lang/french' // relative path
import spanish from './lang/spanish' // relative path
...
const i18n = new VueI18n({
 locale: 'en',
 fallbackLocale: 'en',
 messages: {
  english,
  french,
  spanish
 }
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The onChange method in React is failing to execute within the component

I am having trouble overriding the onChange method in a component. It seems like the method is not triggering on any DOM events such as onChange, onClick, or onDblClick. Below are the snippets of code where the component is rendered and the component itsel ...

Activate a function when the v-data-table in Vuetify is expanded and then collapsed

While trying to create a v-data-table, I came across some odd behavior when monitoring the expanded.sync value. The first layer's expanded.sync value seems normal, but the second layer's expanded.sync has three consecutive identical records. I w ...

The JavaScript creates a select box, but the value does not get sent when the form is submitted

When a user selects a value from the first select box, a second select box is dynamically created using JavaScript. This JS triggers a PHP file to query a MYSQL database for relevant items based on the initial selection. The issue I am facing is that the ...

Is implementing a proxy middleware recommended for production use?

After separating my frontend and backend, I am currently configuring the frontend part. One step I have taken is using a proxy middleware to handle API requests to the backend in production. However, I have some concerns about whether this setup could pote ...

Error! The function worker.recognize(...).progress is throwing an error. Any ideas on how to resolve this

Here is the code snippet: //Imports const express = require('express'); const app = express(); const fs = require("fs"); const multer = require('multer'); const { createWorker } = require("tesseract.js"); co ...

I am experiencing difficulties with displaying my array of JSX elements in the render function of my ReactJS application. What could be

I am currently working on a trivia application and encountering an issue with inserting an updated array of "Choice" elements for each question. Despite my efforts, whenever I attempt to insert an array of JSX elements, the array appears blank. This is qui ...

AngularJS Login Popup with SpringSecurity

I have successfully integrated spring security with my AngularJS webpage utilizing Rest API. However, I am facing an issue where every time I attempt to log in using the rest api from my customized login page, it prompts me for the login credentials in a p ...

Asynchronous Task paired with JSON, the onSuccess method fails to provide any returns

Here is my query: I'm facing an issue with the code in my AsyncTask function that fetches values from a JSONObject through a webservice. Despite successfully filling a List with data from the JSON in the onSuccess method, the "result" turns out to be ...

Only the initial AJAX request is successful, while subsequent requests fail to execute

I am facing an issue with multiple inputs, each requiring a separate AJAX request. < script type = "text/javascript" > $(document).ready(function() { $("#id_1").change(function() { var rating1 = $(this).v ...

Utilizing Vue and Nuxt to Filter JSON Data by Category using Content Api

Currently, I'm working on assembling a portfolio within the Nuxt framework. The portfolio's content is sourced from GoogleSheets, and using the GoogleSheets API, I created a portfolio.json file stored in the Nuxt/Content directory. So far, I have ...

Displaying a Next.js component depending on the environment setting

Having trouble displaying a maintenance message to users based on an environment value. In my .env.local file, I have the following value set: NEXT_PUBLIC_SHOW_MAINTENANCE=true This is how my page is structured: const Index = () => { const showMai ...

Is there a way to asynchronously load image src URLs in Vue.js?

Why is the image URL printing in console but not rendering to src attribute? Is there a way to achieve this using async and await in Vue.js? <div v-for="(data, key) in imgURL" :key="key"> <img :src= "fetchImage(data)" /> </div> The i ...

The website is failing to extend and reveal content that is being concealed by jQuery

I'm currently diving into the world of Javascript and jQuery, attempting to create a functionality where upon clicking the submit button, the website dynamically expands to display search information. Although the feature is still in progress, I am ut ...

Attempting to transmit information using Ajax to an object-oriented programming (OOP) class

Trying to send data with username, password, etc from an HTML form -> Ajax -> Instance -> OOP class file. Questioning the approach... Begins with the form on index.php <!-- Form for signing up --> <form method="post"> <div ...

What steps can I take to resolve the issue of JSON data not displaying in my UITableView?

I'm facing a challenge with this issue. Despite attempting to reference URL1 and URL2 for assistance, I haven't had any luck. How can I resolve the JSON problem that is causing my UITableView to not populate? I'm struggling to prevent my arr ...

Exit the loop when a certain condition is satisfied within a separate loop while using SCRAPY

Currently, I am developing a SCRAPY SPIDER to send requests to an API. The main objective is to check if a specific condition is met in order to exit the loop. The loop is implemented in both the parse method and the content of the parse_api method. Despi ...

Encountering a Vue warning while attempting to perform semantic binding in Vue.js

I am brand new to working with Vue.js and I wanted to experiment with semantic binding. The issue is that I have my Vue.js file in the same directory as my testing page, but for some reason I keep receiving a warning saying "Cannot find element: #growler". ...

Determine the number of JavaScript functions present on a webpage using JavaScript

Hey there! I'm interested in counting the javascript functions on a specific page and then sending this count via ajax. Do you think it's possible to do this using javascript? What would be the best approach? Thanks in advance! Just to explain f ...

Guide to automatically inserting text into an html form and submitting it without manual intervention

Currently, I am in the process of a project where my main goal is to design an HTML form for submitting replies. One interesting feature I want to include is an option for users who are feeling lazy to simply click on "auto-generate comment", which will ...

Building a Loading Bar with Two Images Using JavaScript and CSS

I am currently experimenting with creating a progress bar using two images: one in greyscale and the other colored. My goal is to place these two divs next to each other and then adjust their x-position and width dynamically. However, I'm having troub ...