Skip to content

Commit

Permalink
Fix composed withTranslations
Browse files Browse the repository at this point in the history
  • Loading branch information
rtsao committed Aug 12, 2023
1 parent 918a970 commit e72fb23
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
8 changes: 6 additions & 2 deletions fixtures/i18n-with-translations/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { withTranslations } from 'fusion-plugin-i18n-react';

export default withTranslations(['test', 'foo'])(({translate}) => {
return <input placeholder={translate('test', {name: 'world'})} />;
export default withTranslations(['test', 'foo'])(({ translate }) => {
return <input placeholder={translate('test', { name: 'world' })} />;
});

export default compose(withReducer(baz), withTranslations(['bar'])(({ translate }) => {
return <input placeholder={translate('bar')} />;
}));
13 changes: 10 additions & 3 deletions fixtures/i18n-with-translations/output.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import _fusionPluginI18nChunkTranslationMap from "virtual:fusion-vite-i18n-map";
import { withTranslations } from 'fusion-plugin-i18n-react';
export default withTranslations(['test', 'foo'])(({
translate
}) => {
export default withTranslations([
'test',
'foo'
])(({ translate }) => {
return <input placeholder={translate('test', {
name: 'world'
})} />;
});
export default compose(withReducer(baz), withTranslations([
'bar'
])(({ translate }) => {
return <input placeholder={translate('bar')} />;
}));
_fusionPluginI18nChunkTranslationMap.add("/path/to/file.js", [
"vite-i18n-chunk"
], [
"bar",
"foo",
"test"
]);
1 change: 1 addition & 0 deletions packages/fusion/transform/src/i18n/analyze_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ impl Visit for Analyzer<'_> {
}

fn visit_call_expr(&mut self, call_expr: &CallExpr) {
call_expr.visit_children_with(self);
let error_msg = "The withTranslations hoc must be called with an array of string literal \
translation keys.";
match &call_expr.callee {
Expand Down

0 comments on commit e72fb23

Please sign in to comment.