GitHub

把文件从GitHub f和创建请求rom Lokalise.

Nick Ustinov avatar
Written byNick Ustinov
Updated over a week ago

Use this app to exchange files with yourGitHub repository.

As soon as the app is set up, you can pull the files manually via the Lokalise web dashboard or set up an automatic pull so that the files are imported automatically as they are pushed to GitHub by your developer team.

Once the translations are completed, you can trigger the creation of a pull request on GitHub via theDownloadpage.

Index

Setup

1. Connect your repository

First of all, open your translation project and navigate toApps:

FindGitHubin the list of apps, click on it, pressInstall,and thenConnect. Previously you had to generate a special access token on GitHub but that's not the case anymore. While you can still use personal access tokens for existing integrations, new setups involve OAuth 2 flow. All you have to do after clicking theConnectbutton is to give Lokalise Apps the necessary access rights. Keep in mind that thereposcope is required for this app.

Please notethat if you are trying to connect Lokalise to a GitHub organization (not to a personal account) you will probably have to perform some additional steps as explained in theNote on GitHub organization section.

After that you can enter theRepository name(prefixed with your organization name)and theBranchto pull from:

你从Lokalise出口文件,你可以触发the GitHub app to create pull requests to repositories with a platform related to the exported file format.

It is important to decide whether you would like the filenames toinclude a full path. It is not needed in most cases, as you can configure the directory structure prefix at the pull request creation (export) step. However, when you have similar files in different subfolders, e.g.admin/locale.jsonandfrontend/locale.json, you need to enable the Include path in the filenames option. Keep in mind that if you already have files uploaded to the project, including a path in the filenames at this step would mean that you are uploading different files.

2. Select files to pull

Browse the selected repository and select the files you want to pull and import.

In most cases, at this step you would only need to select thebase languagefiles (the files that are being modified locally and then pushed to GitHub). After selecting a file, you must set the language of the file in the dropdown menu.

After the files are pulled, you can find your translation data in theEditor:

3. Add more repositories

As we recommend keeping all platform files within the same project, you may want to set up other repositories that apply to the same project. ClickAdd another repoto add more repositories.

Note on GitHub organizations

If you are trying to connect Lokalise to aGitHub organizationbut experience errors on the first step (after logging in with GitHub and giving Lokalise all the necessary access rights), you'll need to perform some additional actions:

  • Find your organization in theOrganization accesssection and clickGrant:

  • Open your organization settings under the following URL:https://github.com/organizations/YOUR_ORGANIZATION_NAME/settings/oauth_application_policy(this page can be found underOrganization settings > Integrations > Third-party access). Make sure that theLokalise Appsis approved. If not, click on thepeniconand manually set the status to "approved":

After performing these steps you can return to theSetupsection and try connecting your repository again.

Pulling files

Manual pull

Use thePull nowbutton on the app page. Clicking the button will add the pull to the system queue to be executed in the background.

If you need to adjust the options, clickPull optionson the app page:

These options are similar to the ones presented on theUpload page.

Auto-pull

When you are satisfied with the initial pull results, it is a good idea to set up a webhook in GitHub which automates pulling the changes to Lokalise as you push to GitHub.

In GitHub, navigate to your repository settings >Webhooksand copy/paste theAuto-pullURL provided in the Lokalise app configuration. You will need to provide theAuto-pull secretgenerated on the app page as well.

Pull requests

To create a new pull request on GitHub with all the changes made on Lokalise, proceed to theDownloadpage and find theApp triggerssection. Enable theGitHuboption:

It is a good idea to use thePreviewbutton first, so you can see the resulting file/folder structure before triggering the creation of a pull request.

We would recommend triggering pull requests only to the repos of the platform that match the file type you are exporting, i.e. if you are exporting a JSON format, Lokalise will only create pull requests in repositories with the Web platform.

To actuallycreate a pull requeston GitHub, you should pressBuild only(this way you won't download a translation bundle to your local PC). To check the status of the pull request creation, return to the GitHub app page and click theLogsbutton.

Here is what happens after you trigger a new PR:

  1. A new branch is created from the last revision of the branch you chose in the app setup. The branch name would look like this:lokalise-2018-03-12_15-14-13.

  2. A commit with all the files is created in the new branch.

  3. A pull request from the new branch to the previously chosen branch is created.

You may then review and merge a pull request on GitHub.

To initiate a pull request from the API, usetriggers=['github']parameter with the /export endpoint. If you are using the CLI tool, use--triggers=githubas a parameter when performing the export.

GitHub Enterprise

This app is available from the Pro plan and above.

This type of app allows you to exchange files with a self-hostedGitHub Enterprise. The only difference is that you'll need to provide a URL to the server where your GitHub is hosted and apersonal tokenwhen setting up the app:

To generate a personal access token:

  • Open GitHub.

  • Click on your avatar and chooseSettings.

  • In the left sidebar, clickDeveloper settings.

  • In the left sidebar, clickPersonal access tokens.

  • ClickGenerate new token.

  • Give your token a descriptive name.

  • Enable thereposcope for this token.

  • ClickGenerate token, copy it and paste to the corresponding field on Lokalise. Never publicly expose your token!

Apart from that, this feature works in the same way as the ordinary GItHub app.

FAQ

Why does Lokalise request access to all my repositories?

Lokalise requests access to all repositories in order to list them during the setup process so that you may specify which repository to connect to Lokalise. There is no alternative more restrictive OAuth scope that can be used for this purpose.

Once the app is configured, Lokalise will only work with the repository that you selected. Admin scopes are not required.

What actions does the app use the OAuth token for?

Lokalise will only create merge requests and fetch the files that you selected during the setup process. The Lokalise Github app will not alter the repo’s settings in any way.

Is there any way to restrict the app's permissions?

Github user permission scopes limit access for OAuth tokens. No additional permissions beyond your settings in Github are granted. Therefore, the Lokalise app's access is limited by the permissions of the user who configures the integration.

If you need to limit the integration’s access to a specific repository only, you can do that by limiting the permissions of the authorizing user’s Github account.

Github users always have the option to revoke a token or edit the token scopes, giving them greater control over what the integration can do.

How is my access token stored?

Your token is stored in an encrypted form in our database. The database itself is stored on dedicated servers located at the Hetzner Online provider, which ensures top-level physical security (read more herehttps://www.hetzner.com/pdf/en/Sicherheit_en.pdf).

We take regular snapshots of the database and store them in a 256-bit encrypted Amazon S3 bucket for 30 days.

Did this answer your question?