gilbsgilbs / babel-plugin-i18next-extract Goto Github PK
View Code? Open in Web Editor NEWBabel plugin that statically extracts i18next and react-i18next translation keys.
Home Page: https://i18next-extract.netlify.com
License: MIT License
Babel plugin that statically extracts i18next and react-i18next translation keys.
Home Page: https://i18next-extract.netlify.com
License: MIT License
🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨
To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.
Since we didn’t receive a CI status on the greenkeeper/initial
branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.
If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/
.
Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.
12.7.7
to 12.7.8
.This version is covered by your current version range and after updating it in your project the build failed.
@types/node is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
12.7.6
to 12.7.7
.This version is covered by your current version range and after updating it in your project the build failed.
@types/node is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
6.6.0
to 6.7.0
.This version is covered by your current version range and after updating it in your project the build failed.
eslint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
312a88f
New: Add grouped-accessor-pairs rule (fixes #12277) (#12331) (Milos Djermanovic)5c68f5f
Update: Add 'lexicalBindings' to no-implicit-globals and change messages (#11996) (Milos Djermanovic)6eaad96
New: Add suggestions API (#12384) (Will Douglas)b336fbe
Fix: indent rule with JSX spread props (#12581) (Nathan Woltman)97c745d
Update: Report assignment expression location in no-cond-assign (#12465) (Milos Djermanovic)0f01f3d
Update: Check member expressions with this
in operator-assignment (#12495) (Milos Djermanovic)62c7038
Fix: invalid token checking in computed-property-spacing (fixes #12198) (#12533) (YeonJuan)4f8a1ee
Update: Add enforceForClassMembers option to no-useless-computed-key (#12110) (ark120202)1a2eb99
New: new rule no-constructor-return (fixes #12481) (#12529) (Pig Fang)ca3b2a6
New: ignorePatterns in config files (refs eslint/rfcs#22) (#12274) (Toru Nagashima)60204a3
Docs: Added another Textmate 2 bundle. (#12580) (Ryan Fitzer)62623f9
Fix: preserve whitespace in multiline-comment-style (fixes #12312) (#12316) (Kai Cataldo)17a8849
New: Add no-dupe-else-if rule (fixes #12469) (#12504) (Milos Djermanovic)41a78fd
Update: improve location for semi and comma-dangle (#12380) (Chiawen Chen)0a480f8
Docs: Change "Code Conventions" link in pull-requests.md (#12401) (Denis Sikuler)fed20bb
Fix: require-await crash on global await (#12571) (Brad Zacher)b8030fc
Update: deprecate personal config (fixes #11914, refs eslint/rfcs#32) (#12426) (Toru Nagashima)40c8c32
Fix: improve report location for object-curly-spacing (#12563) (Milos Djermanovic)1110045
Fix: ignore marker-only comments in spaced-comment (fixes #12036) (#12558) (Milos Djermanovic)6503cb8
Update: Fix uglified object align in key-spacing (fixes #11414) (#12472) (YeonJuan)40791af
Docs: clarify ignoreDestructuring option in the camelcase rule (#12553) (Milos Djermanovic)07d398d
Chore: Add GitHub organization to Sponsor button (#12562) (Brandon Mills)a477707
Chore: Format style guide links so they can be clicked (#12189) (Ivan V)0f7edef
Update: add react plugin config for eslint init (#12446) (Ibrahim Rouis)448ff1e
Update: Report '\08' and '\09' in no-octal-escape (fixes #12080) (#12526) (Milos Djermanovic)45aa6a3
New: Add no-setter-return rule (fixes #12285) (#12346) (Milos Djermanovic)0afb518
Fix: invalid autofix in function-call-argument-newline (fixes #12454) (#12539) (YeonJuan)90305e0
Update: Depcrecate isSpaceBetweenTokens() (#12519) (Kai Cataldo)41b1e43
New: add option for camelcase (fixes #12527) (#12528) (Pig Fang)f49f1e0
Upgrade: upgrade optionator to avoid license issue (fixes #11536) (#12537) (Pig Fang)0286b57
Docs: Clean up Getting Started Guide (#12544) (Nicholas C. Zakas)575a98d
Chore: Add funding field to package.json (#12543) (Nicholas C. Zakas)9e29e18
Fix: sourceCode#isSpaceBetweenTokens() checks non-adjacent tokens (#12491) (Kai Cataldo)5868550
Docs: add notice about function
keyword in keyword-spacing (#12524) (Pig Fang)bb556d5
Fix: curly multi
reports single lexical declarations (fixes #11908) (#12513) (Milos Djermanovic)ac60621
Fix: unexpected autofix in prefer-const (fixes #12514) (#12521) (YeonJuan)990065e
Update: curly multi-or-nest flagging semis on next line (fixes #12370) (#12378) (cherryblossom000)084a8a6
Fix: no-cond-assign with always
option reports switch case clauses (#12470) (Milos Djermanovic)7e41355
Update: improve report location for space-infix-ops (#12324) (Chiawen Chen)94ff921
Update: Add capIsConstructor option to no-invalid-this (fixes #12271) (#12308) (Milos Djermanovic)de65de6
New: Add prefer-exponentiation-operator rule (fixes #10482) (#12360) (Milos Djermanovic)c78f4a7
Update: Allow JSX exception in no-inline-comments (fixes #11270) (#12388) (Milos Djermanovic)e17fb90
New: allowAfterThisConstructor for no-underscore-dangle (fixes #11488) (#11489) (sripberger)287ca56
Build: update CI for Node.js 13 (#12496) (Toru Nagashima)98e1d50
Upgrade: globals to v12.1.0 (#12296) (Tony Brix)8ac71a3
Sponsors: Sync README with website (ESLint Jenkins)4e142ea
Docs: Update README team and sponsors (ESLint Jenkins)The new version differs by 49 commits.
61848b4
6.7.0
9162db9
Build: changelog update for 6.7.0
312a88f
New: Add grouped-accessor-pairs rule (fixes #12277) (#12331)
5c68f5f
Update: Add 'lexicalBindings' to no-implicit-globals and change messages (#11996)
6eaad96
New: Add suggestions API (#12384)
b336fbe
Fix: indent rule with JSX spread props (#12581)
97c745d
Update: Report assignment expression location in no-cond-assign (#12465)
0f01f3d
Update: Check member expressions with this
in operator-assignment (#12495)
62c7038
Fix: invalid token checking in computed-property-spacing (fixes #12198) (#12533)
4f8a1ee
Update: Add enforceForClassMembers option to no-useless-computed-key (#12110)
1a2eb99
New: new rule no-constructor-return (fixes #12481) (#12529)
ca3b2a6
New: ignorePatterns in config files (refs eslint/rfcs#22) (#12274)
60204a3
Docs: Added another Textmate 2 bundle. (#12580)
62623f9
Fix: preserve whitespace in multiline-comment-style (fixes #12312) (#12316)
17a8849
New: Add no-dupe-else-if rule (fixes #12469) (#12504)
There are 49 commits in total.
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
I can submit a PR for this, just want to know if anybody would want this. I'd like to be able to wrap the Trans component in, for example, material-ui's Typography component like so:
function Text({i18nKey, children, ...typographyProps}) {
return (
<Typography {...typographyProps}>
<Trans i18nKey={i18nKey}>{children}</Trans>
</Typography>
);
}
and then have all usages of Text parsed as though it were <Trans />
.
dependency
@babel/core was updated from 7.5.5
to 7.6.0
.devDependency
@babel/preset-env was updated from 7.5.5
to 7.6.0
.devDependency
@babel/preset-typescript was updated from 7.3.3
to 7.6.0
.devDependency
@babel/types was updated from 7.6.0
to 7.6.1
.This version is covered by your current version range and after updating it in your project the build failed.
This monorepo update includes releases of one or more dependencies which all belong to the babel7 group definition.
babel7 is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
If the default value of a translation is passed as the second argument to the t
function an error occurs. Example:
t('login.header', 'Sign in')
/data/Projects/project-frontend/src/pages/login/Login.tsx: Cannot use 'in' operator to search for 'context' in Sign in
at parseTCallOptions (/data/Projects/project-frontend/node_modules/babel-plugin-i18next-extract/lib/index.js:539:34)
at extractTCall (/data/Projects/project-frontend/node_modules/babel-plugin-i18next-extract/lib/index.js:573:16)
at Object.extractTFunction (/data/Projects/project-frontend/node_modules/babel-plugin-i18next-extract/lib/index.js:595:13)
at CallExpression.collect (/data/Projects/project-frontend/node_modules/babel-plugin-i18next-extract/lib/index.js:1372:32)
at handleExtraction (/data/Projects/project-frontend/node_modules/babel-plugin-i18next-extract/lib/index.js:1355:16)
at PluginPass.CallExpression (/data/Projects/project-frontend/node_modules/babel-plugin-i18next-extract/lib/index.js:1369:9)
at NodePath._call (/data/Projects/project-frontend/node_modules/@babel/traverse/lib/path/context.js:53:20)
at NodePath.call (/data/Projects/project-frontend/node_modules/@babel/traverse/lib/path/context.js:40:17)
at NodePath.visit (/data/Projects/project-frontend/node_modules/@babel/traverse/lib/path/context.js:88:12)
at TraversalContext.visitQueue (/data/Projects/project-frontend/node_modules/@babel/traverse/lib/context.js:118:16)
This is supported behaviour according to the i18next documentation and it would be nice if babel-plugin-18next-extract
also supports this.
When I change code
<Trans>Profile</Trans>
to
<Trans>Profil</Trans>
I will receive two keys in translation.json
{
"Profile": "",
"Profil": ""
}
I want to have only fresh list of keys in translation file.
Can you please tell is there any way to update config to handle that?
2.7.0
to 2.8.0
.This version is covered by your current version range and after updating it in your project the build failed.
@typescript-eslint/parser is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 20 commits.
a9117f5
chore: publish v2.8.0
46b58b4
feat(eslint-plugin): add rule restrict-template-expressions (#850)
42a48de
fix(eslint-plugin): [no-unnec-type-arg] throwing on call/new expr (#1217)
ba89168
fix(typescript-estree): correctly account for trailing slash in… (#1205)
eb83af1
fix(eslint-plugin): [require-await] better handle nesting (#1193)
9829dd3
fix(eslint-plugin): [nuta] correctly handle null/undefined separation (#1201)
d1de3a7
fix(eslint-plugin): [unified-signatures] crash: cannot read pro… (#1096)
9aee06c
fix(eslint-plugin): [indent] handle empty generic declarations (#1211)
74192f8
chore: bump dependencies (#1208)
e2008e3
fix(eslint-plugin): [indent] fix decorator type (#1189)
4fac6c5
fix(eslint-plugin): [no-unnecessary-cond] fix naked type param (#1207)
259ff20
feat(eslint-plugin): [no-type-alias] handle conditional types (#953)
9c8203f
fix(eslint-plugin): [camelcase] handle optional member expr (#1204)
d8b07a7
feat(eslint-plugin): add space-before-function-paren [extension] (#924)
ca41dcf
docs(eslint-plugin): brace-style as a replacement for one-line (#1202)
There are 20 commits in total.
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
6.2.1
to 6.2.2
.This version is covered by your current version range and after updating it in your project the build failed.
eslint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 6 commits.
ca658fb
6.2.2
3ed9f76
Build: changelog update for 6.2.2
0e0b784
Upgrade: espree@^6.1.1 (#12158)
04e859f
Sponsors: Sync README with website
34783d1
Sponsors: Sync README with website
b809e72
Docs: Update README team and sponsors
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
Large multi-module applications often exist in a monorepo format where there is one canonical babel.config.js
. Calls into i18next exist across the modules.
In these cases, you want to keep the translations for a given module within that module. As outputPath
only supports 2 parameters, locale
and ns
, it's not possible to configure the output in a way that makes sense for large applications.
You could abuse the ns
variable to do this, but I feel it would be better if the outputPath
option accepted a function that is passed the current babel compiler state and or path to the file being operated on for the given i18next call. That would allow complete flexibility in where to output the files.
It looks like it tries to run mkdir
everytime before adding keys to the JSON file.
Error: EEXIST: file already exists, mkdir './extractedTranslations/en'
So it literally just parse one page, add the key correctly and then errors while parsing the next one.
My configuration is super simple, I've got a .babelrc
file with
{
"presets": ["react-app"],
"plugins": ["i18next-extract"]
}
Is your feature request related to a problem? Please describe.
I am using Transifex for storing all of my translations, which only supports ICU Format for pluralization.
I would love if babel-plugin-18next-extract supported an option to generate the ICU format for plurals instead of i18next's default format.
Describe the solution you'd like
What this means is that instead of generating this:
{
"itemCount": "{{count}} item",
"itemCount_plural": "{{count}} items"
}
I want this to be generated:
{
"itemCount": "{count, plural, one {{count} item} other {count} items}}"
}
I suggest that a new boolean option, icuPlurals
, be added to support this.
Describe alternatives you've considered
I've considered just living with the i18next format that has multiple keys instead of the one key with ICU format. This is not ideal because the Transifex translation UI does not know how to handle those keys as a plural string, but it DOES know how to handle the ICU string as plurals. Transifex presents a special UI to translators when the ICU format is correctly presented.
Additional context
devDependency
@babel/cli was updated from 7.4.4
to 7.5.0
.dependency
@babel/core was updated from 7.4.5
to 7.5.0
.devDependency
@babel/preset-env was updated from 7.4.5
to 7.5.0
.dependency
@babel/types was updated from 7.4.4
to 7.5.0
.This version is covered by your current version range and after updating it in your project the build failed.
This monorepo update includes releases of one or more dependencies which all belong to the babel7 group definition.
babel7 is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
2.3.1
to 2.3.2
.This version is covered by your current version range and after updating it in your project the build failed.
@typescript-eslint/parser is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 4 commits.
926cf64
chore: publish v2.3.2
95c13fe
fix(typescript-estree): handle optional computed prop w/o type (#1026)
8ce3a81
fix(typescript-estree): correct ClassDeclarationBase type (#1008)
cdf9294
fix(eslint-plugin): [no-unnec-type-arg] undefined symbol crash (#1007)
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
1.18.2
to 1.19.0
.This version is covered by your current version range and after updating it in your project the build failed.
prettier is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
just a quick note - the config options in the readme say to use the option 'i18nextInstancesNames' but it should say 'i18nextInstanceNames'
Here is my config
{
keyAsDefaultValue: true,
keyAsDefaultValueForDerivedKeys: false,
}
The problem is when I edit the translation file, after that, I add a new key in component, It will write to the translation file the old content with new key, the content I have edited is lost in the wild. So, I need a config for disable cache in this line
Thank you 🙏
Currently, keys in the JSON file may be reordered by the plugin. Similarly, trailing line returns and whitespaces are always discarded when exported (which is not POSIX compliant, yet arguably a de facto standard imposed by JSON serializers in many languages and tools). This can lead to edition wars and merge conflicts in translation files, where an external tool (such as Weblate or even vim) would use a different order or would append a newline at the end.
The ideal solution would be to make the exporter preserve everything and just add keys like a human would do. We could get closer to this by relying on a lexer such as moo in order to keep a tokenized version of the original JSON file that we could use to re-export it just as it was before.
The problem of trailing whitespaces and line breaks could be addressed with way less effort just by copying in memory the trailing whitespaces and line breaks in the original file and re-adding them before exporting.
See discussions in #58
We are using ICU message format in our JSON files, and thus using the babel macros exported by react-i18next/icu.macro
(Trans
(different), Select
, SelectOrdinal
, Plural
).
https://react.i18next.com/misc/using-with-icu-format
However, those macros do not properly set up the bindings in the AST correctly after swapping out the macro imports for the "normal" react-i18next Trans
import, so this plugin doesn't recognize the new Trans import and doesn't extract the translations (isTransComponent
and referencesImport
return false because they can't find a valid binding)
I have learned my way around babel plugins and macros enough to fix some issues with the ICU macros, so that they generate the correct source code, but I've tried and tried to fix the bindings and I just can't figure out how to do it properly in the AST.
I have a workaround in referencesImport
that adds an additional fallback if the bindings don't exist properly, to just look up the import in the ImportDeclarations. Would that be a welcome PR?
The other alternative is to get some help on making the ICU macro correctly update the bindings when it transforms the source code.
A bit of backstory if helpful:
I've been trying to use other command line extractors, but they choke on the curly braces and comma separated options in the ICU format, and they are just doing static parsing with acorn, so they can't take advantage of the work already in the ICU babel macro. And teaching them to recognize the ICU format seems like a lot of work.
Once I found this project, I realized how much cleaner it would be if the macro could run first, transform the source to handle the funky ICU format curly braces, then the extractor wouldn't need to know any special format, and would just have a "normal" Trans element to work with.
I seem to have that working locally as long as I have the workaround to fallback to direct inspection of the ImportDeclarations if a suitable binding can't be found.
I can provide more details or examples if that is helpful.
What solution do you think would be best for this type of situation?
I have been trying to make the babel-plugin-i18next-extract
work on code thats using
decorators.
I got the following .babelrc using @babel/plugin-proposal-decorators
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-proposal-class-properties", { "loose": true }],
["@babel/plugin-proposal-object-rest-spread"],
[
"i18next-extract",
{
"locales": ["en", "nl"],
"keyAsDefaultValue": true,
"discardOldKeys": true,
"i18nextInstancesNames": ["i18next", "i18n", "props"],
"outputPath": "src/i18n/{{locale}}/{{ns}}.json"
}
]
The babel-plugin-i18next-extract
fails to pick up anything that contains a @withTranslation
it seems
import { withTranslation } from 'react-i18next';
@withTranslation()
export default class Login extends React.Component {
render() {
return <span>{this.props.t("string")}</span>
}
}
Wanted to hear if anybody got any ideas, how to bring that to work?
12.7.2
to 12.7.3
.This version is covered by your current version range and after updating it in your project the build failed.
@types/node is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
1.27.0
to 1.27.1
.This version is covered by your current version range and after updating it in your project the build failed.
rollup is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
2019-11-18
acornOptions
optional in parse()
in docs (@tjenkinson)The new version differs by 7 commits.
0697166
1.27.1
d7ad410
Update changelog
690d388
Do not truncate after switch-statement with removed case (#3241)
3885a7f
make acornOptions
optional in parse()
in docs (#3237)
4227977
Update dependencies and fix vulnerability (#3240)
5289fde
docs: Fix tutorial example
d588810
docs: Fix phase for resolveDynamicImport
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨
To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.
Since we didn’t receive a CI status on the greenkeeper/initial
branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.
If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/
.
Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.
24.0.19
to 24.0.20
.This version is covered by your current version range and after updating it in your project the build failed.
@types/jest is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
This might already be a feature and I just haven't been able to figure out how to get it work successfully, but currently in my project I am storing keys inside of JSON files, for example
login.JSON might contain:
{ "login": { "placeHolder": "Phone number", "login": "Login" } }
while my common.JSON might contain:
{ "common": { "welcome": "Welcome to the Home Menu", "language": "You are now using English", "date": "The current date is {{date, 'LLLL'}}" } }
I basically want to be able to combine these into a single JSON file with their namespaces and keys still intact, but whenever I try to have i18next-extract target JSON files, I usually get an error on the colon ':' where a semicolon is expected ';'.
devDependency
@babel/cli was updated from 7.5.0
to 7.5.5
.dependency
@babel/core was updated from 7.5.4
to 7.5.5
.devDependency
@babel/preset-env was updated from 7.5.4
to 7.5.5
.dependency
@babel/types was updated from 7.5.0
to 7.5.5
.This version is covered by your current version range and after updating it in your project the build failed.
This monorepo update includes releases of one or more dependencies which all belong to the babel7 group definition.
babel7 is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
Is your feature request related to a problem? Please describe.
Using react-i18n
hooks-style components, I've become used to the useTranslation("namespace")
syntax where individual t()
calls do not need a specific namespace specified since it can be inferred from the previous call.
When using a redux-thunk
or redux-saga
module, you aren't able to use the useTranslation()
function since it does not run within a react context.
Describe the solution you'd like
There's a very similar function in i18n itself, i18next#getFixedT()
that returns a TFunction using a fixed namespace (or fixed language, of which doesn't apply here), that allows the t()
behavior as found in react-i18next
.
Right now, babel-plugin-i18next-extract
does not know how to infer namespace from this wrapper function (it does extract t()
calls from it, but in the wrong namespace). Presumably, the extractors/useTranslationHook.ts
extractor could be cloned to support this getFixedT()
function.
Describe alternatives you've considered
t("str", { ns: "namespace" })
a bunch of times. --> lots of repetitive namespace declarations :(Additional context
There are two specific react
options in the react-i18next package which I think aren't supported as part of extraction. (from https://react.i18next.com/latest/i18next-instance)
transSupportBasicHtmlNodes: true,
transKeepBasicHtmlNodesFor: ['br', 'strong', 'i'],
With the following Trans
component.
<Trans ns="onboarding" i18n={props.i18n}>
Thank you, {{firstName: props.firstName}}!
<br />
Welcome to the party
</Trans>
The extraction is attempting to overwrite a key I have defined already:
-"Thank you, {{firstName}}!<br/>Welcome to the party": "Thank you, {{firstName}}!<br/>Welcome to the party"
+"Thank you, {{firstName}}!<3>Welcome to the party": "Thank you, {{firstName}}!<3>Welcome to the party",
I'm using the babel plugin as part of a webpack stack.
.babelrc
["i18next-extract", {
"defaultNS": "common",
"locales": ["en_GB", "de_DE", "en_MX"],
"jsonSpace": 4,
"keySeparator": null,
"nsSeparator": null,
"keyAsDefaultValue": ["en_GB"],
"keyAsDefaultValueForDerivedKeys": false,
"tFunctionNames": [
"i18next.t",
"i18n.t",
"this.props.t",
"props.t",
"t"
],
"outputPath": "./i18n/{{locale}}/{{ns}}.json"
}]
devDependency
@babel/cli was updated from 7.4.4
to 7.5.0
.dependency
@babel/core was updated from 7.4.5
to 7.5.0
.devDependency
@babel/preset-env was updated from 7.4.5
to 7.5.0
.dependency
@babel/types was updated from 7.4.4
to 7.5.0
.This version is covered by your current version range and after updating it in your project the build failed.
This monorepo update includes releases of one or more dependencies which all belong to the babel7 group definition.
babel7 is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
6.5.0
to 6.6.0
.This version is covered by your current version range and after updating it in your project the build failed.
eslint-config-prettier is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
When extraction the keys, if an extraction error happens (for example, because of a dynamic key that can't be solved like t(myVariable)
), all the remaining valid keys in the entire file will be ignored.
This is extra annoying when using the "discardOldKeys": true
configuration, because in this case the existing translations will all be "erased".
To get the t
function, all my components have this:
const { t } = useTranslation();
When I extract translations, I get an error like this for each file that uses the hook:
babel-plugin-i18next-extract: Extraction error in <filename> at line xxx. Couldn't
evaluate i18next key. You should either make the key evaluable or skip the line
using a skip comment (/* i18next-extract-disable-line */ or
/* i18next-extract-disable-next-line */).
Where
line xxx
is the line shown above to get access tot
.
Is there a way to have the extractor avoid this line without having to add the comment hints?
1.18.0
to 1.19.0
.This version is covered by your current version range and after updating it in your project the build failed.
rollup is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 6 commits.
9af119d
1.19.0
b3f361c
Update changelog
456f4d2
Avoid variable from empty module name be empty (#3026)
17eaa43
Use id of last module in chunk as name base for auto-generated chunks (#3025)
871bfa0
Switch to a code-splitting build and update dependencies (#3020)
2443783
Unified file emission api (#2999)
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
devDependency
@babel/cli was updated from 7.6.4
to 7.7.0
.dependency
@babel/core was updated from 7.6.4
to 7.7.0
.devDependency
@babel/preset-env was updated from 7.6.3
to 7.7.0
.devDependency
@babel/preset-react was updated from 7.6.3
to 7.7.0
.devDependency
@babel/preset-typescript was updated from 7.6.0
to 7.7.0
.devDependency
@babel/types was updated from 7.6.3
to 7.7.0
.This version is covered by your current version range and after updating it in your project the build failed.
This monorepo update includes releases of one or more dependencies which all belong to the babel7 group definition.
babel7 is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
I suggest adding a comment hint to "force" adding a key to the extraction.
Ex:
// i18next-extract-add-key key_name
Why it is important:
When using dynamic keys like t(`error.${code}\`)
, you must disable the line with // i18next-extract-disable-next-line
or similar.
However, if you want to add the keys of the multiple options that will be dinamically accessed at runtime, your only option would be to directly add them to the final json files.
As we regularly use "discardOldKeys": true
on the configuration, it is not possible for us to add keys that will not be removed by babel-plugin-i18next-extract.
Using the example of t(`error.${code}`)
we would need to have in the translation.json file:
{ "error": { "404": "File not found", "500": "Server error" } }
This could be added in the following manner:
// i18next-extract-disable-next-line
console.log(t(`error.${code}`));
// i18next-extract-add-key error.404
// i18next-extract-add-key error.500
devDependency
@babel/cli was updated from 7.5.5
to 7.6.0
.dependency
@babel/core was updated from 7.5.5
to 7.6.0
.devDependency
@babel/preset-env was updated from 7.5.5
to 7.6.0
.devDependency
@babel/preset-typescript was updated from 7.3.3
to 7.6.0
.devDependency
@babel/types was updated from 7.5.5
to 7.6.0
.This version is covered by your current version range and after updating it in your project the build failed.
This monorepo update includes releases of one or more dependencies which all belong to the babel7 group definition.
babel7 is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
We have this jsx:
<Trans i18nKey="signup.tos">
Mit der Registrierung des Nutzerkontos erkläre ich mich mit den{" "}
<a
href="https://www.polymore.com/tos"
target="_blank"
rel="noopener noreferrer"
>
AGB
</a>{" "}
einverstanden und bestätige die{" "}
<a
href="https://www.polymore.com/privacy"
target="_blank"
rel="noopener noreferrer"
>
Datenschutzerklärung
</a>{" "}
zur Kenntnis genommen zu haben.
</Trans>
Prettier automatically adds the spaces with {" "} to preserve them. The JSX above gets extracted as:
"tos": "Mit der Registrierung des Nutzerkontos erkläre ich mich mit den <3>AGB</3> einverstanden und bestätige die <8>Datenschutzerklärung</8> zur Kenntnis genommen zu haben.",
Notice how it counts 3 and 8 here. Now the final translation ends up as:
Mit der Registrierung des Nutzerkontos erkläre ich mich mit den einverstanden und bestätige die zur Kenntnis genommen zu haben. zur Kenntnis genommen zu haben.
Some values got lost and some get suddenly repeated. When I overwrite the counters to 2 & 6 as below, it all works as expected:
"tos": "Mit der Registrierung des Nutzerkontos erkläre ich mich mit den <2>AGB</2> einverstanden und bestätige die <6>Datenschutzerklärung</6> zur Kenntnis genommen zu haben.",
So it seems like the counter gets confused by the spaces.
This is happening in a create react app, versions:
"@babel/cli": "^7.6.0",
"babel-plugin-i18next-extract": "^0.2.4",
"react": "^16.8.6",
"react-i18next": "^10.12.5",
devDependency
@babel/cli was updated from 7.5.0
to 7.5.5
.dependency
@babel/core was updated from 7.5.4
to 7.5.5
.devDependency
@babel/preset-env was updated from 7.5.4
to 7.5.5
.dependency
@babel/types was updated from 7.5.0
to 7.5.5
.This version is covered by your current version range and after updating it in your project the build failed.
This monorepo update includes releases of one or more dependencies which all belong to the babel7 group definition.
babel7 is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
12.12.7
to 12.12.8
.This version is covered by your current version range and after updating it in your project the build failed.
@types/node is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
Not sure if I'm missing something in the config, but it looks like when I wrap my components in compose
from recompose
, the namespace doesn't get picked up by babel-plugin-i18next-extract
.
The code below puts the key in this translation file: default.json
import React from 'react';
import { compose } from 'recompose';
import { withTranslation } from 'react-i18next';
const SomeComponent = ({ t }) => <div>{t('mykey')}</div>;
export const SomeComponentWrapped = compose(withTranslation('namespace1'))(SomeComponent);
And this code (when removing compose
) puts it in this file: namespace1.json
import React from 'react';
import { compose } from 'recompose';
import { withTranslation } from 'react-i18next';
const SomeComponent = ({ t }) => <div>{t('mykey')}</div>;
export const SomeComponentWrapped = withTranslation('namespace1')(SomeComponent);
I would expect both code snippet to put the key in the namespace1.json
file.
First off, love the library but couldn't help but notice one large caveat: the library won't extract strings unless the t
function is being called as a property of an object (usually i18n
or i18next
. I think it could be beneficial to pass the translation function as an option too, so cases like this are considered:
const t = await i18n.changeLanguage('es')
console.log(t('Test string'));
or
i18n.changeLanguage('es', (err, t) => {
console.log('Test string');
});
I was going to look into it but wasn't sure if allowing users to specify a blanket function is enough or if the way the file is parsed should be smarter so it knows the function originated from the i18next package. What are your thoughts?
🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨
To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.
Since we didn’t receive a CI status on the greenkeeper/initial
branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.
If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/
.
Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.
19.0.0
to 19.0.1
.This version is covered by your current version range and after updating it in your project the build failed.
i18next is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.
The new version differs by 4 commits.
f27eba8
19.0.1
a09ca22
rebuild
537f2a4
Merge pull request #1359 from adrai/master
0563aaa
ignore non valid keys in saveMissing
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
I am using the plugin with settings:
useI18nextDefaultValue: true, keySeparator: null, discardOldKeys: true
I have a project where I'm using i18next with hooks and the t() function, and every component has its own namespace that is specified by const [t] = useTranslation('namespace').
However, only the first key used with t() in each component gets put in the proper namespace folder in extractedTranslations. The rest get shuffled into the default translation.json. Is this a bug or am I configuring something wrong?
Right now I'm just overriding with i18next-extract-mark-ns-start/stop comments to get everything in the folders I want.
12.11.2
to 12.11.3
.This version is covered by your current version range and after updating it in your project the build failed.
@types/node is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
I've written a custom Trans component, MyTrans, and in the code it is used exactly like Trans would be (ie <MyTrans i18nKey="myKey"> Some stuff to translate </MyTrans>
). Is there an option similar to the 'i18nInstanceNames' where we can specify a name for Trans extraction / would it be possible to add?
2.7.0
to 2.8.0
.This version is covered by your current version range and after updating it in your project the build failed.
@typescript-eslint/eslint-plugin is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 20 commits.
a9117f5
chore: publish v2.8.0
46b58b4
feat(eslint-plugin): add rule restrict-template-expressions (#850)
42a48de
fix(eslint-plugin): [no-unnec-type-arg] throwing on call/new expr (#1217)
ba89168
fix(typescript-estree): correctly account for trailing slash in… (#1205)
eb83af1
fix(eslint-plugin): [require-await] better handle nesting (#1193)
9829dd3
fix(eslint-plugin): [nuta] correctly handle null/undefined separation (#1201)
d1de3a7
fix(eslint-plugin): [unified-signatures] crash: cannot read pro… (#1096)
9aee06c
fix(eslint-plugin): [indent] handle empty generic declarations (#1211)
74192f8
chore: bump dependencies (#1208)
e2008e3
fix(eslint-plugin): [indent] fix decorator type (#1189)
4fac6c5
fix(eslint-plugin): [no-unnecessary-cond] fix naked type param (#1207)
259ff20
feat(eslint-plugin): [no-type-alias] handle conditional types (#953)
9c8203f
fix(eslint-plugin): [camelcase] handle optional member expr (#1204)
d8b07a7
feat(eslint-plugin): add space-before-function-paren [extension] (#924)
ca41dcf
docs(eslint-plugin): brace-style as a replacement for one-line (#1202)
There are 20 commits in total.
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
1.0.0
to 1.0.1
.This version is covered by your current version range and after updating it in your project the build failed.
@types/jest-expect-message is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.