Adding a Resource Bundle to a Vue project

I am looking to integrate the ResourceBundle package into my Vue project. After installing it with the following command:

npm install resource-bundle

I discovered these exported functions in the index.js file of the ResourceBundle package:

export function* loader (locale, dir, baseName) {
    console.log('in loader')//Does not print
    ...
    return new ResourceBundle(require(file))
};

function ResourceBundle (resource) {
    this.resource = resource
}

ResourceBundle.prototype.get = function (key) {
    ...
    return util.format.apply(util, params);
};

export const ResourceBundlee = ResourceBundle

Next, I attempted to import and use the 'loader' function in main.js as follows:

import * as ResourceBundle from 'resource-bundle'
console.log(ResourceBundle)
//console:
// ResourceBundlee:ƒ s(t) 
// loader:ƒ r(t,e,n)  
console.log(ResourceBundle.loader('en_US', 
__dirname+'/resources',message').get) 
//console:
//undefined

Since I am unfamiliar with JavaScript, can someone help explain why 'in loader' does not get printed and provide guidance on the correct way to import the loader function? Thank you!

Answer №1

npm install ResourceBundle needs to be corrected to

npm install --save resource-bundle
. Make sure to reinstall with the correct package name and use the save flag.

After doing that, verify the package.json file in the main directory of your project for resource-bundle listed under the "dependencies" section.

  "dependencies": {
    ...
    "resource-bundle": "^0.1.2",
    ...
  }

Adjust your import statement as follows:

import loader from 'resource-bundle'

Then call the loader function like this:

let message = loader('en_US', __dirname+'/resources',message')
console.log(message.get('some-key')) 

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

How can I use Angular to toggle a submenu based on a data-target attribute when clicked?

Struggling to implement a functionality using ng-click to retrieve the data-target attribute of a clicked angular material md-button, in order to display the submenu when a topic is clicked on the sidenav. The navigation structure consists of md-list with ...

Having difficulty coming back from a promise catch block

I'm struggling to populate a menu list from my PouchDB database because I am unable to retrieve anything within the promise that is executed after calling get on the db. Below is the code in question: <MenuList> {this.populateSavedClues()} ...

Discovering the clicking actions on PDF elements within an HTML environment

I am currently working on developing a web application that involves rendering various pdf objects. My main goal is to be able to detect the position of a click inside the pdf container. However, it seems like the OnClick event is not functioning as expe ...

Leveraging Angular 6: Implementing custom scripts on a component basis and verifying their presence

I need some help with a script that I want to run on a specific component only. I've managed to add the script to the component, but there are a few issues that I'm unsure how to fix. When I go to the component, the script is added to the DOM b ...

Navigating the "el" pointer in Vue when using multiple layouts in Laravel MPA

I have recently discovered Vue.js and its many benefits, such as improved user experience and reactivity. I have a Laravel application that is already live, but now I want to incorporate Vue.js to enhance it further by rebuilding it into components. Howev ...

The JSON object was not found in the AJAX response

I received a JSON object through an AJAX request. When I use console.log(response); in the console, I can see my object. However, when I use console.log(response.mostSearched);, it returns undefined. Why is that? I copied the object from the devTools con ...

Error Encountered when Using JQuery AJAX: Unexpected Identifier Syntax Issue

I've been struggling with a strange error for quite some time now. I want to believe that this is one of those errors where the solution will magically appear, but only time will tell. Here's the piece of code causing the issue: var images = ...

Discovering image file extensions in JavaScript using regular expressions

Can anyone provide me with a javascript regular expression to validate image file extensions? ...

Sending user credentials to a new page in JavaScript

My goal is to direct the user from one web page to another that requires a password for access. The user arrives on the initial page by scanning a barcode with a specific terminal, similar to a smartphone equipped with a customized barcode reader applicati ...

Utilizing an Async API call from a separate page and passing it as a component input

I recently set up an asynchronous API fetch in one of my .JS files and then invoked it from another JS file to output the result using console.log. (Is there a more efficient method for achieving this?) Now, my aim is to utilize the fields of the response ...

Why is my Heroku deployment not working properly?

I encountered an issue during the deployment of my application. I developed a PWA locally using Laravel and vueJs, and everything was working fine. My MySQL database has 5 migrations and seeders set up. Now, I am trying to deploy it on Heroku following th ...

Is it possible to initiate validation on an HTML element without the presence of a form?

Is it possible to trigger validation on an HTML element without using a form? For example, I have set the required attribute on a field, but when I click the Save button, the field doesn't display the red outline indicating validation failure. I susp ...

Vue mistakenly displays the template tag instead of the intended content

Learning Vue.js has been quite a challenge for me. Despite trying out five tutorials already, I am still struggling to get anything working. It seems like the template tagging is being displayed instead of the actual content in the following code: < ...

Utilizing Vue.js 2.x to send a REST API request with a collection of objects

I currently have an array of objects stored in state, and my goal is to send this entire structure to a back end API for processing and receive a new set of values in return. Below is a simplified representation of this structure as viewed in the develope ...

Utilizing React and MaterialUI to create a dynamic GridLayout with paper elements

I am using the react-grid-layout library to create a dynamic grid where each item is a paper component from the React Material UI. However, I encountered an issue while running the application. The browser displayed the error message: "TypeError: react__W ...

The search box output will be the same as the JSON result

I have a server in Node.js that is able to read and process a JSON file containing various data, including unique user IDs. I have incorporated a search box into my HTML page, and I am seeking assistance with creating a jQuery method (which will require AJ ...

Select an image based on the input value provided

I'm new to coding and I'm attempting to replicate the search functionality of icomoon where typing a word displays related images. However, I'm facing an issue where I can't seem to get the value entered in the input field to trigger an ...

Encountering an issue with compiling Angular due to a Type Inference error

interface Course { name: string; lessonCount: number; } interface Named { name: string; } let named: Named = { name: 'Placeholder Name' }; let course: Course = { name: 'Developing Apps with Angular', lessonCount: 15 }; named = ...

Error encountered when sending information to web service repeatedly

After populating an array with data, the information is logged into a database using a web service when the array reaches a specific record count. However, upon calling the web service, I encountered an error related to a parameter being passed: Error Ty ...

What is the best way to determine if a variable exists within an array in Angular and JavaScript?

Currently, I am working on a project using Angular 6 with Laravel. In one part of my code, I am fetching an array in the frontend and need to check if a certain variable is present within that array. In PHP, you can easily achieve this using the in_array f ...