Skip to content

Commit 667ce76

Browse files
fix(issue-sync): view on crowdin url (#11)
1 parent ce2d5e9 commit 667ce76

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

src/sync-crowdin-issues.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,14 @@ function buildIssueBody(crowdinIssue, projectId, projectSlug) {
392392

393393
// Build the deep-link URL. If we have the slug, link straight to the string
394394
// in the Crowdin editor for that language; otherwise fall back to the project page.
395-
// The numeric project ID is never used in URLs as it does not resolve on crowdin.com.
395+
// URL format: /editor/{slug}/{fileId}/en-{normalizedLang}?view=comfortable#{stringId}
396+
// The language segment strips hyphens and lowercases (e.g. "zh-CN" → "en-zhcn").
396397
const stringId = crowdinIssue.string?.id;
398+
const fileId = crowdinIssue.string?.file?.id;
397399
let crowdinUrl;
398-
if (projectSlug && crowdinIssue.languageId && stringId) {
399-
crowdinUrl = `https://crowdin.com/editor/${projectSlug}/${crowdinIssue.languageId}#${stringId}`;
400+
if (projectSlug && crowdinIssue.languageId && fileId && stringId) {
401+
const normalizedLang = crowdinIssue.languageId.replaceAll(/[-_]/g, '').toLowerCase();
402+
crowdinUrl = `https://crowdin.com/editor/${projectSlug}/${fileId}/en-${normalizedLang}?view=comfortable#${stringId}`;
400403
} else if (projectSlug) {
401404
crowdinUrl = `https://crowdin.com/project/${projectSlug}`;
402405
} else {

tests/sync-crowdin-issues.test.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,10 +557,23 @@ describe('buildIssueBody', () => {
557557
expect(body).toContain('https://crowdin.com/project/my-project');
558558
});
559559

560-
it('links directly to the string in the editor when slug and string.id are present', () => {
560+
it('links directly to the string in the editor when slug, file.id and string.id are present', () => {
561+
const issue = { ...baseIssue, languageId: 'fr', string: { text: 'Source', id: 999, file: { id: 5842 } } };
562+
const body = buildIssueBody(issue, projectId, 'my-project');
563+
expect(body).toContain('https://crowdin.com/editor/my-project/5842/en-fr?view=comfortable#999');
564+
});
565+
566+
it('links directly to the editor with a compound language code normalized (zh-CN → en-zhcn)', () => {
567+
const issue = { ...baseIssue, languageId: 'zh-CN', string: { text: 'Source', id: 91860, file: { id: 5842 } } };
568+
const body = buildIssueBody(issue, projectId, 'my-project');
569+
expect(body).toContain('https://crowdin.com/editor/my-project/5842/en-zhcn?view=comfortable#91860');
570+
});
571+
572+
it('falls back to project page when file.id is absent', () => {
561573
const issue = { ...baseIssue, languageId: 'fr', string: { text: 'Source', id: 999 } };
562574
const body = buildIssueBody(issue, projectId, 'my-project');
563-
expect(body).toContain('https://crowdin.com/editor/my-project/fr#999');
575+
expect(body).toContain('https://crowdin.com/project/my-project');
576+
expect(body).not.toContain('/editor/');
564577
});
565578

566579
it('includes the File row when string.file.path is present', () => {

0 commit comments

Comments
 (0)