ngx-translate-extract icon indicating copy to clipboard operation
ngx-translate-extract copied to clipboard

[FR]: Support context/comments

Open vandres opened this issue 1 year ago • 3 comments

Would it be possible, to implement context as this fork https://www.npmjs.com/package/@shavenzov/ngx-translate-extract ?

vandres avatar Mar 10 '24 22:03 vandres

Note: the feature is described here: https://www.npmjs.com/package/@shavenzov/ngx-translate-extract#context-and-comment-support

I'll leave this to the community to see if someone has the will and ability to implement this. If so, let me know and we can discuss whether that API is the best option.

michaelbromley avatar Mar 11 '24 15:03 michaelbromley

I created a first running version for us. https://github.com/vandres/ngx-translate-extract

Docs are lacking and I am not sure, if the quality is good enough for a PR. Would love some feedback from you guys!

We are using it with CrowdIn the following way:

ngx-translate-extract -k --input ./src --output ./src/static/assets/i18n/{en,de,fr,it,nl,es,sv,ja,da,no}.json --clean --sort --format context-json --format-context-key crowdinContext --format-value-key text

With marker from https://github.com/vandres/ngx-translate-extract-marker:

marker('We', 'Short for Wednesday');

With Pipe, Service or Directive, just provide a "_context" translate param:

<h3 mat-subheader>{{ "User" | translate: {_context: 'System-User'} }}</h3>

Known issues:

  • remove context, after it has been added to the translations files, not automatically possible
  • no unit tests for context
  • conversion between different json formats untested

vandres avatar Mar 13 '24 13:03 vandres

Thanks @vandres,

@michaelbromley, would it be possible to take what was done and also support gettext (pot) format ?

dsnoeck avatar Mar 24 '25 09:03 dsnoeck