fulls1z3 / ngx-i18n-router

Route internationalization utility for Angular
MIT License
35 stars 2 forks source link

pipe, routes translations, config.json vs lodash #10

Closed fulls1z3 closed 7 years ago

fulls1z3 commented 7 years ago

I'm submitting a ... (check one with "x")

[x] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  <!-- Please check the repository for a similar issue or PR before submitting -->
[ ] Support request => <!-- Please check the repository for a similar issue or PR before submitting -->
[ ] Feature request
[ ] Documentation issue or request

Current behavior Hello guys, I updated all my i18n-router modules to last release and i got a problem with the I18NRouterPipe. It doen't seems to work (for me at least) anymore. Routes doesn't seems to be translated anymore, exemple for this : -> [routerLink]="['visit'] | i18nRouter", the route that is retreived is "/visit" even if my default language is /fr. We should have seen "/fr/visiter".

I found that is because we uses now lodash's get method now for routes translations _.get(this.translations, this.languageCode + "." + key.toUpperCase(), undefined); (l.42 of i18n-router.services.js).

Lodash itself uses : path = castPath(path, object); (l.3040) which split path to iterate over and find correct translation.

The problem is using this kind of config structure into config.json file:

  "routes": {
    "en": {
      "ROOT.VISIT": "visit"
   },
    "fr": {
      "ROOT.VISIT": "visiter",
   }

path is an array(3) like this : 0:"fr" 1:"ROOT" 2:"VISIT"

The translation will never be found because our key "ROOT.VISIT" is splited.

Expected/desired behavior If am not wrong, we should now uses this structure :

  "routes": {
    "en": {
      "ROOT" : {
        "VISIT": "visit"
      }
  },
    "fr": {
      "ROOT" : {
        "VISIT": "visiter"
      }
  }

if we want to keep using lodash way. Or keep using the old way into i18n-router.service :

if (!this.translations[this.languageCode][key.toUpperCase()])
      return undefined;
return this.translations[this.languageCode][key.toUpperCase()];

I could be wrong so let me know ^^'. I also reproduice this case using ng-seed/spa

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior? If am right, It could be great to update documentation about configurations settings config.json and the ng-seed/spa.

Environment

fulls1z3 commented 7 years ago

@Pipweak just merged all the packages into one single repository, so I moved your issue here. Will update this soon 👍