You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Having an interpolated string (using template-literals) causes failure in processing the Node. This is currently handled by throwing an error; example:
However, it would be helpful to just get the string as whole without substituting the variable for its value. For example, this string would cause failure: some interpolated string ${someVar}. But instead, this could just be output as is (some interpolated string ${someVar}), without attempting to substitute someVar for its value, and not throw an error.
Describe the solution you'd like
The loader-config should accept a fallback callback-function to allow custom-processing the AST. In my case, I could get the actual string I need by just replacing above error-code with:
if(typeofkeyEvaluation!=='string'){if(config.fallbackTCallBabelNodeProcessor){keyEvaluation=config.fallbackTCallBabelNodeProcessor(args[0]);}else{thrownewExtractionError(`Couldn't evaluate i18next key. You should either make the key `+`evaluable or skip the line using a skip comment (/* `+`${COMMENT_HINTS_KEYWORDS.DISABLE.LINE} */ or /* `+`${COMMENT_HINTS_KEYWORDS.DISABLE.NEXT_LINE} */).`,path,);}}
This will add a lot of flexibility to the plugin.
Describe alternatives you've considered
An alternative is to actually implement this kind of fallback inside evaluateIfConfident, where it just returns the code as is. In my case, replacing null on last line of this function with return path.hub.file.code.substring(path.node.start + 1, path.node.end + 1); does the trick.
I am open to taking this on and creating a PR if the solution looks viable.
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
Having an interpolated string (using template-literals) causes failure in processing the Node. This is currently handled by throwing an error; example:
babel-plugin-i18next-extract/src/extractors/tFunction.ts
Lines 99 to 105 in b709c84
However, it would be helpful to just get the string as whole without substituting the variable for its value. For example, this string would cause failure:
some interpolated string ${someVar}
. But instead, this could just be output as is (some interpolated string ${someVar}
), without attempting to substitutesomeVar
for its value, and not throw an error.Describe the solution you'd like
The loader-config should accept a fallback callback-function to allow custom-processing the AST. In my case, I could get the actual string I need by just replacing above error-code with:
The implementation can look something similar to:
This will add a lot of flexibility to the plugin.
Describe alternatives you've considered
An alternative is to actually implement this kind of fallback inside
evaluateIfConfident
, where it just returns the code as is. In my case, replacingnull
on last line of this function withreturn path.hub.file.code.substring(path.node.start + 1, path.node.end + 1);
does the trick.I am open to taking this on and creating a PR if the solution looks viable.
The text was updated successfully, but these errors were encountered: