Comments (2)
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.
@robisim74 thank you for your explanation :)
from angular-l10n.
Related Issues (20)
- How i can translate the word HOT 1
- feature: easily register and bundle translation data with a lazy loaded module HOT 3
- Number format options HOT 7
- Release a version with peerDependencies compatible with RxJS v7 HOT 3
- split big files HOT 2
- Namespace 'Intl' has no exported member 'RelativeTimeFormatOptions' HOT 3
- [Question] Differences / Benefits vs ngx-translate? HOT 3
- Setting available languages from Database HOT 5
- Problems after Upgrading HOT 2
- locale.language is empty, Error: angular-l10n (L10nDefaultTranslationLoader): Asset not found HOT 2
- Incorrect date format HOT 2
- Namespace 'Intl' has no exported member 'ListFormatOptions' HOT 1
- possibility to configure PARSE_DATE_STYLE const. Configure full, long,medium,short options HOT 2
- Refreshing page redirects to fallback HOT 5
- Opening subpages in tabs works - sometimes HOT 1
- I encountered this problem: Unexpected value 'TranslateModule' imported by the module 'SharedModule'. Please add an @NgModule annotation. HOT 2
- angular-l10n used in angular component being imported from react parent application as library doesnot work HOT 8
- Is it possible to use angular-l10n to support custom translations in library1 while the config for translations stays in the main app that uses library1? HOT 10
- Allow for template elements inside of params HOT 4
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 angular-l10n.