simplelocalize / simplelocalize-cli

SimpleLocalize CLI is a developer-friendly command-line tool for uploading and downloading translation files
https://simplelocalize.io
MIT License
56 stars 11 forks source link

Not all ids are extracted from react-intl defineMessages #101

Closed cwitteveen closed 3 months ago

cwitteveen commented 5 months ago

The regex defined in the ReactIntlKeyExtractor to extract ids from the defineMessages function only ever matches the first id defined, and it also only matches when the id is on the same line as the key in the object. So nicely formatting your code breaks the extraction.

Regex in the code: https://github.com/simplelocalize/simplelocalize-cli/blob/2e8bf5fcfc7daf9cbf21453a80ddf7dbc4ce0908/src/main/java/io/simplelocalize/cli/extraction/keys/ReactIntlKeyExtractor.java#L32

I entered the regex on regex101.com and tested it with a code sample.

  1. Screenshot with original test string -> no matches image
  2. Removed the newlines within the message object -> only first id matches image
jpomykala commented 5 months ago

Hey @cwitteveen

thanks for the report. Could you please paste the file or part of the file for which the extraction doesn't work?

it also only matches when the id is on the same line as the key in the object

It's not an issue, because code is converted to a one line before looking for IDs:

https://github.com/simplelocalize/simplelocalize-cli/blob/2e8bf5fcfc7daf9cbf21453a80ddf7dbc4ce0908/src/main/java/io/simplelocalize/cli/extraction/keys/ReactIntlKeyExtractor.java#L18