This eslint plugin allows you to enforce certain rules in your ICU message.
Then in your eslint config:
Currently this uses
react-intl as hooks to verify the message. Therefore, in your code use 1 of the following mechanisms:
This will check against
$formatMessage function calls in both your JS/TS & your SFC
.vue files. For example:
This blacklists usage of specific elements in ICU message.
- Certain translation vendors cannot handle things like
description in the message descriptor.
- Description provides helpful context for translators
description to always be a string literal instead of function calls or variables. This is helpful for extraction tools that expects
description to always be a literal
defaultMessage in the message descriptor.
- Can be useful in case we want to extract messages for translations from source code. This way can make sure people won't forget about defaultMessage
defaultMessage to always be a string literal instead of function calls or variables. This is helpful for extraction tools that expects
defaultMessage to always be a literal
Makes sure all values are passed in if message has placeholders (number/date/time/plural/select/selectordinal). This requires values to be passed in as literal object (not a variable).
ignoreList: List of placeholder names to ignore. This works with
react-intlso we don't provide false positive for ambient global tag formatting
Enforce certain plural rules to always be specified/forbidden in a message.
- It is recommended to always specify
otheras fallback in the message.
- Some translation vendors only accept certain rules.
This make sure placeholders are not camel-case.
- This is to prevent case-sensitivity issue in certain translation vendors.
This prevents usage of emoji in message.
- Certain translation vendors cannot handle emojis.
- Cross-platform encoding for emojis are faulty.
This prevents usage of multiple consecutive whitespaces in message.
- Consecutive whitespaces are handled differently in different locales.
\linebreaks in JS string which results in awkward whitespaces.
This prevents specifying multiple plurals in your message.
- Nested plurals are hard to translate across languages so some translation vendors don't allow it.
This prevents specifying offset in plural rules in your message.
- Offset has complicated logic implication so some translation vendors don't allow it.
This enforces generated ID to be set in
Pipelines can enforce automatic/manual ID generation at the linter level (autofix to insert autogen ID) so this guarantees that.
idInterpolationPattern: Pattern to verify ID against
This bans explicit ID in
We generally encourage automatic ID generation due to these reasons. This makes sure no explicit IDs are set.
Make sure a sentence is not too complex. Complexity is determined by how many strings are produced when we try to flatten the sentence given its selectors. For example:
has the complexity of 2 because flattening the plural selector results in 2 sentences:
I have a dog &
I have many dogs.
Default complexity limit is 20 (using Smartling as a reference)