Skip to content
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

ui: Use "channel" or "stream" based on server feature level #5830

Merged
merged 2 commits into from
Apr 26, 2024

Conversation

chrisbobbe
Copy link
Contributor

@chrisbobbe chrisbobbe commented Mar 5, 2024

Done at the level of TranslationProvider, which (conveniently) can
access the feature level of the active account if any.

Fixes: #5827

@chrisbobbe chrisbobbe requested a review from gnprice March 5, 2024 02:06
Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @chrisbobbe for taking care of this! Glad to see this is a lot cleaner (thanks to the idea you described on Friday and implemented here) than I was originally imagining.

The changes all look good modulo the TODOs you have, and a few small things below.

Comment on lines 17 to 18
"stream": "stream",
"channel": "channel",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit in commit message:

The messages_en.json changes were done with a handy Perl one-liner
that Greg helped me work out:

perl -i -ne 'print; print if (s/stream/channel/g || s/Stream/Channel/g)' static/translations/messages_en.json

The command can be made a bit more readable by breaking across multiple lines. Two ways to do that:

  • A single-quoted string (such as the argument to -e here) can have newlines in it. And Perl, like JS, has a syntax that generally isn't affected by newlines or indentation.
  • A line in a shell command can end in a backslash \ (outside of any quoted string), and in that case both the backslash and the newline right after it are effectively deleted so that the next line forms more of the same command.

Here, I might write:

$ perl -i -ne '
      print;
      print if (s/stream/channel/g || s/Stream/Channel/g);
    ' static/translations/messages_en.json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool; thanks!

