Failure of Ngx-translate to propagate to subcomponents

Since I have implemented my translate module in the shared/header.module.ts file, it mainly serves the purpose of handling language switching for the entire application.

In header.module.ts:

@NgModule({
  imports: [

    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useClass: CustomTranslateLoader,
        deps: [HttpClient]
      }
    }),

  exports: [
    TranslateModule,
    HeaderComponent
  ]
})

The module is then exported.

In leftnavigation.component.html, footer.component.html, and rightbar.component.html files, I import and successfully retrieve translation values.

In leftbarnavigation.ts, I also export the module:

@NgModule({
  imports: [
    TranslateModule,
    RouterModule,
  ],
  exports: [
    TranslateModule,    
  ]
})

No modifications were made in app.module.ts since the primary translate settings are defined in header.module.ts. Basic import and export operations are carried out there.

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    TranslateModule,
    SharedModule,
  ],
  exports: [
    TranslateModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})

In app-routing.module.ts, further import and export actions are performed:

const routes: Routes = [
  {
    path: "",
    component: MainLayoutComponent,
    data: { pageTitle: "Home" },
    children: [
      {
        path: "dashboard",
        loadChildren: "./dashboard/dashboard.module#DashboardModule",
      }, {
        path: "portfolio",
        loadChildren: "./portfolio/portfolio.module#PortfolioModule",
      },
    ]
  },

];

@NgModule({
  imports: [    TranslateModule, RouterModule.forRoot(routes, { useHash: true })],
  exports: [    TranslateModule, RouterModule]
})
export class AppRoutingModule { }

Next is portfolio.module.ts:

@NgModule({
  imports: [
    TranslateModule,    
    PortfolioRoutingModule,
    SharedModule,
  ],
  exports: [
    TranslateModule
  ]
})
export class PortfolioModule { }

Followed by portfolio-routing.module.ts:

const routes: Routes = [
  {
    path: 'portfolio-list',
    component: PortfolioListComponent
  }
];

@NgModule({
  imports: [TranslateModule, RouterModule.forChild(routes)],
  exports: [TranslateModule, RouterModule]
})
export class PortfolioRoutingModule { }

However, when attempting to access the page /portfolio/portfolio-list,

I notice that the translations do not take effect on this specific page.

It seems like the translation fails to be shared properly on this particular page.

I am currently using Angular 6.

Any suggestions on how to resolve this issue?

Answer №1

Is the PortfolioListComponent loading correctly? It's possible that you may have overlooked declaring it within a module, such as in the PortfolioModule.

@NgModule({
  imports: [
    TranslateModule,
    PortfolioRoutingModule,
    SharedModule,
  ],
  exports: [
    TranslateModule
  ],
  declarations: [PortfolioListComponent],
})
export class PortfolioModule { }

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

Incorporate TypeScript with Angular 2 to construct a dictionary with <key, value> pairs. Then, utilize a JSON file to populate the dictionary with data

I am in need of assistance with creating a dictionary or list with a specific structure. I have prepared a json file within my angular 2 project, and I would like to load this data into the dictionary that I am creating. Sample content from my Json file: ...

Inferring types from synchronous versus asynchronous parameters

My objective is to create an "execute" method that can deliver either a synchronous or an asynchronous result based on certain conditions: type Callback = (...args: Arguments) => Result const result: Result = execute(callback: Callback, args: Arguments) ...

What is the process for defining an opaque type in programming?

