Coder Social home page Coder Social logo

Comments (11)

andrewwhitehead avatar andrewwhitehead commented on June 14, 2024 3

I have a potential fix for this here: https://github.com/cywolf/localize-router/tree/fix-151

from localize-router.

JoseCMRocha avatar JoseCMRocha commented on June 14, 2024 1

Hi @dragorwyin that is strange your case is very similar with mine and the solution by @CyWolf worked for me, did you check your routing configuration to see if there is something wrong? are you able to create a example to reproduce your problem?

from localize-router.

JoseCMRocha avatar JoseCMRocha commented on June 14, 2024

Hi @CyWolf just tested that changes and it seems to fix the problem that I described. Did you reported this problem previously on this repository? Asking to see if there is more discussion about the problem reported.
Did you try to create a pull request of your change to this greentube/localize-router? I verified that your solution fix my problem but I don't know if it will break something else.

from localize-router.

andrewwhitehead avatar andrewwhitehead commented on June 14, 2024

@JoseCMRocha Hiya, I haven't reported the issue separately, and haven't created a PR as I don't have time to add unit test(s) as the moment.

from localize-router.

dragorwyin avatar dragorwyin commented on June 14, 2024

@CyWolf Your solution not working for me when I have translated first slug in path, for example: /en/register/token and /pl/rejestracja/token. After language change it moves me into /pl/rejestracja without handling :token parameter. Even if I did fork and just copied your file. It's huge bug for me actually :?

from localize-router.

dragorwyin avatar dragorwyin commented on June 14, 2024

@JoseCMRocha Here is a reproduction:
I have a app-routing.module.ts file with simple configuration:

import { Routes } from '@angular/router';
import { FullComponent } from './core/layouts/full/full.component';
import { BlankComponent } from './core/layouts/blank/blank.component';
import { NotFoundComponent } from './modules/not-found/not-found.component';
import { LoginComponent } from './modules/login/login.component';
import { AuthGuardConfirmed } from './core/guard/auth-guard-confirmed.service';

export const routes: Routes = [
  {
    path: '',
    component: FullComponent,
    canLoad: [AuthGuardConfirmed],
  }, {
    path: '',
    component: BlankComponent,
    children: [{
      path: 'login',
      component: LoginComponent
    }, {
      path: 'register',
      loadChildren: './modules/register/register.module#RegisterModule',
    }]
  },
  { path: '404', component: NotFoundComponent },
  { path: '**', redirectTo: '/404' }
];

app.module.ts

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

import { AppComponent } from './app.component';
import { FullComponent } from './core/layouts/full/full.component';
import { BlankComponent } from './core/layouts/blank/blank.component';
import { NotFoundComponent } from './modules/not-found/not-found.component';
import { LoginComponent } from './modules/login/login.component';
import { AuthGuardConfirmed } from './core/guard/auth-guard-confirmed.service';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';

import { HttpClientModule, HttpClient } from '@angular/common/http';

import { TranslateModule, TranslateService, TranslateLoader } from '@ngx-translate/core';
import { LocalizeRouterModule, LocalizeRouterSettings, LocalizeParser } from 'localize-router';
import { LocalizeRouterHttpLoader } from 'localize-router-http-loader';
import { routes } from './app-routing.module';
import { RouterModule } from '@angular/router';
import { Location } from '@angular/common';

export function createTranslateLoader(http: HttpClient) {
  return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}

export function HttpLoaderFactory(http: HttpClient) {
  return new TranslateHttpLoader(http);
}


@NgModule({
  declarations: [
    AppComponent,
    BlankComponent,
    NotFoundComponent,
    FullComponent,
    LoginComponent,
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    HttpClientModule,
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: HttpLoaderFactory,
        deps: [HttpClient]
      }
    }),
    LocalizeRouterModule.forRoot(routes, {
      parser: {
        provide: LocalizeParser,
        useFactory: (translate, location, settings, http) =>
          new LocalizeRouterHttpLoader(translate, location, settings, http),
        deps: [TranslateService, Location, LocalizeRouterSettings, HttpClient]
      }
    }),
    RouterModule.forRoot(routes)
  ],
  providers: [
    AuthGuardConfirmed,
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

register.routing.ts:

import { Routes, RouterModule } from '@angular/router';
import { RegisterComponent } from './register.component';
import { ConfirmComponent } from './confirm/confirm.component';

export const routes: Routes = [
  {
    path: '',
    children: [{
      path: '',
      component: RegisterComponent
    }, {
      path: ':token',
      component: ConfirmComponent
    }]
  }
];

export const RegisterRoutes = RouterModule.forChild(routes);

register.module.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { routes } from './register.routing';

import { MaterialModule } from '../../shared/material.module';
import { SharedModule } from '../../shared/shared.module';

import { ComponentsModule } from '../../components/components.module';
import { RegisterComponent } from './register.component';
import { ConfirmComponent } from './confirm/confirm.component';
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { LocalizeRouterModule } from 'localize-router';
import { RouterModule } from '@angular/router';

@NgModule({
  imports: [
    CommonModule,
    SharedModule,
    MaterialModule,
    ComponentsModule,
    TranslateModule,
    LocalizeRouterModule.forChild(routes),
    RouterModule.forChild(routes)
  ],
  declarations: [
    RegisterComponent,
    ConfirmComponent,
  ],
})
export class RegisterModule { }

I have translations in assets/i18n (pl.json and en.json):

  • pl.json: "{ ROUTES.register": "rejestracja" }",
  • en.json: "{ ROUTES.register": "register" }",

I have an locales.json in assets:

{
  "locales": [
    "en",
    "pl"
  ],
  "prefix": "ROUTES."
}

I hope there will be any solution and will be implemented soon in this library ;P

There is also another problem: I cannot translate child name, for example: /pl/rejestracja/potwierdz is an translation of /en/register/confirm. I tried translate confirm slug without any success. Tried use

  • { ROUTES.confirm: "potwierdz" },
  • { ROUTES.register.confirm: "potwierdz" } and
  • { ROUTES.register.confirm: "rejestracja/potwierdz" } without success.

from localize-router.

MarcARoberge avatar MarcARoberge commented on June 14, 2024

Hi, just wondering when @CyWolf is going to be merged to fix this issue?

from localize-router.

hohler avatar hohler commented on June 14, 2024

@MarcARoberge as @CyWolf does not have time for tests, I just created a PR from his fork. We need this fix.

from localize-router.

giacomo avatar giacomo commented on June 14, 2024

any news on this?

from localize-router.

relvingonzalez avatar relvingonzalez commented on June 14, 2024

Are there any plans for this?

from localize-router.

giacomo avatar giacomo commented on June 14, 2024

for a patch see #159 (comment)

from localize-router.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.