Check a string is a valid jsLingui string or not (compare with jsLingui minimal format key).
- lodash
- Sorry for that, it will be removed in next version
- Install
yarn add lodash lingui-string-validation
- Usage
/**
* -1: bad key
* 0: bad text
* 1: valid text
* 2: empty text
*/
import checkI18nString from 'lingui-string-validation'
// const lingui-string-validation = require('lingui-string-validation').default
const linguiKey = '<0>This is a text with <1>{variable}</1><2>visit counts: {0}</2></0>'
const badKey = 'This is a bad {key'
checkI18nString(badKey, '<0>This is a text with <1>{variable}</1><2>visit counts: {0}</2></0>') // -1
checkI18nString(linguiKey, '<0>This is a text with <1>{variable}</1><2>visit counts: {0}</2></0>') // 1
checkI18nString(linguiKey, '<0><2>觀看次數:{0}</2>, 這是一段有<1>變數</1>的文字</0>') // 1
checkI18nString(linguiKey, '<0>This is a text with <1>{variable}<1><2>visit counts: {0}</2></0>') // 0
checkI18nString(linguiKey, '<0>This is a text with <3>{variable}</3><2>visit counts: {0}</2></0>') // 0
checkI18nString(linguiKey, '<0>This is a text with <1>{different}</1><2>visit counts: {0}</2></0>') // 0
checkI18nString(linguiKey, '<0>This is a text with <1>{variable}</1><2>visit counts: 0}</2></0>') // 0
checkI18nString(linguiKey, '') // 2