-
-
Notifications
You must be signed in to change notification settings - Fork 574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ng2-translate on Angular 2.0.0 with Angular CLI #249
Comments
Hi, I tried to install it today. Version: Added the following to my module (/app/app.module.ts):
And my homepage component (/app/homepage/homepage.component.ts):
My view:
It outputs homepage.title (removing the curly brackets), doesn't pick up the translation (no error shown in the console). |
@vincentp I have exactly the same thing. Did you find a solution? |
I didn't dig further, no solution yet |
I think I found the problem. Once I moved my i18n folder under src, everything worked. |
I also encountered a problem when I used Angular CLI, it raised an error.
|
Please read this comment #219 (comment) @hantsy nothing to with Angular CLI. Make sure you import TranslateModule in your shared module. |
@SamVerschueren Thanks for your quick response. Of course, I added TranslateModule. Just pushed my sample codes, https://github.com/hantsy/angular2-sample/, under the vanilla folder. https://github.com/hantsy/angular2-sample/blob/master/vanilla/src/app/app.module.ts |
@SamVerschueren I have just tried, get lang value from Component is working. I added the following to
But I added https://github.com/hantsy/angular2-sample/blob/master/vanilla/src/app/shared/navbar.component.html |
@SamVerschueren I found I can see my the content from
I added a standalone module to configure
|
if you're using html5 urls, then you shouldn't use the path |
@ocombe I have tried both, none of them is working. always printing missing key:[xxx] in codes, and translate pipe still does not work. |
Have you manually checked if that file actually is present in your dist directory? |
It seems Angular CLI does not created a dist folder at runtime when in development env. As I said above, I can get the translation content via URL directly, http://localhost:4200/assets/en.json, if the file is found by ng2-translate, why the translations are not found in this file. The codes is here. https://github.com/hantsy/angular2-sample/blob/master/vanilla Translations files are in assets/i18n folder. |
@hantsy Thanks for the code. Could you point me to the file where it tries to load a value with a certain key but can't find it? |
@hantsy I also created a repository that shows how it works with |
I was trying to load a vlaue in the My config is almost like, except I use the arrow function instead of explicit function as factory. But it does not work, unfortunately, ng2-translate does not raised helpful exception to indicate where is wrong. |
Could you confirm that it does not load both of them? https://github.com/hantsy/angular2-sample/blob/master/vanilla/src/app/app.component.ts#L22-L23 |
@SamVerschueren All printed missing key [xxxx](as my MyMissingTranslationHandler .) |
@hantsy The docs state:
The language file is not yet loaded when you call this.translate.get('posts').subscribe(t => {
console.log(t); //=> 'Posts'
}); But most of the time you can do everything with the To come back to your issue regarding the
Yes you added import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { TranslateModule } from 'ng2-translate'; // <- THIS
import { ShowAuthedDirective } from './show-authed.directive';
import { NavbarComponent } from './navbar.component';
import { FooterComponent } from './footer.component';
@NgModule({
imports: [
CommonModule,
RouterModule
],
declarations: [
ShowAuthedDirective,
NavbarComponent,
FooterComponent
],
exports: [
TranslateModule, // <- THIS
ShowAuthedDirective,
NavbarComponent,
FooterComponent
],
})
export class SharedModule { } |
@SamVerschueren Defining a shared module is not a must, I checked the ng2-translate documentation. I have read the Angular style guide. I am confused why all of other modules work well, but this module is an exception. For the |
Nope it isn't, if you are not using that approach, make sure to import
The docs are clear about this. |
I'm closing this as the original question was answered. |
Thanks. |
I'm submitting a Question
Current behavior
Not working with latest version of Angular CLI 1.0.0-beta.16
The text was updated successfully, but these errors were encountered: