diff --git a/src/parser.js b/src/parser.js
index 0c2a202..d243d19 100644
--- a/src/parser.js
+++ b/src/parser.js
@@ -614,6 +614,28 @@ class Parser {
}, {});
}
+ // Member Expression (e.g. i18nKey={foo.bar})
+ if (expression.type === 'MemberExpression') {
+ acc[name] = expression.object.name + '.' + expression.property.name;
+ }
+
+ // Conditional Expression (e.g. i18nKey={true ? 'foo' : 'bar'})
+ if (expression.type === 'ConditionalExpression') {
+ acc[name] = expression.consequent.value;
+ }
+
+ // Unary Expression (e.g. i18nKey={foo?.bar})
+ if (expression.type === 'UnaryExpression') {
+ acc[name] = expression.alternate.object.name + '.' + expression.alternate.property.name;
+ }
+
+ // Binary Expression (e.g. i18nKey={foo.bar - 1})
+ if (expression.type === 'BinaryExpression') {
+ if (expression.left.type === 'MemberExpression' && expression.right.type === 'Literal') {
+ acc[name] = expression.left.object.name + '.' + expression.left.property.name;
+ }
+ }
+
// Template Literal
if (expression.type === 'TemplateLiteral') {
acc[name] = expression.quasis
diff --git a/test/react-i18next/i18n.js b/test/react-i18next/i18n.js
index 5cfcda3..543155d 100644
--- a/test/react-i18next/i18n.js
+++ b/test/react-i18next/i18n.js
@@ -28,6 +28,8 @@ i18n.init({
transTest2InV2: 'Hello <1>{{name}}1>, you have {{count}} message. Open <5>hear5>.',
transTest2InV2_other:
'Hello <1>{{name}}1>, you have {{count}} messages. Open <5>here5>.',
+ transPluralWithCountAsMemberExpression: '{{count}} item',
+ transPluralWithCountAsMemberExpression_other: '{{count}} items',
testTransKey1: '<0>{{numOfItems}}0> item matched.',
testTransKey1_other: '<0>{{numOfItems}}0> items matched.',
testTransKey2: '<0><0>{{numOfItems}}0>0> item matched.',
@@ -53,7 +55,9 @@ i18n.init({
escapeValue: false, // not needed for react!!
formatSeparator: ',',
format(value, format) {
- if (format === 'uppercase') return value.toUpperCase();
+ if (format === 'uppercase') {
+ return value.toUpperCase();
+ }
return value;
},
},
diff --git a/test/react-i18next/trans-render.test.js b/test/react-i18next/trans-render.test.js
index 494e393..a882a82 100644
--- a/test/react-i18next/trans-render.test.js
+++ b/test/react-i18next/trans-render.test.js
@@ -1,6 +1,6 @@
/** @jest-environment jsdom */
-import React from 'react';
import { render } from '@testing-library/react';
+import React from 'react';
import {
Trans,
withTranslation,
@@ -309,7 +309,7 @@ describe('trans complex - count only in props', () => {
// prettier-ignore
return (