diff --git a/cli/lib/listing-translate.ts b/cli/lib/listing-translate.ts index 795d778c..b6dc55c8 100644 --- a/cli/lib/listing-translate.ts +++ b/cli/lib/listing-translate.ts @@ -129,7 +129,9 @@ export function normalizeKeywords(text: string, o: { name?: string; subtitle?: s return { text: kept.join(','), dropped }; } -export interface FieldCheck { store: 'apple' | 'play'; field: string; chars: number; limit: number; problems: string[] } +/** `chars` is what the store counts: characters, except App Store keywords, which App Store Connect limits in UTF-8 bytes + * (`unit` says which). */ +export interface FieldCheck { store: 'apple' | 'play'; field: string; chars: number; unit: 'chars' | 'bytes'; limit: number; problems: string[] } /** Limits and rules of one translated section. `source` = the source language's fields (identical text is flagged). */ export function checkFields(store: 'apple' | 'play', f: Record, source: Record = {}, status?: TStatus): FieldCheck[] { @@ -139,10 +141,11 @@ export function checkFields(store: 'apple' | 'play', f: Record)[k]!; - const c: FieldCheck = { store, field: k, chars: len(v), limit, problems: [] }; - if (len(v) > limit) c.problems.push(`${len(v)} > ${limit} characters`); - if (store === 'apple' && k === 'keywords') { - if (Buffer.byteLength(v) > limit) c.problems.push(`${Buffer.byteLength(v)} bytes > ${limit}`); + const bytes = store === 'apple' && k === 'keywords'; + const n = bytes ? Buffer.byteLength(v, 'utf8') : len(v); + const c: FieldCheck = { store, field: k, chars: n, unit: bytes ? 'bytes' : 'chars', limit, problems: [] }; + if (n > limit) c.problems.push(`${n} > ${limit} ${bytes ? 'bytes' : 'characters'}`); + if (bytes) { if (/,\s|\s,/.test(v)) c.problems.push('spaces around commas'); const words = v.split(',').map(w => w.trim().toLocaleLowerCase()).filter(Boolean); const dup = words.filter((w, i) => words.indexOf(w) !== i); diff --git a/cli/listing.ts b/cli/listing.ts index b1d59a18..731ef17d 100644 --- a/cli/listing.ts +++ b/cli/listing.ts @@ -127,7 +127,7 @@ async function translate(ctx: Ctx): Promise { if (a.has('json')) printJson({ source: src.id, dryRun: dry, hook: !!hook, files: { apple: files.apple?.path ?? null, play: files.play?.path ?? null }, results: rows.map(r => ({ ...r, problems: problemsOf(r) })) }); else { console.log(textTable(['language', 'store', 'section', 'fields', 'problems'], rows.map(r => [r.lang, r.store === 'apple' ? 'App Store' : 'Google Play', r.action, - r.checks.map(c => `${c.field} ${c.chars}/${c.limit}`).join(', '), problemsOf(r).join('; ')]))); + r.checks.map(c => `${c.field} ${c.chars}/${c.limit}${c.unit === 'bytes' ? ' B' : ''}`).join(', '), problemsOf(r).join('; ')]))); } const json = a.has('json'); if (dry) { if (!json) done(TAG, 'dry run: listing files not written'); return; } @@ -167,7 +167,7 @@ function check(ctx: Ctx): void { if (ctx.args.has('json')) printJson({ sections: r, ok: !bad.length, drafts: drafts.map(d => `${d.store}:${d.lang}`) }); else { console.log(textTable(['store', 'language', 'status', 'fields', 'problems'], r.map(x => [x.store === 'apple' ? 'App Store' : 'Google Play', x.lang, - x.status === 'draft' ? 'DRAFT (review)' : x.status === 'translate' ? 'TO TRANSLATE' : 'reviewed', x.checks.map(c => `${c.field} ${c.chars}/${c.limit}`).join(', '), + x.status === 'draft' ? 'DRAFT (review)' : x.status === 'translate' ? 'TO TRANSLATE' : 'reviewed', x.checks.map(c => `${c.field} ${c.chars}/${c.limit}${c.unit === 'bytes' ? ' B' : ''}`).join(', '), x.checks.flatMap(c => c.problems.map(p => `${c.field}: ${p}`)).join('; ')]))); if (drafts.length) warn(TAG, `${drafts.length} machine-translated draft(s) not reviewed yet: ${drafts.map(d => `${d.store}:${d.lang}`).join(', ')} (storebound listing reviewed --lang after reading them)`); done(TAG, bad.length ? `${bad.length} section(s) with problems` : `${r.length} section(s) within the store limits`); diff --git a/tests/listing-translate.test.ts b/tests/listing-translate.test.ts index 312686df..31350502 100644 --- a/tests/listing-translate.test.ts +++ b/tests/listing-translate.test.ts @@ -97,3 +97,12 @@ describe('listing commands', () => { expect(sb(dir, 'listing', 'translate', '--to', 'xx').stderr.toString()).toContain('not a language of the config'); }); }); + +test('listing check counts App Store keywords in UTF-8 bytes, the other fields in characters', () => { + const ru = 'игра,бег,прыжки,монеты,уровни,рекорд,аркада,быстро'; // 50 characters, 93 bytes + const kw = checkFields('apple', { keywords: ru, subtitle: 'Быстрая аркада' }).find(c => c.field === 'keywords')!; + expect(kw).toMatchObject({ chars: 93, unit: 'bytes', problems: [] }); + expect(checkFields('apple', { keywords: ru + ',звук' }).find(c => c.field === 'keywords')!.problems).toContain('102 > 100 bytes'); + expect(checkFields('apple', { subtitle: 'Быстрая аркада' })[0]).toMatchObject({ chars: 14, unit: 'chars' }); +}); +