Ngx-admin: How to config multi languages for sidebar

Created on 21 Feb 2017  ·  9Comments  ·  Source: akveo/ngx-admin

  • I'm submitting a ...
    [ ] bug report
    [ ] feature request
    [X] question about the decisions made in the repository

  • Do you want to request a feature or report a bug?

I can setup the ng2-translate for my ng2-admin project. But, I found the sidebar menu was load from
PAGES_MENU. And Declared like this: public routes = _.cloneDeep(MENU);

Is there any way I can setup multi-languages?

help wanted question

All 9 comments

In pages.menu.ts, you can change the title as follows.
export const PAGES_MENU = [ { path: 'pages', children: [ { path: 'dashboard', data: { menu: { title: 'PAGES_MENU.dashboard', icon: 'ion-android-home', selected: false, expanded: false, order: 0 } } },

Then put your translations in a json file, for example en-US.json.

  "PAGES_MENU": {
    "dashboard": "Dashboard",
    ...

and zh-TW.json

 "PAGES_MENU": {
    "dashboard": "儀表板",
    ...

Thanks for your comment. But, your solution works only for non-sidebar content.

@coderQQ My example is sidebar. I don't understand what does 'non-sidebar content' mean?

@apeter10 Could you please provide more detail or some sample code? Or, is there any other step I have to do to make it work? I did exactly what you explain in the previous comment. It did not translate for me.

@apeter10 in general, you solution works for html content. But, if I need translate something in a ts file(not in the template). does your solution still work?

@coderQQ Please refer to ng2-translate README.md. You can translate somethins in a ts file as follows.
constructor(translate: TranslateService) {
// this language will be used as a fallback when a translation isn't found in the current language
translate.setDefaultLang('en');
// the lang to use, if the lang isn't available, it will use the current loader to get them
translate.use('en');
translate.get('HELLO', {value: 'world'}).subscribe((res: string) => {
console.log(res);
//=> 'hello world'
});
}

@apeter10 ... it doesn't work for me... it seems that the const PAGES_MENU is not parameterized, I mean that cannot link anything...

I got the same issue, previous version ng2-admin seems to work well when you put translate directive in page-menu.ts, like this

       menu: {
          title: 'general.menu.dashboard'
        }

While in the latest version ngx-admin doesn't work

@jiradeto please open a separate issue as this one seems to be outdated.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tal-shahar picture tal-shahar  ·  3Comments

burtonator picture burtonator  ·  3Comments

fabltd picture fabltd  ·  3Comments

pulfabio picture pulfabio  ·  4Comments

lopn picture lopn  ·  4Comments