-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
i18nline with Preact-CLI #6
Comments
Does not ring a bell for me. Unfortunately I have not yet tried preact-18nline i.c.w. preact-cli. |
In package.json: |
Ay yes sorry should have seen that. |
I think I fixed the issue with the |
Hi @chuikoffru I'm closing this issue, but feel free to comment or open a new issue if it's not fixed or you have other problems. Thanks for trying preact-i18nline and for taking the time to report issues. Much appreciated! |
Hi @Download , I recently discovered an issue, when running
|
This suggests the code is not being transpiled by Babel correctly. Can you post the commands you used to create this project (so I can try to reproduce)? And did you create/change preact.config.js and if so, can you post that here as well? Can you try to create a preact project from scratch and follow the steps for setting up a project as outlined here and here? Does this work for you? Thank you for trying out preact-i18nline and for taking the time to report feedback. It is much appreciated! |
Project was created with: export default (config, env, helpers) => {
// Use Preact CLI's helpers object to get the babel-loader
let babel = helpers.getLoadersByName(config, 'babel-loader')[0].rule;
// Update the loader config to include preact-i18nline
babel.loader = [
{ // create an entry for the old loader
loader: babel.loader,
options: babel.options
},
{ // add the preact-i18nline webpack loader
loader: 'preact-i18nline/webpack-loader'
}
];
// remove the old loader options
delete babel.options;
}; I will create another project from scratch later the day, because I am currently at work. Thanks for reaching out! |
So these are the steps I did, to recreate the issue.
import { h, Component } from 'preact';
import { Link } from 'preact-router/match';
import style from './style';
import I18n from "../../i18n";
export default class Header extends Component {
constructor(props) {
super(props);
this.state = {
key: 0
}
}
translate() {
I18n.changeLocale("en");
}
render() {
I18n.on("change", locale => {
// to avoid this.forceUpdate()
this.setState({ key: Math.random() });
});
return (
<header class={style.header}>
<h1 translate="yes">Preact App</h1>
<nav>
<Link activeClassName={style.active} href="/">Home</Link>
<Link activeClassName={style.active} href="/profile">Me</Link>
<Link activeClassName={style.active} href="/profile/john">John</Link>
<button onclick={this.translate}>translate</button>
</nav>
</header>
);
}
}
Hope this helps :) |
Thanks this does help. One question still though. If you just run the project with |
|
This issue baffles me. I am not convinced there is an issue with i18nline here but I understand it would be helpful if you could test with Jest :p I will leave this issue open but I am currently not able to dive into it. The fact that If you find a solution, please do let me know! I will do the same. |
Mmmmmmm wait.... I just realized something... There is The Does your project have a I guess you have to add this when not using Webpack, but again I am not sure. As an alternative you could try to replace the EDIT: references: |
Ok, so... there is this book coming up that I have been working on that has a chapter about internationalization with Preact CLI. I can't share any of the book of course, but you can have a look at the example app that we published to Github for this book: This repo has a branch C:\ws\preact-book-example\src\tests>node ../../node_modules/jest/bin/jest.js
PASS .\Item.test.js
<Item />
√ should render a list item
PASS .\CommentItem.test.js
<CommentItem />
√ should render a comment item (16ms)
√ should render a comment replies
PASS .\CommentsList.test.js
<CommentsList />
√ should render a list of comments
PASS .\header.test.js
<Header />
√ should render a title and nav
PASS .\HNList.test.js
<HNList />
√ should a HNList of articles (16ms)
√ should have called fetch()
Test Suites: 5 passed, 5 total
Tests: 7 passed, 7 total
Snapshots: 6 passed, 6 total
Time: 5.897s
Ran all test suites. I am now sorta committed to figure this thing out. Damn you, posing these baffling problems that my mind cannot let go of! What will come of my duties now? 😀 Anyway I will see if I can reproduce using your repro steps. |
Ok, so following your reproduction steps, I can indeed reproduce this issue. And I now think I understand why we did not encounter it in our example app. In our example app, we import If you wanted to make this a pure unit test, you can mock the I'm laying it to rest now. If you come up with a way to make Jest just understand |
Wow, first of all thank you for your dedication to this problem! I will try your proposals as soon as possible and will report my solutions. Thanks again! |
BTW, if you just import |
Hello again, I think the problem was really, that I imported the I18n object from the generated index.js file instead of the i18nline package. Thanks again for your time and dedication to this problem! Much appreciated! Cheers |
Hi @yduman
Yes, agreed. My ramblings above about mocking only apply when you want to test the actual change locale functionality (your translate button). In that case, you need function If you finish your project I would be glad to hear from you! It would be really cool to add some projects using preact-i18nline to the README. |
I guess that I really can't share the project since we try to pitch Preact to very well known client. Compliance and stuff... |
Hi, I create project by Preact-CLI
Next,
npm i preact-i18nline i18nline
I create i18n/en.json
Add strings to package.json:
{ "i18n": { "plugins": [ "preact-i18nline" ], "directories" : "src", "patterns" : ["**/*.js", "**/*.jsx"], "outputFile" : "i18n/en.json" }, "scripts": { "trlt": "i18nline export" } }
Run
npm run trlt
And...
The text was updated successfully, but these errors were encountered: