Wielojęzyczność
i18n/no-string-concat
User-facing sentences are one message with placeholders, never joined from translated fragments and values.
umiarkowanastatycznefe-i18n
Dlaczego
Word order, grammatical case and agreement differ between languages, so "You have" + 3 + "items" cannot be translated: a Polish translator needs the number in the middle and a different noun form for 3 and for 5. Fragments also lose context for the translator.
Poprawka
Write the whole sentence as one message with named placeholders and let the library insert the values: t('cart.items', { count }) with "You have {count, plural, one {# item} other {# items}}". Pass components for links and emphasis through the library's rich text API instead of splitting the string.
Przykłady
// bad
t('cart.has') + ' ' + count + ' ' + t('cart.items')
// good
t('cart.items', { count }) // "You have {count, plural, one {# item} other {# items}}"Źródła
Fakty
- Identyfikator
i18n/no-string-concat- Waga
- umiarkowana
- Sprawdzanie
- statyczne sprawdzane w kodzie źródłowym przez
audit - Dotyczy plików
jsxvuesvelteastrohtml- Uczy jej skill
fe-i18nInternationalisation- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain i18n/no-string-concat