diff --git a/__tests__/incorrectTranslationPlaceholders.js b/__tests__/incorrectTranslationPlaceholders.js new file mode 100644 index 00000000..51926467 --- /dev/null +++ b/__tests__/incorrectTranslationPlaceholders.js @@ -0,0 +1,24 @@ +const fs = require('fs'); +const path = require('path'); +const messagesFolder = path.resolve(__dirname, '../src/i18n_messages'); + +for (const file of fs.readdirSync(messagesFolder)) { + const filePath = path.join(messagesFolder, file); + const content = fs.readFileSync(filePath, 'utf8'); + const lines = content.split('\n'); + + for (let i = 0; i < lines.length; i++) { + const line = lines[i]; + if (line.includes('${')) { + const index = line.indexOf('${'); + const neighborValue = 10 + const neighbor = line + .trim() + .slice( + Math.max(0, index - neighborValue), + Math.min(line.length, index + neighborValue), + ) + console.log(`${filePath}(${i+1},${index+1}): Likely incorrect placeholder selector \$\{\}: ...${neighbor}...`); + } + } +} \ No newline at end of file diff --git a/package.json b/package.json index 9a8fae62..416b8637 100644 --- a/package.json +++ b/package.json @@ -12,10 +12,10 @@ "lint": "eslint .", "start": "npx react-native start", "test": "jest", + "test:i18n": "node __tests__/missingTranslations.js && node __tests__/incorrectTranslationPlaceholders.js", "adb": "adb devices && adb reverse tcp:9090 tcp:9090 && adb reverse tcp:3000 tcp:3000 && adb reverse tcp:9001 tcp:9001 && adb reverse tcp:8081 tcp:8081", "adb:unreverse": "adb devices && adb reverse --remove-all", "adb:inspect": "adb shell input keyevent 82", - "i18n:missing": "node __tests__/missingTranslations.js", "postinstall": "patch-package --exclude 'nothing'" }, "dependencies": {