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

Apply translations from local JSON / YAML file and not from a remote source (locize.io) #1

Open
Nowaker opened this issue May 26, 2022 · 3 comments

Comments

@Nowaker
Copy link

Nowaker commented May 26, 2022

🚀 Feature Proposal

We need a way to tell this library what local directory to use as the source of translation keys, so translations don't have to be downloaded from locize.io API.

Motivation

We want to use locizify-ssg as part of our CI build. Currently, executing ssg() on 1000 files will cause the keys in a given namespace to be downloaded 1000 times. This is slow and wasteful, and often not needed - e.g. we don't need to apply up-to-date translations from Locize.io, and whatever is cached locally is fine, and locize download -f json can be executed manually if it needs to be brought up-to-date.

Example

ssg('index.html', 'de', 'de.html', {
  fallbackLng: 'en',
  backend: {
    projectId: '123aa5aa-4660-4154-b6d9-907dbef10bb2',
    version: 'production'
  },
  namespace: 'landingpage'
}, function(namespace) { // last parameter is a callback to fetch the keys from a given namespace
  return JSON.parse(fs.readFileSync(`i18n/${namespace}.json`))
})

or

ssg('index.html', 'de', 'de.html', 'i18n/', { // 4th paramter is local directory where translations are stored
  fallbackLng: 'en',
  backend: {
    projectId: '123aa5aa-4660-4154-b6d9-907dbef10bb2',
    version: 'production'
  },
  namespace: 'landingpage'
})
@adrai
Copy link
Contributor

adrai commented May 27, 2022

locizify-ssg is highly experimental and based on locizify so there is only the option to download directly from locize.
You can try to pass in the translations via resources option, like here: https://www.i18next.com/how-to/add-or-load-translations#add-on-init but never tried if this works.

@Nowaker
Copy link
Author

Nowaker commented May 27, 2022

It sounds promising. Could you help provide a Locizify init example? What to add here?

locizify-ssg -i _gatsby/public/es/index.html -o _gatsby/public/es/index.html -l es -s '{"backend":{"projectId":"3f516219-6546-4f2a-9030-fc31659dc115","apiKey":"xxx","referenceLng":"en"},"fallbackLng":"en","lng":"es","saveMissing":false,"debug":false,"namespace":"root","ns":["common"],"translateAttributes":["placeholder","title","alt","content#meta.name=description","content#meta.name=keywords","content#meta.property","value#input.type=submit","value#input.type=button","value#input.type=reset"],"ignoreTags":["script","style","iframe","svg"]}'

@adrai
Copy link
Contributor

adrai commented May 27, 2022

something like this:

just made an example with the key: "Academy"

locizify-ssg -i _gatsby/public/es/index.html -o _gatsby/public/es/index.html -l es -s '{"resources": { "es": { "root": { "Academy": "Academia" } } }, "backend":{"projectId":"3f516219-6546-4f2a-9030-fc31659dc115","apiKey":"xxx","referenceLng":"en"},"fallbackLng":"en","lng":"es","saveMissing":false,"debug":false,"namespace":"root","ns":["common"],"translateAttributes":["placeholder","title","alt","content#meta.name=description","content#meta.name=keywords","content#meta.property","value#input.type=submit","value#input.type=button","value#input.type=reset"],"ignoreTags":["script","style","iframe","svg"]}'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants