Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localizing the navigation? #12

Closed
blissi opened this issue Jun 8, 2018 · 14 comments
Closed

Localizing the navigation? #12

blissi opened this issue Jun 8, 2018 · 14 comments

Comments

@blissi
Copy link

blissi commented Jun 8, 2018

Hallo,
how can I localize the navigation of the AppSidebarNav? I tried two approaches, but both failed:

  • Create a new navigation-array. Through the data binding, this should fully replace all existing navigation items in the UI - but that's not the case: the new items are added to the existing items.
  • Update the "name"-property of the existing navigation items in the array. This works for regular navigation items, but not for titles: the titles keep their previous text.
@xidedix
Copy link
Member

xidedix commented Jun 8, 2018

Hi @blissi
navItems array is located here:
https://github.com/coreui/coreui-free-angular-admin-template/blob/master/src/app/_nav.ts
if you need some more customization, you can create a wrapper around it

@blissi
Copy link
Author

blissi commented Jun 8, 2018

@xidedix oh sorry, I didn't explain it well enough what I am trying to do...I have a language toggle in my application that allows the user to update the current language on-the-fly. That works fine for the rest of my app, but I couldn't get the navigation to work properly. I tried the two approaches that I described in my first post.

@burntblark
Copy link

@blissi I have the same problem trying to update the navigation menu dynamically. My use case is that my menu items come from the server. So based on the content I am viewing, the menu may be different.

Been watching for update on this since you posted this. By any chance, have you found a work around for this?

burntblark added a commit to burntblark/coreui-angular that referenced this issue Jun 16, 2018
@burntblark
Copy link

@blissi Spent sometime on the codes. Found what may be wrong. The host replacement routine Replace is messing this up for the app-sidebar-nav-item component or so. It works as expected on my project now. Thought I should share it with you. I'd do a pull request so you could check it.

@blissi
Copy link
Author

blissi commented Jun 20, 2018

@burntblark Thanks that you shared your changes with me. It doesn't work, though: when the user switches the language, the regular navigation items change their text, but the title items don't do (as a side note: I implemented language switch with my second approach - that is, the navigation items in _nav.ts are patched, no new navigation structure created).

@steolits
Copy link

steolits commented Jul 3, 2018

Hi everyone! I'm trying to update the navigation menu dynamically but it doesn't work. Menu data comes from server. Everytime that the application received the new menu data, the component adds the new menu after the old. How can I fix this? Thanks!

-- core ui versions:
"@coreui/angular": "^2.0.0-rc.1",
"@coreui/coreui": "^2.0.2",

@gabord
Copy link

gabord commented Jul 19, 2018

Hi!
I am experiencing the same problem. I managed to solve the i18n of items by adding a key property to the _nav.ts, on which the name property will be filled when changing languages. However, as others said, the titles remain the same - that's because these items got created once on init in AppSidebarNavTitleComponent. An OnChanges-type check and reloading / re-rendering would be nice!

@Azuka
Copy link

Azuka commented Aug 17, 2018

Hi. I'm experiencing this same issue with duplicate menu items. What's the best way to resolve?

@derdeka
Copy link

derdeka commented Oct 17, 2018

+1

@Azuka
Copy link

Azuka commented Oct 17, 2018

What I did for the duplicate issue was create my own components locally. See https://gist.github.com/Azuka/b4837da81614826e655c60dcdbf3d40b. I haven't seen any issues so far. It seems to have something to do with multiple elements in a template with ngFor.

@nealyip
Copy link

nealyip commented Dec 16, 2018

Hallo,
how can I localize the navigation of the AppSidebarNav? I tried two approaches, but both failed:

  • Create a new navigation-array. Through the data binding, this should fully replace all existing navigation items in the UI - but that's not the case: the new items are added to the existing items.
  • Update the "name"-property of the existing navigation items in the array. This works for regular navigation items, but not for titles: the titles keep their previous text.

For the titles,
Here's a simple reproduction.

src/app/app.component.html
<app-sidebar-nav [navItems]="navItems"></app-sidebar-nav>

src/app/app.component.ts

import {Component, OnInit} from '@angular/core';

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
    title = 'app';
    navItems = [
        {
            title: true,
            name: 'Transactions'
        },
        {
            name: 'List',
            url: 'users/list',
            // icon: 'icon-list'
        }
    ];

    ngOnInit(): void {
        let cnt = 0;
        setInterval(() => {
            cnt++;
            this.navItems[0].name = '' + cnt;
            this.navItems[1].name = '' + cnt;
        }, 1000);
    }


}

src/app/app.module.ts

import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';

import {AppComponent} from './app.component';
import {AppSidebarModule} from '../../projects/coreui/angular/src/lib/sidebar';
import {RouterModule} from '@angular/router';

@NgModule({
    declarations: [
        AppComponent
    ],
    imports: [
        BrowserModule,
        AppSidebarModule,
        RouterModule.forRoot([])
    ],
    providers: [],
    bootstrap: [AppComponent]
})
export class AppModule {
}

The title one won't get incremented.

It's likely because of the AppSidebarNavTitleComponent using a simple property assignment instead of an angular template without property change detection.
const name = this.renderer.createText(this.title.name);

@nealyip
Copy link

nealyip commented Dec 16, 2018

For those whom may concern, it may be an ugly fix

import {Component, OnInit} from '@angular/core';

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
    title = 'app';
    navItems = [
        {
            title: true,
            name: 'Transactions',
            class: 'nav-transactions-title'
        },
        {
            name: 'List',
            url: 'users/list'
        }
    ];

    ngOnInit(): void {
        let cnt = 0;
        setInterval(() => {
            cnt++;
            this.navItems[0].name = '' + cnt;
            this.navItems[1].name = '' + cnt;

            document.getElementsByClassName('nav-transactions-title').item(0).innerHTML = this.navItems[0].name;
        }, 1000);
    }
}

Directly update the content by dom method.

xidedix added a commit that referenced this issue Feb 15, 2019
- fix(sidebar): navItems reassignment bug [#126](coreui/coreui-free-angular-admin-template#126), [#42](coreui/coreui-free-angular-admin-template#42), #12
- refactor(aside): drop `Replace`
- refactor(breadcrumb): drop `Replace` new component `cui-breadcrumb` (migration needed)
- refactor(footer): minor changes
- refactor(header): drop `Replace`
- refactor(layout): cleanup
- refactor(sidebar-nav): drop `Replace`, redesign
@andrejsn
Copy link

I have the same problem.
Only solved with DOM manipulation

in *.component.html

... <a>... (click)="transalteTo('ru') ...>Русский</a> <a>... (click)="transalteTo('de') ...>Deutsh</a> <a>... (click)="transalteTo('en') ...>English</a>

in *.component.ts
`
translateTo(language:string):void {
console.log('switch to: ' + language);

...translateService.use(language)...

// as an example, we change only the first menu item
var menu:Element = document.getElementsByTagName('app-sidebar-nav-link').item(0);
const menuTextOriginalHTML = menu.innerHTML;
console.log(menuTextOriginalHTML); // see original HTML

// set new i18n value
menu.innerHTML = `<!--bindings={
"ng-reflect-ng-switch-case": "disabled"

}--> ### HERE i18n VALUE ### `;

...

}
`

For a change, all menu items use foreach(){...}

damingerdai added a commit to damingerdai/coreui-angular that referenced this issue Sep 1, 2021
@github-actions
Copy link

github-actions bot commented May 5, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants