Skip to content

Commit

Permalink
fix: correctly extend react-i18next from i18next framework
Browse files Browse the repository at this point in the history
  • Loading branch information
SimeonC committed Mar 1, 2022
1 parent c9e4537 commit 2a493e6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/frameworks/i18next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ class I18nextFramework extends Framework {
'{key}_7',
'{key}_8',
'{key}_9',
// support v4 format as well as v3
'{key}_zero',
'{key}_one',
'{key}_two',
'{key}_few',
'{key}_many',
'{key}_other'
]

refactorTemplates(keypath: string) {
Expand Down
39 changes: 39 additions & 0 deletions src/frameworks/react-i18next.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { I18nextFramework } from './i18next'
import { LanguageId } from '~/utils'

class ReactI18nextFramework extends Framework {
id= 'react-i18next'
display= 'React'

detection= {
packageJSON: [
'react-i18next',
'next-i18next',
],
}

languageIds: LanguageId[] = [
'javascript',
'typescript',
'javascriptreact',
'typescriptreact',
'ejs',
]

// for visualize the regex, you can use https://regexper.com/
usageMatchRegex = [
// general jsx attrs
'[^\\w\\d](?:i18nKey=|FormattedMessage[ (]\\s*id=|t\\(\\s*)[\'"`]({key})[\'"`]',
'<Trans>({key})<\\/Trans>',
]

refactorTemplates(keypath: string) {
return [
`{t('${keypath}')}`,
`t('${keypath}')`,
keypath,
]
}
}

export default ReactI18nextFramework
File renamed without changes.

0 comments on commit 2a493e6

Please sign in to comment.