[ This is not this ] Take a look at this snippet of code: interface Machine<OpaqueType> { get(): OpaqueType, update(t: OpaqueType); } const f = <U, V>(uMachine: Machine<U>, vMachine: Machine<V>) => { const u = uMach ...

Tips for using an ArrayBuffer to stream media in Angular

Currently, I am facing an issue while transferring data from my backend with nodeJS to Angular. Everything seems to be working fine except for one problem - my media files are not functioning properly in my code. To resolve this, I have implemented Blob fi ...

React, Typescript, and Material-UI 4 compilation dilemma

Out of the blue, my entire project collapsed and I can't seem to build it. I recently reset the project using a fresh create-react app build, which seemed fine initially. However, just yesterday, I encountered a similar issue but with a different erro ...

How to use D3 to add arrow directions to an SVG path

Within my svg path lies the representation of a shuttle track used in manufacturing processes. Every shuttle on this track moves in a distinct direction, and I wanted the svg path to visually indicate these directions for easy reference. Initially, I tried ...

Tips for enhancing the accessibility of Angular CDK Drag and Drop using keyboard controls

Our application features a unique "Form Builder" tool that allows users to easily create forms by simply dragging and dropping form fields onto it. I am currently investigating ways to ensure that this functionality is accessible via keyboard navigation, e ...

Syntax highlighting in VSCode does not seem to be functional when the ?? nullish coalescing operator is being utilized

Hello there! I've recently started using react.js with typescript on a new computer, but I've encountered an issue with syntax highlighting in VSCode. It seems that the problem arises when there's a double question mark (??) in the code, spe ...

Angular: Guidelines for detecting checkbox change events and dynamically updating content in a separate component

One of my components contains a checkbox element: <mat-checkbox class="mr-5"></mat-checkbox>. I want to be able to detect when this checkbox is checked or unchecked, and based on its state, display text in a separate component that is ...

Divide a given number of elements within an array of arrays

Presented below is an array: [ { "id": "34285952", "labs": [ { "id": "13399-17", "location": "Gambia", "edge": ["5062-4058-8562-294 ...

Activate individual row Kendo UI Angular 2 grid mouse hover event

I understand that utilizing the template syntax allows me to utilize the standard angular 2 (mouseover) event listener in order to detect a mouse over event for a specific column. I am curious if there exists a method to listen for mouseover events for an ...

Adding data to an array from a JSON source using Angular 5

When I receive a response from an endpoint, it looks like this: { "data": [{ "volume": 4.889999866485596, "name": "Carton03", "weight": 5.75, "storage": 3 }, { "volume": 2.6500000953674316, "name": "Carton02", "weight": 4.5 ...

The implementation of Typescript in Express does not rely on Middleware

I've encountered an issue with my Auth Middleware - it seems that the middleware isn't being called at all. Even when I intentionally throw an Error within the middleware function, nothing is printed out. For testing purposes, I only need to inv ...

Unable to locate the specified CSS file

I've been diving into the world of NativeScript and exploring the tutorials provided at . However, I'm facing an issue with getting the platform specific CSS to work properly. Every time I try to run the code, I encounter the following error mess ...

typescript push in react native is a crucial step to enhance performance and optimize

I've been diving into TypeScript within the realm of React Native. Oddly, when I translated a certain snippet to vanilla JavaScript, the application worked flawlessly. However, upon converting it back to TypeScript, an error message popped up stating ...

Enhance Angular Form Functionality: Implement Button-Triggered Option Selection

My current Angular page features a select dropdown that is automatically populated with existing client addresses, including the option "Add New Address". Clicking on this option opens a modal window where a new address can be entered. Once the new address ...

Introducing the Angular 2/4 Dashboard Widget Module!

I am currently developing the dashboard for my Angular 2 application and I am in search of an npm package that fits my requirements. I came across a link that provides similar functionalities to what I need, which is . I want to be able to add new w ...

What is the best way to convert this object/array into TypeScript?

My React application contains a data structure organized in the following format: data = { 2021-03-01: { "date": 1st March, "value": 17 }, 20 ...

Enhance your Typescript code by incorporating typing for response objects that include both index signatures and key-value pairs

I am grappling with how to properly incorporate typescript typings for the response object received from a backend service: { de49e137f2423457985ec6794536cd3c: { productId: 'de49e137f2423457985ec6794536cd3c', title: 'ite ...

How can you set a checkbox to be selected when a page loads using Angular?

On page load, I need a checkbox to already be 'checked', with the option for the user to uncheck it if they want. Despite trying to add [checked]="true" as recommended in some Stack Overflow answers, this solution is not working for me. <label ...