listing check: App Store keywords shown and limited in UTF-8 bytes (96/100 B), other fields in characters
This commit is contained in:
parent
d5bc7b8889
commit
124e3097ec
3 changed files with 19 additions and 7 deletions
|
|
@ -129,7 +129,9 @@ export function normalizeKeywords(text: string, o: { name?: string; subtitle?: s
|
||||||
return { text: kept.join(','), dropped };
|
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). */
|
/** 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<string, string | undefined>, source: Record<string, string | undefined> = {}, status?: TStatus): FieldCheck[] {
|
export function checkFields(store: 'apple' | 'play', f: Record<string, string | undefined>, source: Record<string, string | undefined> = {}, status?: TStatus): FieldCheck[] {
|
||||||
|
|
@ -139,10 +141,11 @@ export function checkFields(store: 'apple' | 'play', f: Record<string, string |
|
||||||
const v = f[k];
|
const v = f[k];
|
||||||
if (v === undefined) continue;
|
if (v === undefined) continue;
|
||||||
const limit = (FIELD_LIMITS[store] as Record<string, number>)[k]!;
|
const limit = (FIELD_LIMITS[store] as Record<string, number>)[k]!;
|
||||||
const c: FieldCheck = { store, field: k, chars: len(v), limit, problems: [] };
|
const bytes = store === 'apple' && k === 'keywords';
|
||||||
if (len(v) > limit) c.problems.push(`${len(v)} > ${limit} characters`);
|
const n = bytes ? Buffer.byteLength(v, 'utf8') : len(v);
|
||||||
if (store === 'apple' && k === 'keywords') {
|
const c: FieldCheck = { store, field: k, chars: n, unit: bytes ? 'bytes' : 'chars', limit, problems: [] };
|
||||||
if (Buffer.byteLength(v) > limit) c.problems.push(`${Buffer.byteLength(v)} bytes > ${limit}`);
|
if (n > limit) c.problems.push(`${n} > ${limit} ${bytes ? 'bytes' : 'characters'}`);
|
||||||
|
if (bytes) {
|
||||||
if (/,\s|\s,/.test(v)) c.problems.push('spaces around commas');
|
if (/,\s|\s,/.test(v)) c.problems.push('spaces around commas');
|
||||||
const words = v.split(',').map(w => w.trim().toLocaleLowerCase()).filter(Boolean);
|
const words = v.split(',').map(w => w.trim().toLocaleLowerCase()).filter(Boolean);
|
||||||
const dup = words.filter((w, i) => words.indexOf(w) !== i);
|
const dup = words.filter((w, i) => words.indexOf(w) !== i);
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ async function translate(ctx: Ctx): Promise<void> {
|
||||||
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) })) });
|
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 {
|
else {
|
||||||
console.log(textTable(['language', 'store', 'section', 'fields', 'problems'], rows.map(r => [r.lang, r.store === 'apple' ? 'App Store' : 'Google Play', r.action,
|
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');
|
const json = a.has('json');
|
||||||
if (dry) { if (!json) done(TAG, 'dry run: listing files not written'); return; }
|
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}`) });
|
if (ctx.args.has('json')) printJson({ sections: r, ok: !bad.length, drafts: drafts.map(d => `${d.store}:${d.lang}`) });
|
||||||
else {
|
else {
|
||||||
console.log(textTable(['store', 'language', 'status', 'fields', 'problems'], r.map(x => [x.store === 'apple' ? 'App Store' : 'Google Play', x.lang,
|
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('; ')])));
|
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 <ids> after reading them)`);
|
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 <ids> after reading them)`);
|
||||||
done(TAG, bad.length ? `${bad.length} section(s) with problems` : `${r.length} section(s) within the store limits`);
|
done(TAG, bad.length ? `${bad.length} section(s) with problems` : `${r.length} section(s) within the store limits`);
|
||||||
|
|
|
||||||
|
|
@ -97,3 +97,12 @@ describe('listing commands', () => {
|
||||||
expect(sb(dir, 'listing', 'translate', '--to', 'xx').stderr.toString()).toContain('not a language of the config');
|
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' });
|
||||||
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue