Skip to content

Commit

Permalink
Merge pull request #9581 from nanaya/join-one
Browse files Browse the repository at this point in the history
Fix joining one component
  • Loading branch information
notbakaneko authored Dec 2, 2022
2 parents 6ce1af0 + 9ac23fd commit 355aff9
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 355aff9

Please sign in to comment.