#not angular specific - general guidance needed

8 messages · Page 1 of 1 (latest)

late verge
#

I have a 60k line json that holds key:value for localization of a huge website
example:

{ 
  "message": "讯息"
}

and there's a file for each language.
I created a c# script that scans each ts & html file in my project
if on ts there's a regex that matches for .translate("string"), that string key is kept
and if in html the key is used next to a pipe, that key is also kept
all other unused keys will be deleted

but since I am using regex there are so many edge cases that don't work, specially since there could be a lot of differences when it comes to stylers, whitespaces...etc

Any idea how to do something like this in the context of vscode or whatever context:
scan all the ts files and whenever there's a ts file that injects translationService & uses the translate() method, take the passed key and log it somewhere
or get all references to a method, and see what value is passed to it.
also scan all the html files and whenever there's usage of my translation pipe, check the passed value and log it somewhere

icy kettle
#

Why not use $localize instead of building your own custom translation solution?

late verge
desert cradle
#

Yes, but you don't have to manually look for translations

peak granite
# late verge regardless of the approach, i still have to have a file with my translations no?

$localize, and the related tooling coming with the CLI has the advantage (for your problem) of generating the translation files for you, by extracting the messages to translate from the sources (HTML and TS) directly.
So you have a way, using that, of only having the actually used keys in the source file.
There are disadvantages though: it's a build-time solution, and not a runtime solution. So you can't (AFAIK) dynamically generate keys and lookup translations at runtime such as

const countryName = translate(`country.` + someObject.countryIsoCode);

Another diadvantage (still AFAIK) is that you have to generate and deploy one application per language rather than created and deploy a single application that can use any of your supported languages.

icy kettle
#

$localize does either build-time or runtime translation

peak granite
#

I stand corrected then. Thanks @icy kettle

peak granite
#

But since it's used by tagging a template literal string, I don't see how to use it to translate IDs generated at runtime.