toonvanstrijp / nestjs-i18n

The i18n module for nestjs.
https://nestjs-i18n.com
Other
625 stars 102 forks source link

move error log to only show if key for default value is missing #598

Closed henrikhertler closed 7 months ago

henrikhertler commented 7 months ago

Description

As discussed here https://github.com/toonvanstrijp/nestjs-i18n/discussions/540: It would be nice to only print an error to the console if the translation couldn't be found in any fallback language. Therefore I created this PR.

This will prevent "polluting" logs as the system works as intended and will only log an error if no key in any fallback language is found.

Linked Issues

https://github.com/toonvanstrijp/nestjs-i18n/discussions/540

Additional context

Following the Boy Scout rule (Always leave the code you are working on a little bit better than you found it.) I also tried to make the function I touched more readable.

This is my first contribution. Feel free to remark on anything I can improve. :relieved:

coveralls commented 7 months ago

Coverage Status

coverage: 90.828% (-0.04%) from 90.869% when pulling b0f56b7ea9fc1927cfddc76a05198894c13c51c5 on henrikhertler:move-does-not-exist-log into 3fc33c105a68b112ed7af6237c5f49902d0864b6 on toonvanstrijp:main.

toonvanstrijp commented 7 months ago

@henrikhertler thanks for your contribution! All tests are passing, and this addition will for sure help keep your logs clean! 🎉

toonvanstrijp commented 7 months ago

@rubiin I don't have time to make a release, can you please do it? 🙇🏻 👀

rubiin commented 7 months ago

@rubiin I don't have time to make a release, can you please do it? 🙇🏻 👀

sure thing

lvisb commented 5 months ago

I am still receiving the error message. Version 10.4.0.

@henrikhertler should the line this.logger.error(translationKeyMissing); be inside the clause: if (this.i18nOptions.logging && this.i18nOptions.throwOnMissingKey)?

henrikhertler commented 5 months ago

@lvisb it worked for my use case, I tested it.

Just to double check: Are you sure that you properly set up a fallback language? And your translation is in the fallback language?

If yes, maybe @toonvanstrijp or @rubiin can have a look again. If you could isolate the relevant parts of your code and create a small, standalone example, that would be very helpful.

lvisb commented 5 months ago

@henrikhertler Yes, I have properly set up a fallback language, and the translation is indeed in the fallback language.

I've created a small, standalone example with the relevant parts of the code for easier analysis. You can find it at this link: https://github.com/lvisb/nesti-18n-error