Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extraction Tool #3

Closed
beeing opened this issue Feb 26, 2019 · 6 comments
Closed

Extraction Tool #3

beeing opened this issue Feb 26, 2019 · 6 comments
Labels
question Further information is requested

Comments

@beeing
Copy link

beeing commented Feb 26, 2019

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

@vthibault
Copy link
Member

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.

@beeing
Copy link
Author

beeing commented Feb 26, 2019

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.

@beeing
Copy link
Author

beeing commented Feb 26, 2019

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

set(locale, loadFromJsonFile)

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

@vthibault
Copy link
Member

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.

@chrisnicola
Copy link

You can try https://github.com/lukasgeiter/gettext-extractor. po2json or https://github.com/perch-foundation/po-loader can be used to convert the PO data.

@vthibault vthibault added the question Further information is requested label Feb 26, 2019
@beeing
Copy link
Author

beeing commented Feb 27, 2019

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

@beeing beeing closed this as completed Feb 27, 2019
vthibault added a commit that referenced this issue Feb 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Development

No branches or pull requests

3 participants