koala-interactive/frenchkiss.js

Extraction Tool

Closed this issue · 6 comments

Nice library! Just wondering whether there's a way to extract the texts to external file such as JSON for further translation?

Hi @beeing,
Do you have an example/more informations about what you actually trying to do ?

I don't get if you're talking about extracting text from your HTML to a JSON file, or about feeding frenchkiss.js with an imported JSON file.

Hi, I'm currently using ngx-translate which is similar but for angular.

Based on your example, we need to set the language first with string template.

set('en', {
  hello: 'Hello {name} !',
});

Then use the template by calling:

t('hello', { name: 'John' }); // => 'Hello John !'

However, a natural workflow is to do the following:

t('Hello {name}', { name: 'John' })

Then we will need a CLI (command line utility) to extract all the texts from t().
Example above would return:

{
    "Hello {name}": ""
}

We can then duplicate this JSON as en.json or any {locale}.json with different key values.

I hope you get the idea.

Just to add in, when the JSON is completed, we can use:

set(locale, loadFromJsonFile)

so that t() will use the correct string templates.

I think you should take a look at i18next-scanner (or another tool).
It extracts translations from your files based on a list of function (here ['t', 'frenchkiss.t']) then generate a json as output.

Ok, looks like this is quite the same. Perhaps can add this into README for a complete picture.
Thanks.