With Angular 9+ you can do this
let <local_variable> = $localize`:@@<unique_id>:<optional_text>`
Example: let err_msg = $localize`:@@err_username:Invalid username, please check your inputs`;
As of now you cannot auto extract these variables automatically using npm script. You have to manually add it like this
In messages.xlf file
<trans-unit id="err_username:Invalid" datatype="html">
<source>Invalid username, please check your inputs</source>
</trans-unit>
In messages.lang.xlf file (translation file for language
<trans-unit id="err_username:Invalid" datatype="html">
<source/>
<target>Ungültiger Benutzername, bitte überprüfen Sie Ihre Eingaben</target>
</trans-unit>