Giter VIP home page Giter VIP logo

Comments (8)

meeroslav avatar meeroslav commented on August 20, 2024 2

It would be really helpful if you can set up a universal playground project with localize-router or try to solve this for localize-router. Unfortunately I won't have time to play with this until February so any help is appreciated.

from localize-router.

meeroslav avatar meeroslav commented on August 20, 2024 1

@samvloeberghs and @dneeleman

I've made some modifications but it's not finalized yet. In order to load localize router config with node use this:

Server loader for ng2-translate

export class TranslateUniversalLoader implements TranslateLoader {
  /**
   * Gets the translations from the server
   * @param lang
   * @returns {any}
   */
  public getTranslation(lang: string): Observable<any> {
    return Observable.create(observer => {
      observer.next(JSON.parse(fs.readFileSync(`assets/locales/${lang}.json`, 'utf8')));
      observer.complete();
    });
  }
}

Server loader for localize-router

export class LocalizeUniversalLoader extends LocalizeParser {
  /**
   * Gets config from the server
   * @param routes
   */
  public load(routes: Routes): Promise<any> {
    return new Promise((resolve: any) => {
      let data: any = JSON.parse(fs.readFileSync(`assets/locales.json`, 'utf8'));
      this.locales = data.locales;
      this.prefix = data.prefix;
      this.init(routes).then(resolve);
    });
  }
}
export function localizeLoaderFactory(translate: TranslateService) {
  return new LocalizeUniversalLoader(translate);
}

I still need to remove location from parser, though, so be patient please.

from localize-router.

samvloeberghs avatar samvloeberghs commented on August 20, 2024

More details:

You will need to put a way to define where to load the assets/locales.json, if ran on serverside.

As an example I would point to your dependecy: ng2-translate. Related issues & gists:
ngx-translate/core#353
angular/universal-starter#263
https://gist.github.com/ocombe/593d21598d988bf6a8609ba5fc00b67e

Will be glad to help out more on this one! Please request my help if needed anywhere

from localize-router.

samvloeberghs avatar samvloeberghs commented on August 20, 2024

on it, will update you asap

from localize-router.

ItsMeDelanoDev avatar ItsMeDelanoDev commented on August 20, 2024

@samvloeberghs Any updates? Would like to integrate this in our Universal App as well.

from localize-router.

samvloeberghs avatar samvloeberghs commented on August 20, 2024

@dneeleman no sorry.. I came to the conclusion that this plugin is not fitting my needs so I stopped investigating. I'm solving it completely different now.

You could use the ManualParserLoader to solve the universal problem I had..

LocalizeRouterModule.forRoot(routes, {
    provide: LocalizeParser,
    useFactory: (translate, http) =>
        new ManualParserLoader(translate, ['en','de',...], 'YOUR_PREFIX'),
    deps: [TranslateService, Http]
}),

So instead of loading it via fs on your server, like you would do for ng2 translate, you just define it in your app root module.

from localize-router.

ItsMeDelanoDev avatar ItsMeDelanoDev commented on August 20, 2024

@samvloeberghs No problem, what in the plugin doesn't fit your needs if i may ask?

from localize-router.

samvloeberghs avatar samvloeberghs commented on August 20, 2024

@dneeleman (also check my updated comment above)

Nothing very general, my architecture ( mainly in how I build urls ) and the way I serve the specific app made this plugin not useful. I would use it in other, more common and trivial, cases I believe ..

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.