mirror of
https://github.com/stablyai/orca.git
synced 2026-11-02 18:17:36 +00:00
* fix(i18n): localize the rest of the source control dropdown The Commit & Push, Push, Force Push, Pull, Fast-forward, Sync, Publish, abort and Push-before-PR rows and their tooltips were English literals next to rows that already go through translate(). Route them through translate(), reusing the primary button's and the conflict card's keys where the words match, and add 42 keys to the English catalog. Commit blockers stay English inside eligibility, which compares them, and are translated only when the dropdown shows them. * test(i18n): pin the other two commit blockers under the pseudo-locale The pseudo-locale test only reached the stage-file blocker, so an English return for the conflict or commit-message blocker still passed. The new case checks both in the Commit, Commit & Push and Commit & Sync titles. * i18n: translate source control dropdown keys; trim duplicate pseudo-locale test Add zh/ko/ja/es/fr/pt translations for the 42 dropdown keys this PR adds to en.json, matching each catalog's existing source-control glossary. Drop the second pseudo-locale test; the first already covers commit-blocker titles through the active locale. --------- Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
159 lines
5.5 KiB
TypeScript
159 lines
5.5 KiB
TypeScript
// Share commit blockers across Commit, Commit & Push, and Commit & Sync so disabled reasons agree.
|
|
|
|
import type { CommitDisabledReason } from './source-control-commit-eligibility'
|
|
import type { DropdownItem } from './source-control-dropdown-item-types'
|
|
import type { DropdownActionContext } from './source-control-dropdown-action-context'
|
|
|
|
// Desktop localizes these strings; other clients pass their own copy.
|
|
export type CommitDropdownCopy = {
|
|
commit: string
|
|
commitStagedChanges: string
|
|
commitPush: string
|
|
commitForcePush: string
|
|
commitSync: string
|
|
checkingBranchStatus: string
|
|
checkingPrStatus: string
|
|
prAlreadyMerged: string
|
|
checkOutBranchToPush: string
|
|
linkedReviewTargetUnavailable: string
|
|
publishBranchFirstToPush: string
|
|
commitAndForcePush: string
|
|
commitAndTryPush: string
|
|
commitAndPush: string
|
|
checkOutBranchToSync: string
|
|
publishBranchFirstToSync: string
|
|
useCommitAndForcePush: string
|
|
commitThenPullPush: string
|
|
// Eligibility compares the English reasons, so copy translates them only for display.
|
|
commitDisabledReason: (reason: CommitDisabledReason) => string
|
|
}
|
|
|
|
export const ENGLISH_COMMIT_DROPDOWN_COPY: CommitDropdownCopy = {
|
|
commit: 'Commit',
|
|
commitStagedChanges: 'Commit staged changes',
|
|
commitPush: 'Commit & Push',
|
|
commitForcePush: 'Commit & Force Push',
|
|
commitSync: 'Commit & Sync',
|
|
checkingBranchStatus: 'Checking branch status…',
|
|
checkingPrStatus: 'Checking PR status…',
|
|
prAlreadyMerged: 'PR is already merged',
|
|
checkOutBranchToPush: 'Check out a branch before pushing commits',
|
|
linkedReviewTargetUnavailable: 'Linked review branch target is unavailable',
|
|
publishBranchFirstToPush: 'Publish the branch first to push commits',
|
|
commitAndForcePush: 'Commit staged changes and force push with lease',
|
|
commitAndTryPush: 'Commit staged changes and try to push',
|
|
commitAndPush: 'Commit staged changes and push',
|
|
checkOutBranchToSync: 'Check out a branch before syncing commits',
|
|
publishBranchFirstToSync: 'Publish the branch first to sync commits',
|
|
useCommitAndForcePush: 'Use Commit & Force Push — remote only has older copies of local commits',
|
|
commitThenPullPush: 'Commit, then pull and push',
|
|
commitDisabledReason: (reason) => reason
|
|
}
|
|
|
|
export type CommitDropdownItems = {
|
|
commit: DropdownItem
|
|
commitPush: DropdownItem
|
|
commitSync: DropdownItem
|
|
}
|
|
|
|
export function buildCommitDropdownItems(
|
|
ctx: DropdownActionContext,
|
|
copy: CommitDropdownCopy = ENGLISH_COMMIT_DROPDOWN_COPY
|
|
): CommitDropdownItems {
|
|
const {
|
|
globalBusy,
|
|
upstreamLoading,
|
|
hasUpstream,
|
|
hasOpenHostedReview,
|
|
canPushLinkedReviewWithoutUpstream,
|
|
pushBlockedByOpenHostedReviewTarget,
|
|
publishBlockedByMergedPR,
|
|
publishBlockedByPRLoading,
|
|
publishBlockedByDetachedHead,
|
|
behind,
|
|
shouldForcePushWithLease,
|
|
commitDisabledReason,
|
|
canCommit
|
|
} = ctx
|
|
const commitDisabledTitle =
|
|
commitDisabledReason === null ? null : copy.commitDisabledReason(commitDisabledReason)
|
|
|
|
const commit: DropdownItem = {
|
|
kind: 'commit',
|
|
label: copy.commit,
|
|
title: commitDisabledTitle ?? copy.commitStagedChanges,
|
|
disabled: !canCommit
|
|
}
|
|
|
|
// Committing changes divergence, so compound labels must omit pre-commit counts.
|
|
const commitPushTitle = upstreamLoading
|
|
? copy.checkingBranchStatus
|
|
: publishBlockedByPRLoading
|
|
? copy.checkingPrStatus
|
|
: publishBlockedByMergedPR
|
|
? copy.prAlreadyMerged
|
|
: publishBlockedByDetachedHead
|
|
? copy.checkOutBranchToPush
|
|
: pushBlockedByOpenHostedReviewTarget
|
|
? copy.linkedReviewTargetUnavailable
|
|
: !hasUpstream && !(hasOpenHostedReview && canPushLinkedReviewWithoutUpstream)
|
|
? copy.publishBranchFirstToPush
|
|
: (commitDisabledTitle ??
|
|
(shouldForcePushWithLease
|
|
? copy.commitAndForcePush
|
|
: behind > 0
|
|
? copy.commitAndTryPush
|
|
: copy.commitAndPush))
|
|
const commitPush: DropdownItem = {
|
|
kind: 'commit_push',
|
|
label: shouldForcePushWithLease ? copy.commitForcePush : copy.commitPush,
|
|
title: commitPushTitle,
|
|
// Match Push: without upstream, Commit & Push requires a known open-review head.
|
|
disabled:
|
|
globalBusy ||
|
|
upstreamLoading ||
|
|
(!hasUpstream && !(hasOpenHostedReview && canPushLinkedReviewWithoutUpstream)) ||
|
|
publishBlockedByDetachedHead ||
|
|
publishBlockedByPRLoading ||
|
|
publishBlockedByMergedPR ||
|
|
commitDisabledReason !== null
|
|
}
|
|
|
|
const commitSyncTitle = ((): string => {
|
|
if (upstreamLoading) {
|
|
return copy.checkingBranchStatus
|
|
}
|
|
if (publishBlockedByPRLoading) {
|
|
return copy.checkingPrStatus
|
|
}
|
|
if (publishBlockedByMergedPR) {
|
|
return copy.prAlreadyMerged
|
|
}
|
|
if (publishBlockedByDetachedHead) {
|
|
return copy.checkOutBranchToSync
|
|
}
|
|
if (!hasUpstream) {
|
|
// Point to the existing Publish Branch primary instead of naming a nonexistent compound action.
|
|
return copy.publishBranchFirstToSync
|
|
}
|
|
if (shouldForcePushWithLease) {
|
|
return commitDisabledTitle ?? copy.useCommitAndForcePush
|
|
}
|
|
return commitDisabledTitle ?? copy.commitThenPullPush
|
|
})()
|
|
const commitSync: DropdownItem = {
|
|
kind: 'commit_sync',
|
|
label: copy.commitSync,
|
|
title: commitSyncTitle,
|
|
disabled:
|
|
globalBusy ||
|
|
upstreamLoading ||
|
|
!hasUpstream ||
|
|
publishBlockedByDetachedHead ||
|
|
shouldForcePushWithLease ||
|
|
commitDisabledReason !== null
|
|
}
|
|
|
|
return { commit, commitPush, commitSync }
|
|
}
|