Skip to content

Commit

Permalink
Fix joining one component
Browse files Browse the repository at this point in the history
  • Loading branch information
nanaya committed Dec 2, 2022
1 parent 6ce1af0 commit 9ac23fd
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions resources/assets/lib/utils/lang.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ export function joinComponents(array: React.ReactElement[], key = 'common.array_
if (array.length > 0) {
nodes.push(array[0]);

const lastIndex = array.length - 1;
const lastConnector = lastIndex === 1 ? trans(`${key}.two_words_connector`) : trans(`${key}.last_word_connector`);
const connector = trans(`${key}.words_connector`);
if (array.length > 1) {
const lastIndex = array.length - 1;
const lastConnector = lastIndex === 1 ? trans(`${key}.two_words_connector`) : trans(`${key}.last_word_connector`);
const connector = trans(`${key}.words_connector`);

for (let i = 1; i < lastIndex; i++) {
nodes.push(<React.Fragment key={array[i].key}>{connector}{array[i]}</React.Fragment>);
}
for (let i = 1; i < lastIndex; i++) {
nodes.push(<React.Fragment key={array[i].key}>{connector}{array[i]}</React.Fragment>);
}

nodes.push(<React.Fragment key={array[lastIndex].key}>{lastConnector}{array[lastIndex]}</React.Fragment>);
nodes.push(<React.Fragment key={array[lastIndex].key}>{lastConnector}{array[lastIndex]}</React.Fragment>);
}
}

return <>{nodes}</>;
Expand Down

0 comments on commit 9ac23fd

Please sign in to comment.