1.1.0 • Published 6 years ago

lingui-string-validation v1.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

lingui-string-validation

Check a string is a valid jsLingui string or not (compare with jsLingui minimal format key).

Dependencies

  • lodash
    • Sorry for that, it will be removed in next version

Usage

  • 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
1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago