lokalise / node-lokalise-api

Lokalise API v2 Node.js client.

Home Page:https://lokalise.github.io/node-lokalise-api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Update translation values en masse and in different branches.

Trevorton27 opened this issue · comments

Hey there. Based on the docs, I am unsure on how to go about the bulk update of a given value in translation keys. Do I need to call each instance I want to update, update it locally and then push it back up?

Also, I am unsure how to select which branch I am pushing to from my local machine. I have successfully created to two branches with 100 keys each but need to update the translation values for both. The documentation is not too helpful here. Any suggestions?
Thank you so much in advance.
-Trevor

That's a fair question! Actually, we do have bulk update for the Keys endpoint: https://app.lokalise.com/api2docs/curl/#transition-bulk-update-put It works in the following way https://github.com/lokalise/node-lokalise-api/blob/master/test/keys/keys.spec.ts#L203

For example, we could say:

      const keys = await lokaliseApi.keys().bulk_update(
        [
          {
            key_id: 1234,
            translations: [
              {
                language_iso: 'en',
                "translation": "English translation"
              },
              {
                language_iso: 'fr',
                "translation": "French translation"
              },
            ]
          },
          {
            key_id: 5678,
            translations: [
              {
                language_iso: 'en',
                "translation": "English translation for the 2nd key"
              },
              {
                language_iso: 'fr',
                "translation": "French translation for the 2nd key"
              },
            ]
          },
        ],
        { project_id: '123.abc'}
      );

So, you'll need to know your key IDs to update and then just pass translations array with the language ISO codes and the corresponding translation values. I believe it should work.

As for the branches, https://lokalise.github.io/node-lokalise-api/api/getting-started#branching here's a brief explanation. All in all, you just provide the branch name right after the project ID separated with :

'123.abc:my_branch'

So, for example to list all keys from a develop branch:

const keys = await lokaliseApi.keys().list({ project_id: '123.abc:develop' });

You can use exactly the same approach for all other methods: just add branch name after the project ID.

And once again this post https://lokalise.com/blog/lokalise-apiv2-in-practice/ might present some helpful examples as well.

I'm going to close this for now but if you have any other questions don't hesitate to reach out to us!