-
-
Notifications
You must be signed in to change notification settings - Fork 282
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
MBS-13496: Support attributes with spaces in link phrase interpolation #3186
base: master
Are you sure you want to change the base?
Conversation
@@ -46,6 +46,7 @@ test('expand2', function (t) { | |||
); | |||
expandText('An {apple_fruit}', null, 'An {apple_fruit}'); | |||
expandText('An {apple_fruit}', {apple_fruit: 'apple'}, 'An apple'); | |||
expandText('An {apple fruit}', {'apple fruit': 'apple'}, 'An apple'); |
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.
It'd be nice to have two more small tests for condSubstStart
and linkSubstStart
. :)
Also, I think MusicBrainz::Server::Translation::expand
already supports this, but perhaps add a small test for the Perl side, too? There are some existing ones in t/lib/t/MusicBrainz/Server/Translation.pm.
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.
Do I understand correctly that condSubstStart
would be used in tests such as expandText('{a:%{b:%|}%|}', {a: '0', b: ''}, '00');
? And is linkSubstStart
tested in tests like this?
expandHtml(
'A {apple_fruit|<strong>{prefix} APPLE!</strong>}',
{apple_fruit: 'http://www.apple.com', prefix: 'dang'},
'A <a href="http://www.apple.com"><strong>dang APPLE!</strong></a>',
);
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 added a couple tests to the Perl file :)
Using the new "a cappella" attribute was breaking link phrase interpolation, because spaces were not accepted as part of the interpolated "variable name". We already had several attributes with spaces in their name though, we just had gotten lucky we were not using any of them in link phrases until now. Just adding spaces to the allowed characters doesn't seem to cause any new issues, so it seems good enough for our needs.
@brainzbot please retest this. |
@@ -206,7 +206,7 @@ export const createTextContentParser = <T, V>( | |||
return mapValue(text); | |||
}; | |||
|
|||
const varSubst = /^\{([0-9A-z_]+)\}/; | |||
const varSubst = /^\{([0-9A-z_ ]+)\}/; |
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.
Beginning/ending spaces should probably not be allowed.
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.
Is there a reason why they shouldn't? I mean, I don't think we're going to use them, but what's the damage? We're also probably not going to use ending underscores but we allow them.
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.
To prevent using them indeed. Damage is broken interpolation and translation. Same for underscores.
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.
But that would only be a problem if we actually did add spaces at the beginning or end of variables, or a translator messed up (which is already the case even without the spaces) :) That said, if the regex can be easily changed to your preference, I have nothing against committing a suggestion for it, I just don't think we should complicate it too much otherwise.
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.
Actually I don’t think that allowing spaces in variable names is a good approach at all, see below.
Yes, at https://github.com/metabrainz/musicbrainz-weblate-checks/blob/main/weblate_musicbrainz_format_check/checks.py#L17 and tests too. A more durable implementation would be to use a slug of attribute name for variable name. In either case, the examples at https://wiki.musicbrainz.org/MusicBrainz_Server/Internationalization#Variables have to be updated accordingly. |
Do you mean that we should convert all attributes to what, replace spaces by hyphens and then check the variables? I'm not against that if it feels better, I guess, I just thought it might be more confusing but maybe not? |
By underscores, to follow the convention already in use for variables in the MusicBrainz Server code.
On the contrary, underscores make variable names more easily recognized as not translatable code by translators. |
Hmm. Well, we already support underscores, meaning it could theoretically clash between a name with a space and one with underscores, but we could probably make sure we don't mess that up at least :) |
Fix MBS-13496
Problem
Using the new "a cappella" attribute is breaking link phrase interpolation, because spaces are not accepted as part of the interpolated "variable name". We already had several attributes with spaces in their name though, we just had gotten lucky we were not using any of them in link phrases until now.
Solution
Just adding spaces to the allowed characters doesn't seem to cause any new issues, so it seems good enough for our needs.
Testing
Added one test with spaces to the
expand2
tests.Further action