scratchblocks icon indicating copy to clipboard operation
scratchblocks copied to clipboard

Fix incorrect translation keys [WIP]

Open tjvr opened this issue 1 year ago • 0 comments
trafficstars

This change will fix #505: for the (size) block, we're incorrectly using the SENSING_OF_SIZE translation key, rather than the correct LOOKS_SIZE. This meant that we chose the wrong translation in some cases (e.g. isiZulu).

I've also corrected a few other incorrect translation keys. I did this by reviewing the differences in selectors between scratchblocks, and the Scratch 2 -> Scratch 3 mapping used inside scratch-vm, with the help of the following script:

import commands from './syntax/commands.js'
import specMap from './sb2_specmap.cjs'

for (const cmd of commands) {
  const { category, selector, id: actualId, spec } = cmd
  if (selector == null) {
    continue // Some blocks are only in Scratch 3.0, and have no Scratch 2.0 selector.
  }
  if (category === 'obsolete') {
    continue // Ignore Scratch 1.4 blocks.
  }

  const map = specMap[selector]
  let expectedId = (map?.opcode ?? '').toUpperCase()

  // The operator translation keys are spelt different from the block IDs.
  expectedId = expectedId.replace(/^OPERATOR_/, 'OPERATORS_')
  // So are the Control blocks.
  if (/CONTROL_/.test(expectedId)) {
    expectedId = 'CONTROL_' + expectedId.slice('CONTROL_'.length).replace(/_/g, '')
  }
  if (/OPERATORS_/.test(expectedId)) {
    expectedId = 'OPERATORS_' + expectedId.slice('OPERATORS_'.length).replace(/_/g, '')
  }
  if (expectedId === 'MUSIC_SETTEMPO') expectedId = 'music.setTempo'

  if (expectedId === actualId) {
    continue // Already correct!
  }
  if (/\./.test(actualId)) {
    continue // Skip extension blocks for now.
  }
  console.log('category:   ', category)
  console.log('spec:       ', spec)
  console.log('s2 selector:', selector)
  console.log('s3 selector:')
  console.log('   expected ', expectedId)
  console.log('   actual   ', actualId)
  console.log('    comment:', map)
  console.log('')
}

tjvr avatar Apr 14 '24 16:04 tjvr