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 properly integrate the aurelia-i18n plugin in a TypeScript with Webpack scenario?

See original GitHub issue

First of all, I’m new to Aurelia, so please forgive me if this is somewhat of a noob issue.

I set up an Aurelia project with TypeScript and Webpack using aurelia-cli v2.0.2 and tried to follow the official docs on aurelia.io. I want to use the Aurelia loader to provide i18n with translation.json files. However, I wasn’t able to correctly configure i18next, it always says that the corresponding JSON files could not be loaded:

Unable to load translation files

My main.ts file looks like this:

import { Aurelia } from 'aurelia-framework';
import * as environment from '../config/environment.json';
import { PLATFORM } from 'aurelia-pal';
import { Backend, TCustomAttribute } from 'aurelia-i18n';

export function configure(aurelia: Aurelia): void {
    aurelia.use
        .standardConfiguration()
        .developmentLogging(environment.debug ? 'debug' : 'warn')
        .plugin(PLATFORM.moduleName('aurelia-i18n'), instance => {
            const aliases = ['t', 'i18n'];
            TCustomAttribute.configureAliases(aliases);
            instance.i18next.use(Backend.with(aurelia.loader));

            return instance.setup({
                backend: {
                    loadPath: './locales/{{lng}}/{{ns}}.json'
                },
                attributes: aliases,
                lng: 'de',
                fallbackLng: 'en',
                debug: true
            });
        });

    if (environment.testing) {
        aurelia.use.plugin(PLATFORM.moduleName('aurelia-testing'));
    }

    aurelia.start().then(() => aurelia.setRoot(PLATFORM.moduleName('app')));
}

What I tried so far:

  • I removed the dot in in the path. According to this Discourse request, Webpack cannot handle dots in paths, but loadPath: 'locales/{{lng}}/{{ns}}.json' does not fix the problem.
  • I also tried to omit the Aurelia loader and apply the parsed JSON files directly to resources, but using import * as en from './locales/en/translation.json' didn’t work as well. I assume this has to do with the webpack configuration where the default json loader was removed a while ago? However, when I simply reintroduce it, compilation failed.

Import of json files fails

My next steps will be to re-add the JSON loader to Webpack for the translation files only. However, I think that the docs need to be updated so that the Aurelia loader can be used in a Webpack scenario.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
feO2xcommented, Feb 11, 2021

Sure - I will get to it in the upcoming days.

0reactions
Sayan751commented, Jul 4, 2021

I am closing this issue, as it seems to be resolved. Please feel free to continue the discussion.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Integrating TypeScript with Webpack | by Uday Hiwarale
In this lesson, we are going to learn how to compile a TypeScript project using Webpack. This setup becomes necessary if you want...
Read more >
TypeScript - webpack
In this guide we will learn how to integrate TypeScript with webpack. Basic Setup. First install the TypeScript compiler and loader by running:...
Read more >
I18N | Aurelia
Webpack. Install the aurelia-i18n plugin in your project using npm and the following command: Shell.
Read more >
Using aurelia-i18n with webpack + typescript + ... - GitHub
I was, however, able to determine that aurelia-i18n itself was working fine. Therefore, I designed a workaround. Firstly, I converted the ...
Read more >
Using webpack with TypeScript - LogRocket Blog
Learn how to use webpack to compile TypeScript to JavaScript and bundle source code into a single JavaScript file.
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