Skip to content

purepennons/lingui-string-validation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lingui-string-validation

npm version Coverage Status license mit circle ci

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

About

test a lingui translated text is valid or not

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published