Load and substitute variables in template strings retrieved from a document

I am interested in utilizing ES6 template strings as templates for translating content within my Node.js application.

For example, I have a JSON file named en_GB.json with the following structure:

{
  "app.template": "This is ${foo} I ${bar}",
  "app.foo": "bar"
}

In my Node.js code, I perform the following actions:

const translations = require('./en_GB.json')
const foo = 'what'
const bar = 'want'

console.log(translations['app.template']) // Outputs This is ${foo} I ${bar}

The desired output I want to achieve is "This is what I want"

Is there a way to accomplish this without resorting to using a helper function?

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

Differences between Array and Database Search

Currently, I have implemented a system where I store a refresh token in a JavaScript array as well as in each user's information table. When a user requests data, I first check the token in the array. If the token matches one in the array, I loop thro ...

CORS problem in Chrome when using AngularJS and Symfony 3

I've been dealing with a bug on my backend and frontend for the past week. I created a REST API (php/symfony) to manage books and authors. Initially, I had trouble with cross-origin requests on DELETE, which has been resolved. However, now I am facin ...

Is it possible to utilize EmberJS or other frameworks without the necessity of setting up its server?

I am in search of a JavaScript framework that offers the following features: MV* Well-structured HTML file as template Fast rendering (possibly using virtual DOM) Ability to combine and be compatible with other plugins or libraries Edit on tablet IDE app ...

Retrieve information from JsonResult

While working with ASP.NET Core, the MVC controller is returning JSON data. I am currently attempting to retrieve this data in a unit test. The best solution so far has been string data = JsonConvert.SerializeObject(jsonResult.Value); and then comparing ...

JavaScript generates fresh arrays according to specific criteria

I have arrays containing old and entity data: var old = [ { "id": 3, "entity_type_id": 1, "product_id": 4, "name": "test1", "acreage": 100, "yield": 20, "worth": 30 }, { "id": 4, ...

Refresh the data using the Ajax function

I am attempting to implement a delete function using Ajax. function delCatItem(catitem){ var theitem = catitem; $.ajax({ url: "movie/deleteitem/", type: "POST", data: { "movieid" : catitem ...

The NextJS route handler successfully loads when accessed directly through the browser's search bar, but fails to function properly when attempting to console log it

Essentially, I am attempting to retrieve JSON placeholder data by using my route handler that is defined in /api/posts/route.js export async function GET() { const res = await fetch('https://jsonplaceholder.typicode.com/posts'); const data = ...

SignalR gets stuck on the 'Initiating start request' screen, halting all progress

SignalR has been causing some strange behavior for me lately. After doing some refactoring, I started experiencing connectivity issues. It seems like my code was just lucky to work before because it didn't follow the recommended practices. For example ...

The alert function in the Ajax web method is malfunctioning

Every time I try to call the Ajax web method, I keep receiving a 'save error' message. However, the data is successfully saved to the database without any issues. I have checked for errors but couldn't find any. How can I display an alert sa ...

Creating an autocomplete/autosuggestion feature using AJAX and displaying the results in a table separate from the form

I am in the process of creating a basic webpage with a search engine. I have learned that to incorporate autocomplete/autosuggest with a form, using ajax is necessary. This is acceptable to me. There are numerous solutions available online, but unfortunate ...

Nested click events in a loop using Javascript

My issue involves nested click event listeners in my JavaScript code. Whenever I trigger the event multiple times, it seems to loop and send a request twice as many times as expected. Can someone help me locate the mistake in my code? I'm still new to ...

Combining meshes results in a lower frame rate

I have combined approximately 2500 meshes, each with its own color set, but my FPS is lower than if I had not merged them. Based on THIS article, merging is recommended to improve FPS performance. Is there something I am overlooking? var materials = new ...

Associate a unique identifier string with a randomly generated integer identifier by Agora

For my current web project, I am utilizing a String username as the UID to connect to the channel in an Agora video call. However, I now need to incorporate individual cloud recording by Agora into the project. The challenge lies in the fact that cloud r ...

trigger the focusout event within the focusin event

I am attempting to trigger the focusout event within the focusin event because I need to access the previous value from the focusin event, but the focusout event is being triggered multiple times. $('tr #edituser').focusin(function(){ var ...

The logout confirmation message functionality in Laravel 8 is malfunctioning

In my Laravel project, I am attempting to implement a logout confirmation message that will pop up when a user clicks on the logout button. Here is the code I have added to my navbar.blade.php: <a class="dropdown-item" id="logout" hr ...

Can you explain how the interactive notification on stackoverflow is generated when you are responding to a question and someone posts a new answer?

Have you ever been in a situation where you're writing an answer to a question, but then someone else posts their response and a popup appears notifying you of the new answer? I'm curious about how that whole process works. It seems like the answ ...

From jQuery integration to Wordpress - Frustrating uncaught errors are making me lose

I recently completed a small application on Codepen and decided to transfer it to my Wordpress website. After updating the necessary elements, such as replacing $ with jQuery and adjusting the JSON file location, I encountered some issues in the console. ...

The process of uploading a React App to Heroku resulted in a critical error: "FATAL ERROR: Heap limit reached, Allocation failed - JavaScript heap out of memory."

There's a puzzling issue that I believe I have the solution to (paying for more bandwidth on Heroku), but the root of the problem eludes me and it's truly frustrating. Any assistance in pinpointing the cause would be greatly appreciated! Hopefull ...

Fetching JSON data from a URL using Java

I came across this link: JSON file The JSON file is stored on an online server. Everything seems to be fine, but I'm facing some challenges. I'm trying to retrieve values like "hood_id" or "damage_or_theft_car_id," however, my code crashes with ...

opacity of highcharts heatmap data points reduces to zero

Recently, I integrated a Heat Map feature from the Highcharts library into my app. However, I encountered a strange issue where certain rows of data were not displaying on the map. Please refer to the screenshot below for reference: Upon inspecting the el ...