Manage Laravel translations with Google Spreadsheets

  • 2 Min. Read.

Managing translations with Google Spreadsheets in your Laravel application is very easy thanks to nikaia/translation-sheet.

Install the package

In your Laravel project root, run the follwing composer command:

Creating a project in the Google Cloud Console

  1. Head to https://console.developers.google.com/ and create a new project. 
  2. Activate the Sheet Api for the project (Library -> search for ‘Sheets’ -> Enable)
  3. Create a Service Account and credentials
    1. Navigate to “Credentials”
    2. Click “Create credentials”
    3. Choose “Service Account key”
    4. Choose A “New Service Account” in the “Service account” select
    5. Choose a name. (ie. This is the name that will show up in the Spreadsheet history operations), “Editor” as role and “JSON” for the key type.
    6. Save the credentials to ‘resources/google/service-account.json’ folder. (This can be configured later)
    7. Make sure to write down the service account email, you will need it later for the package configuration.

Create a new spreadsheet

  1. Create a blank/new spreadsheet here https://docs.google.com/spreadsheets/ .
  2. Share it with the service account email (from the cloud console) with Can edit permission.
  3. Copy the ID from the URL, the ID looks like this: https://docs.google.com/spreadsheets/d/1Vt3QwJV6qovvHZhSxGVdpb8VEYEzRwV-gxyGlRwugWa/edit#gid=0

Configure your Laravel project

In your .env file, add the following variables:

Then, in your console run the following sequence of commands:

Adding translations to the sheet

Open up the Google sheet (if you forgot the URL, you can open it by executing php artisan translation_sheet:open in the console).

Importing translations into Laravel

After translating the keys to your desired languages, it’s time to import them back into the Laravel application. You can import the translations with the following command:

 

A concept by Wonderlus

Warning: Parameter 1 to W3_Plugin_TotalCache::ob_callback() expected to be a reference, value given in /mnt/home_bingo/codecaptain/codecaptain.io/public/wp-includes/functions.php on line 3583