question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use without files?

See original GitHub issue

I’m submitting a … (check one with “x”)

[ ] bug report => check the FAQ and search github for a similar issue or PR before submitting
[x] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request

I do not want to use files to store my translations, rather load from an api and use translate.setTranslation() to add them later.

What I did:

added to app.module.ts

     imports: [ ... TranslateModule.forRoot(), ... ]

added to app.component.ts

    this.translate.setDefaultLang('en');
   this.translate.setTranslation('en', {abc: 123});

However when I run the app, the console says: GET http://127.0.0.1:6300/i18n/en.json 404 (Not Found) zone.js:1805

Whats the problem?

Please tell us about your environment:

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

12reactions
whyboriscommented, Dec 16, 2018

Thank you for this question and resolution. I wanted to include my translations as part of the application (not loaded over HTTP) so I implemented things thus:

Module:

imports: [ ... TranslateModule.forRoot(), ... ]

en.ts:

export const English = {
  HOME: {
    TITLE: 'Hello in English!',
  }
};

Component:

import { English } from '../../i18n/en';
...
    this.translate.setDefaultLang('en');
    this.translate.use('en');
    this.translate.setTranslation('en', English );

Template:

  <span>{{ 'HOME.TITLE' | translate }}</span>
2reactions
SamVerschuerencommented, Mar 24, 2017

That’s the thing, don’t use the TranslateHttpLoader because as the name implies, it’s loading over Http.

Use the loader defined by @kamok and return the data that you want.

export class TranslationLoaderService implements TranslateLoader {

  constructor(private http: Http) {
  }

  getTranslation(lang: string): Observable<any> {
    if (lang === 'en') {
      return Observable.of({
        HELLO: 'Hi there'
      });
    }else {
      return Observable.of({
        HELLO: 'Hola'
      });
    }
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Use Google Drive files offline - Android
Save files for offline use. Open Google Drive Drive . Next to the file, tap More More . To save a file offline,...
Read more >
Use the Files app on your iPhone, iPad, or iPod touch
On your iPhone, iPad, or iPod touch, open the Files app. Don't see the blue Files app icon on your Home Screen? Just...
Read more >
How to share files offline without an internet connection - Adobe
Share files offline via Bluetooth. · Use your device's Bluetooth menu to connect to a nearby receiver, be it a phone or computer....
Read more >
How to Fix Hard Disk Full but No Files on Windows 10?
Hard disk full but no files ? Or c drive is full without reason in windows 10? Fixed now! In this video, you...
Read more >
Save disk space with OneDrive Files On-Demand for Windows
You can open a locally available file anytime, even without Internet access. If you need more space, you can change the file back...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found