Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix react-i18next(and next-i18next) framework integration #735

Merged
merged 2 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR does not seem to have been checked at all. Surely ReactI18nextFramework should be extending I18nextFramework and not Framework. I18nextFramework is also a default export and not a named one...

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
4 changes: 1 addition & 3 deletions src/frameworks/react.ts → src/frameworks/react-intl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ class ReactFramework extends Framework {

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

Expand Down