const englishCanonicalStringOf = (type: WildcardMentionType): string => {
const englishCanonicalStringOf = (
type: WildcardMentionType,
channelTerminologyUsed: boolean,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: perhaps useChannelTerminology

When I first saw this name, I read it as indicating which "channel terminology" is being used. Then I was puzzled it was a boolean instead of some enum: which way is encoded as true, and which as false?

Then I realized what you actually mean is whether "channel terminology" is being used.

Also "used" sounds like "has been used" as much as "is being used", and here this is really about telling this code what it should use rather than informing it about what has been used (or even is being used elsewhere). So an imperative works well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting; yeah, I agree. Thanks!

const handlePress = useCallback(() => {
onPress(type, serverCanonicalStringOf(type));
}, [onPress, type]);
onPress(type, serverCanonicalStringOf(type, channelTerminologyUsed));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I guess this makes one spot where the switch is actually changing a request we make to the server! Not only the UI we show to the user.

It'd be good to flag this in… #api design, I guess. The server should make sure that it starts accepting the new form, either at the same time as the web UI switches over or before then. No harm in accepting it early — it can keep accepting the old form, and probably should do so for a good while into the future anyway — so probably it should go ahead and do so early, to reduce the risk of forgetting and having it do so only later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(If the server were tardy in starting to accept the new @channel form for wildcard mentions, we could always deal, but it'd make the conditionals here more complicated.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 23 to 30
* instead of
*
* "Notify stream": "Notify stream",
*
* and likewise for all the other languages.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* instead of
*
* "Notify stream": "Notify stream",
*
* and likewise for all the other languages.
* instead of
*
* "Notify stream": "Notify stream",
* "Notify channel": "Notify channel",
*
* and likewise for all the other languages.

I think that makes it a bit easier to see how the mapping is all happening on the message-ID side, and not the translated-string side.

Comment on lines +29 to +36
export const streamChannelRenamesMap: {| [string]: string |} = {
stream: 'channel',
'Notify stream': 'Notify channel',
'Who can access the stream?': 'Who can access the channel?',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW here's the command I used just now to help check this — a variation on the Perl one-liner that edited the messages JSON file:
<static/translations/messages_en.json perl -lne 'next unless (my ($k) = /^ *(".*"): \1/); $_ = $k; next unless (s/stream/channel/g || s/Stream/Channel/g); print "$k: $_,"'

I took that command's output, copy-pasted it between the braces of this object literal, deleted what had been here, and reformatted. The result was identical to what you have… except it added a line

  'No messages in topic: {streamAndTopic}': 'No messages in topic: {channelAndTopic}',

which indeed shouldn't be there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also occurs to me that that {streamAndTopic} string might be worth including but commented out, as a bit of a reminder of why this map isn't just a replaceAll or the like.

Comment on lines 79 to 80
|| /en[-$]/.test(language)
|| messageId === message
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
|| /en[-$]/.test(language)
|| messageId === message
|| /^en($|-)/.test(language)
|| messageId === message

The version with [-$] will match only if there's an actual $ character, which I think isn't what you intended. (It ends up doing the same thing because for language en the messageId === message condition will always hold. But clearer when the regexp part already does what that part is meant to do.)

Also I think you only want to match from the beginning (with ^), if there's somehow another match. (E.g. because of a three-letter language name, which some less-common languages have.)

Comment on lines 77 to 90
if (
renamedMessage !== renamedMessageId
|| /en[-$]/.test(language)
|| messageId === message
) {
// Prefer using `renamedMessage`, the one with "channel", when:
// - It doesn't match its American-English message ID, thanks to
// our kind volunteer translators. Or:
// - It does match its American-English message ID, but:
// - It's still appropriate to show because the UI is set to
// English. Or:
// - The message with "stream" isn't translated either. Might as
// well show the "channel" one even though it'll be in English.
return [messageId, renamedMessage];
} else {
// Otherwise, use `message`, the one with "stream".
return [messageId, message];
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bodies of these conditionals are thankfully quite short and clear. So it may make the logic easier to read if we break the conditions up a bit more, even if it means duplicating the bodies some.

Here's one possibility:

  if () {
    // The newfangled "channel" string hasn't been translated yet,
    // but the older "stream" string has.  Consider falling back to that.
    if () {
      // The language is a variety of English.  Prefer the newer terminology,
      // even though awaiting translation.  (Most of our strings don't change at all
      // between one English and another.)
      return ;
    }
    // Use the translation we have, even of the older terminology.
    // (In many languages the translations have used an equivalent
    // of "channel" all along anyway.)
    return ;
  }
  return ;

@chrisbobbe
Copy link
Contributor Author

Thanks for the review! Revision pushed.

@chrisbobbe chrisbobbe marked this pull request as draft March 6, 2024 23:28
@chrisbobbe
Copy link
Contributor Author

And converted to draft, to help prevent accidentally merging this without doing the TODOs in the commit message.

@gnprice
Copy link
Member

gnprice commented Mar 6, 2024

Thanks! All looks good modulo those TODOs.

I think you can go ahead and fill in the todo-server comments with a reference to 9.0. This is one issue that seems pretty solidly like we're going to make it part of the 9.0 release. But then the other two just mean we're waiting for the server-side changes to be ready before we can merge.

I guess one thing that would be good, since we're waiting, is to get the "channel" strings into Transifex so that people can translate them whenever they get to doing some Zulip translation. So perhaps pull out a commit that just adds to messages_en.json without yet adding the logic that uses the new strings, and then we can merge that and do tools/tx-sync.

@chrisbobbe
Copy link
Contributor Author

Makes sense! Done; revision pushed.

@gnprice
Copy link
Member

gnprice commented Mar 7, 2024

Thanks! All LGTM.

I'll go ahead and merge that first commit:
50c9656 i18n: Offer UI strings with "channel" terminology to translators
and run tools/tx-sync.

Then the remaining changes are just waiting for the server-side changes to be ready, so that we know what feature level to condition on (and can confirm that accepting @**channel** happens before then, so that just one threshold feature level suffices).

@gnprice
Copy link
Member

gnprice commented Apr 5, 2024

The server change to accept @**channel** was merged:

So that will indeed happen before the other server-side changes; and this PR is now just waiting for those other server-side changes to land so we can determine the feature-level threshold.

@gnprice
Copy link
Member

gnprice commented Apr 25, 2024

The server-side UI changes have landed — the feature level to use is 255:
https://chat.zulip.org/api/changelog#changes-in-zulip-90

So this is now ripe to update for merge.

(It looks like the main commit's commit message has a couple of elements that would have belonged instead in the commit 50c9656 that we merged earlier; ah well.)

@chrisbobbe
Copy link
Contributor Author

(It looks like the main commit's commit message has a couple of elements that would have belonged instead in the commit 50c9656 that we merged earlier; ah well.)

Ah yeah, the Perl command?

@chrisbobbe chrisbobbe marked this pull request as ready for review April 26, 2024 00:10
@chrisbobbe
Copy link
Contributor Author

chrisbobbe commented Apr 26, 2024

Thanks for the bump! Revision pushed, using that feature level, and I've unmarked as draft.

This explicitness will help us avoid a shadowed variable soon.
Done at the level of TranslationProvider, which (conveniently) can
access the feature level of the active account if any.

Fixes: zulip#5827
@gnprice gnprice merged commit 7c35635 into zulip:main Apr 26, 2024
1 check passed
@gnprice
Copy link
Member

gnprice commented Apr 26, 2024

Thanks! LGTM; merging.

Ah yeah, the Perl command?

Yeah, exactly — the bit about updating messages_en.json.

@chrisbobbe chrisbobbe deleted the pr-stream-channel-rename branch April 26, 2024 00:33
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this pull request Apr 26, 2024
Oops; this was missed because I didn't do end-to-end testing before
we merged zulip#5830.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use "stream" or "channel" based on server version
2 participants