Comments (8)
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.
@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.
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.
on it, will update you asap
from localize-router.
@samvloeberghs Any updates? Would like to integrate this in our Universal App as well.
from localize-router.
@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.
@samvloeberghs No problem, what in the plugin doesn't fit your needs if i may ask?
from localize-router.
@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)
- localize-router not working as expected with Angular Universal: server-side rendering HOT 6
- Function traverseSnapshot not properly assembling the new translated route. HOT 11
- Localize router unable to pass data params on an empty path HOT 2
- Out of sync localize pipe HOT 1
- changeLanguage does not work for route with parameters HOT 6
- After language is switch, back button redirect into 404
- InitialNavigation enabled crashes Routing HOT 7
- Lazy loaded component is not bootstrapping HOT 4
- can't trigger window.load
- Angular 8 + IVy support HOT 1
- Can't make it, need tutorial. HOT 1
- Angular recognize only the default lang in SSR. HOT 4
- Angular 8 support HOT 6
- Extra slash translating root route
- LazyLoad Child Componenter onPage Refresh re-directs:Home Page HOT 1
- Unhandled promise rejection HOT 6
- Custom Cookies expiration
- Children routes issue lazy load module HOT 5
- Problem with Initial Navigation in RouterModule HOT 4
- LocalizeRouterModule.forRoot returns a ModuleWithProviders type without a generic type argument HOT 20
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from localize-router.