-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
transifex/restructure: add context to whitespace errors #832
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely a clearer description of the error!
bin/util/transifex.js
Outdated
console.error(` [${message}]`); // eslint-disable-line no-console | ||
console.error(` [${''.padStart(badLength, '^').padStart(badWhitespace.index + badLength, ' ').padEnd(message.length, ' ')}]`); // eslint-disable-line no-console | ||
throw new Error(`unexpected whitespace in message '${path}' at index ${badWhitespace.index} ("${message}")`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this doesn't fully account for the difference between message
and form
. As an example, for the pluralized message App User | App Users
, the second plural form is the one with multiple spaces. Here, the entire message would be shown (both plural forms), but then the index from the match on only the second form would be used to position the ^^^ and describe the index of the unexpected whitespace.
How about something like:
const error = forms.length === 1
? `unexpected white space in message '${path}'`
: `unexpected white space in plural form of message '${path}'`;
console.error(`${error}:`); // eslint-disable-line no-console
const badLength = badWhitespace[0].length;
console.error(` [${form}]`); // eslint-disable-line no-console
console.error(` [${''.padStart(badLength, '^').padStart(badWhitespace.index + badLength, ' ').padEnd(message.length, ' ')}]`); // eslint-disable-line no-console
if (forms.length !== 1)
console.error(`The entire message is: [${message}]`); // eslint-disable-line no-console
throw new Error(`${error} at index ${badWhitespace.index} ("${form}")`);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
I've updated to consider the index of the form. Some example errors:
single-value
unexpected white space in translation string 'datasets':
[Data sets]
[ ^^ ]
...
Error: unexpected whitespace in message 'datasets' at index 4 ("Data sets")
singular of multi-value
unexpected white space in translation string 'appUser[0]':
[App User]
[ ^^ ]
...
Error: unexpected whitespace in message 'appUser[0]' at index 3 ("App User | App Users")
plural of multi-value
unexpected white space in translation string 'appUser[1]':
[App Users]
[ ^^ ]
...
Error: unexpected whitespace in message 'appUser[1]' at index 3 ("App User | App Users")
ec25972
to
f47d54a
Compare
Example
Add a new translation string:
Current
master
This PR