Unable to modify translation values in an existing ngx-translate object

I am facing an issue where I am unable to change the value of an object property within a translation JSON file using ngx translate. Despite attempting to update the value dynamically when receiving data from an API, it seems to remain unchanged.

I have tried using both the setTranslation() method and the set() method, but neither seem to work. Although I can see the updated value in the console log after making changes, it does not reflect in the HTML.

Below is a snippet of my TS file:

getDict() {
    this.getDictionary.getDictionary('dictionary').subscribe(
      res => {
        console.log(res);
        console.log('ar');
        this.translateService.use('ar').subscribe(response => {
        let config = [];
        for (let i in res) {
        if(res[i].language == 'ar') {
        config[res[i].key] = res[i].value;
        console.log('this is obj ', config);
        this.translateService.get(config[res[i].key]).subscribe((result: 
        String) => {
          console.log('tr res ', result);
          console.log(this.translateService.get(res[i].key));
          this.translateService.set(config[res[i].key], 
          config[res[i].value], 'ar');
        });
       }
       }
     })
    this.translateService.getTranslation('ar').subscribe(res => {
      console.log('this is the language translation ', res);
    });
   }
 )
}

This is how my HTML looks like:

<div [translate]="'first_name'" [translateParams]="{value: 'world'}"></div>

Here is a snippet from my ar.json file:

{
  "admin": {
       "first_name": "{{value}}"
           }
}

It's important to note that there are no issues with the app module, as it can read the translation file without any problems. The API response has also been reviewed and works smoothly without any errors, allowing me to retrieve data successfully.

Your assistance in resolving this issue would be greatly appreciated. Feel free to ask for further information if needed.

Answer №1

Let's start by addressing the error in this particular line of code:

<div [translate]="'first_name'" [translateParams]="{value: 'world'}"></div>

The correct syntax should be:

<div [translate]="'admin.first_name'" [translateParams]="{value: 'world'}"></div>

However, I'm having trouble grasping the issue at hand. Could you please provide a step-by-step explanation of your requirements?

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

Show the user's username on their profile page by retrieving the name from the database

Upon successful login/signup with various services, I want to display the username on the profile page. However, my database stores user data in different fields depending on the service used - user.twitter.name for Twitter logins, user.google.name for Goo ...

Issue encountered while generating a dynamic listing using Angular

My goal is to generate a dynamic table using Angular. The idea is to create a function where the user inputs the number of rows and columns, and based on those values, a table will be created with the specified rows and columns. However, I am facing an iss ...

Dealing with consecutive time period inquiries in Angular

My goal is to make 4 consecutive requests in Angular, and for some of these requests, I need to send multiple requests within this.myService.startAudit() until either the timer reaches 30 seconds or we receive a non-empty response. The issue with my curren ...

Zurb's Vertical Navigation Bar: A Stylish and Functional Design

I attempted to replicate the left navigation bar from this link: The responsive navigation bar and contents on the right caught my attention. Currently, I am working on a project that requires a similar navigation bar. While I am proficient in HTML and C ...

How can I find the "types" specific to modules within the "firebase" library?

I have a question that applies to various scenarios, with Firebase serving as an example. When working on my react project, I find myself wanting to import firebase from "@firebase/app", which is logical. However, if I want the const locationRef ...

Anticipate feedback from a new user

I'm currently working on a verification system that involves sending a message in one channel and triggering an embed with two emoji options (accept or deny) in another channel. The issue I'm facing is that the .awaitReaction function is getting ...

What are the steps to utilize a personalized validation access form within a component?

I created a unique validator to verify if an email already exists in the database before saving a new user, however, it appears that the validator is not functioning properly. Here is my template: <form class="forms-sample" #f="ngForm" (ngSubmit)="onS ...

Angular - creating a specialized input field for a unique MatDialogConfig configuration file

I have a unique setup with a custom MaterialDialogConfig file dedicated to handling all of my material dialog components. Here's what the configuration file looks like: import { MatDialogConfig } from "@angular/material"; export class MaterialDialog ...

The error message "Unable to retrieve property 'commands' of undefined (discord.js)" indicates that the specified property is not defined

As I try to incorporate / commands into my Discord bot, I encounter a persistent error: An issue arises: Cannot read property 'commands' of undefined Below is my main.js file and the problematic segment causing the error: Troublesome Segment c ...

how to use all parameters except the first one in TypeScript

Is there a way to reference one function's parameter types in another function, but only use a subset of them without repeating the entire list of parameters? //params of bar should be same as foo, except p1 should be a different type function foo(p1 ...

Identifying a sequence of characters as a string in Erlang

One of the functions in my codebase recursively parses a map to convert it into JSON. Here is the function that handles the output: hash(Map) -> binary:bin_to_list(jiffy:encode(Map)). atomJSON(Atom) -> binary:list_to_bin(atom_to_list(Atom)). % j ...

What is the best way to retrieve a {collection object} from a JavaScript map?

My application utilizes a third-party library that returns the map in the following format: public sids: Map<SocketId, Set<Room>> = new Map(); When I try to access it using the code below: io.of("/").adapter.sids.forEach(function(va ...

Is it true that Angular 16 does not have compatibility with the ng search filter feature?

Is it true that Angular 16 does not support the ng search filter? I encountered an error when trying to implement it, saying "the library (ng2-search-filter) which declares Ng2SearchPipeModule is not compatible with Angular Ivy". Looking for suggestions o ...

Modifying the key values of an associative array

In my code snippet, I am attempting to loop through a JSON array and update the values within it. Here is an overview of what the JSON structure looks like: <?php $json='[{"type":"dropdown","label":"Is the property tenanted ?","req":0,"choices":[{ ...

How to assign a class specifically to a single row using Angular 2

I have a tab containing multiple rows, and I am trying to add a class to the current row when I click on my delete button. The delete button returns the id of the row that needs to be deleted. My issue is that I am unsure how to dynamically add a class to ...

Getting rid of unwanted scrollbars in a breeze

I am facing an issue with two nested divs that have the same height settings. The outer div has a max-width/height constraint along with overflow auto, causing scrollbars to appear when the inner content exceeds its dimensions. However, even if I resize ...

Using Redux and Typescript to manage user authentication states can help streamline the process of checking whether a user is logged in or out without the need for repetitive checks in the mapStateToProps function

In the process of developing a web application utilizing React & Redux, I am faced with defining two primary "states" - Logged In and Logged Out. To tackle this challenge, I have structured my approach incorporating a union type State = LoggedIn | LoggedO ...

steps for signing up and keeping the parameters current

I am currently working on an app using React Native built with Expo. I have been trying to register and update some columns, but I am encountering issues. Below is a snippet of my source code: import * as Location from 'expo-location'; const UR ...

Having issues with my custom AngularJS directive functionality

app.directive("myData", function() { return { templateUrl: '/my-data.html' }; }); my-data.html file code <tr ng-repeat="employee in employees"> <td>{{employee.id}}</td> <td>{{employee.name}}</t ...

How can you avoid Ajax calls from failing due to frequent requests?

Currently, I am utilizing ajax to retrieve some data. However, I have encountered an issue where the ajax request is triggered by hovering over a button, which could potentially result in multiple requests being sent and overwhelming the server, leading to ...