-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Dynamically translate left sidebar #123
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
Comments
Rather than using an array of items you may instead importing using a navbar service by subscribing the translated result.
|
@nealyip What is |
something like that
|
Hello, Is it possible a simple way to translate _nav.ts? Something like this:
|
Does anybody know how to translate breadcrumbs? |
I am also facing the same issue of how to change the dynamically to as per the localization can anyone help out on this. |
Here is what to do on _nav.ts and DefaultLayoutComponent.ts files //_nav.ts file
export interface NavData {
key?: string; //Add a new key
name?: string;
url?: string;
icon?: string;
badge?: NavBadge;
title?: boolean;
children?: NavData[];
variant?: string;
attributes?: NavAttributes;
divider?: boolean;
class?: string;
label?: NavLabel;
wrapper?: NavWrapper;
}
export const navItems: NavData[] = [
{
key: 'DASHBOARD.NAME',
name: '',
url: '/dashboard',
icon: 'icon-speedometer',
badge: {
variant: 'info',
text: 'NEW'
}
}
]
// DefaultLayoutComponent.ts file
import { navItems } from '../../_nav';
export class DefaultLayoutComponent implements OnDestroy, OnInit {
public navItems = navItems.map(items => {this.translate(items); return items; });
constructor(private ts: TranslateService){}
ngOnInit(): void {
this.ts.onLangChange.subscribe((event: LangChangeEvent) => {
this.navItems = navItems.map(items => {this.translate(items); return items; });
});
}
translate(item): void {
if ('key' in item) {
const trans = this.ts.instant(`${item.key}`);
if (trans !== `${item.key}`) {
item.name = trans;
}
}
if (item.children && item.children.length > 0) {
item.children.map( (child: any) => this.translate(child));
}
}
} |
I did the same way as @Nyfaristide mentioned. I did father by update value of item.name when use changes language, but new value of item.name is not updated in UI. Is there another way to translate "name" or simple was as: [translate]="KEY" in sidebar |
@papaiking The issue is because the nav items is an array of objects if u change anything inside u have to intimate Angular that a change has been done.For that you have to use deep clone like below
For Refhttps://stackoverflow.com/questions/60504757/app-sidebar-navs-navitems-is-not-updating |
I have did some other ways.
But the major problem is in ie it’s not working as expected can you please
suggest what I have to change in code level.
On Wed, 9 Sep 2020 at 9:10 PM, nidhinkumar06 ***@***.***> wrote:
@papaiking <https://github.com/papaiking> The issue is because the nav
items is an array of objects if u change anything inside u have to intimate
Angular that a change has been done.For that you have to use deep clone
like below
ngOnInit(): void {
this.subscription = this.translateService.onLangChange.subscribe(() => {
const translatedNavs = navItems.map(items => {this.translate(items); return items; });
this.navItems = [];
translatedNavs.forEach(val => this.navItems.push(Object.assign({}, val)));
});
}
For Ref
https://stackoverflow.com/questions/60504757/app-sidebar-navs-navitems-is-not-updating
#180
<#180>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#123 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGHFKT6Z755OOR2HQZTEWBLSE6OVBANCNFSM4GIIRD4Q>
.
--
Regards,
Mohd Jameel
(Time is limit not your imagination)
|
Got a solution? |
The suggested code examples here worked for me. The case was that
|
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 |
I need to translate sidebar dynamically with http://ngx-translate.com . How to do it?
The text was updated successfully, but these errors were encountered: