Closed acangiani closed 5 years ago
@acangiani Thanks for the report. withText
is also capable of accepting a function which will receive props
, and resolve <Text>
components with fields. I gave your App a try and the following changes seemed to make the title render correctly:
@withText((props) => ({
title: <Text id="second.title" fields={{ field: props.slug }} />
}))
export default class SecondView extends Component {
render(props, state) {
return (
<div>
<Helmet
title={props.title}
meta={[
{name: "title", content: props.title },
]}
/>
</div>
);
}
};
Let me know if that resolves the issue.
@pl12133 your code resolves the issue!
Thank you for your time and for the quick response!
On the project I'm currently working we needed to support several languages so we ended upusing preact-helmet to inject the title and the corresponding metatags for each of the App views, but I'm unable to make it work with
{{fields}}
placeholders, so I created this sample project to demonstrate the issue.How to install and run the sample project
git clone git@github.com:acangiani/preact-i18n-issue.git
npm install
npm run start
First view
This one works fine and correctly adds the title and the title metatag.
Doing
curl http://localhost:3000/
, this outputs the following html:Second view
On the other hand on this view I needed to use a
{{field}}
placeholder, so doingcurl http://localhost:3000/test
, this outputs the following html:Things I tried
@withText
as decorator on the second view, but I cannot access the props.withText
as a functional component wrapper so to obtain the translated text but I couldn't make it work.but I only obtained the default text regardless of the i18n definitions loaded on the
IntlProvider
.Bottom line what I need it's to obtain the translated text as a string but I'm unable to do so, could you please help with this?