Code Monkey home page Code Monkey logo

Comments (2)

robisim74 avatar robisim74 commented on June 20, 2024

Hi @johaven,

I assume you are using dynamic import as in the recent documentation example (I remind you here that it is just an example: implemeting L10nTranslationLoader you can load the file in the way you prefer).

Angular v17 uses esbuild by default. In newer bundlers, such as esbuild, vite, and rollupjs, the return value of a dynamic import is a javascript object.

Now in your example, you are using keys that are valid in a json, but are not valid in a javascript object, because they are not valid variable names.

You have two alternatives: implement a different loader, or import and transform the files by yourself, like this:

import it from '../i18n/it-IT/app.json';
import en from '../i18n/en-US/app.json';

@Injectable() export class TranslationLoader implements L10nTranslationLoader {

  public get(language: string, provider: L10nProvider): Observable<{ [key: string]: any }> {
    let data: any;
    switch (language) {
      case 'it-IT':
        data = it;
        break;
      default:
        data = en;
        break;
    }
    return of(JSON.parse(JSON.stringify(data)));
  }
}

and add "resolveJsonModule": true in tsconfig.

Hope this helps!

from angular-l10n.

johaven avatar johaven commented on June 20, 2024

@robisim74 thank you for your explanation :)

from angular-l10n.

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.