Translation is not applied in simple TS
See original GitHub issueWe are using ttag in normal JSX and it works perfectly.
However, we’re also loading some data from TS files and ttag does not work properly there.
Working example:
// Taste.tsx
<h2 className="title center-text">{t`Taste`}</h2>
Non-working example:
// (same file)
const getTastes = () => {
return tastes.map((taste, index) => {
return (
<li className="tastes" key={index}>
<Circle size="2em" color={taste.color} />
<p className="option">{taste.name}</p>
</li>
);
});
};
<ul>{getTastes()}</ul>
// (Taste.ts)
export const TASTE = new Map<string, ITaste>([
['FLORAL', { name: t`Floral`, color: '#F3B8B7' }],
‘Floral’ is still showing up as the given text.
Some things seem to be working:
- Floral is extracted to the .po file
- Floral is in the JSON file with the translation
- In the output, there is no trace of the
t
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
ngx translate - Using get or instant method in ts file is not ...
in app.module.ts try: import {APP_INITIALIZER, Injector, NgModule} from '@angular/core'; import {LOCATION_INITIALIZED} from ...
Read more >How to translate your Angular app with ngx-translate
1. Add ngx-translate to your Angular application 2. Set up the TranslateService in your app.module.ts 3. Create your main language translation file (in...
Read more >Internationalization and Localization with Qt Quick | Qt 6.4
ts files are XML files with the source texts and a place for the translated text. The updated .ts files are converted into...
Read more >Making Your App Ready for Translations
The basic concept is that all strings which must be translated are separated into a JSON file per language. The app's html and...
Read more >Angular I18n: How to Internationalize with ngx-translate | Phrase
The ngx-translate library allows us to change the language of the application at runtime without reloading the whole app. However, Angular ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @lroellin! I suppose the problem here is that this code is executed before ttag locale was applied:
You should ensure that you call
useLocale
before anyttag
functions are executed. You can look here for example: https://github.com/ttag-org/CRA-runtime-example/blob/master/app/src/App.js#L1Here we are setting up the appropriate language in the first import of the app entry point:
Please, let me know if that works for you.
Alternatively, you can also use function to execute
t
later:Hi! We now fixed the issue by always setting the locale (we have a side-effecty import). Thanks!