PHPackages                             atico/translator-symfony-demo-google-auth-to-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. atico/translator-symfony-demo-google-auth-to-php

ActiveProject[Utility &amp; Helpers](/categories/utility)

atico/translator-symfony-demo-google-auth-to-php
================================================

Spreadsheet Translator. Symfony Demo Application. Takes a Google Drive spreadhseet file and creates a translation file per locale in Yml format

v8.4.2(6mo ago)012MITPHPPHP &gt;=8.4CI passing

Since Jan 2Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/samuelvi/translator-symfony-demo-google-auth-to-php)[ Packagist](https://packagist.org/packages/atico/translator-symfony-demo-google-auth-to-php)[ RSS](/packages/atico-translator-symfony-demo-google-auth-to-php/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (22)Versions (5)Used By (0)

Spreadsheet Translator Symfony Demo Application - Use Case
==========================================================

[](#spreadsheet-translator-symfony-demo-application---use-case)

Introduction
------------

[](#introduction)

Lightweight Symfony Demo Application for the Spreadsheet Translator functionality. This demo provides a command that connects to Google Drive with authentication, reads a spreadsheet file, and generates translation files per locale in PHP format.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.4
- Symfony ^7.0
- Composer

Installation
------------

[](#installation)

```
composer create-project atico/translator-symfony-demo-google-auth-to-php
```

This will install the demo application on your computer.

Google OAuth Setup
------------------

[](#google-oauth-setup)

This application uses Google OAuth 2.0 to access secured Google Sheets. Follow these steps to configure authentication:

### 1. Create Google Cloud Project and Enable APIs

[](#1-create-google-cloud-project-and-enable-apis)

1. Go to [Google Cloud Console](https://console.cloud.google.com)
2. Create a new project or select an existing one
3. Navigate to **"APIs &amp; Services" &gt; "Library"**
4. Search and enable **"Google Sheets API"**
5. Search and enable **"Google Drive API"**

### 2. Create OAuth 2.0 Credentials

[](#2-create-oauth-20-credentials)

1. Go to **"APIs &amp; Services" &gt; "Credentials"**
2. Click **"Create Credentials" &gt; "OAuth client ID"**
3. If prompted, configure the OAuth consent screen:
    - Add your email and application name
    - User Type: External (or Internal if using Google Workspace)
4. Select application type: **"Desktop application"**
5. Give it a name (e.g., "Spreadsheet Translator")
6. Click **"Create"**
7. Download the JSON file
8. Rename it to `credentials.json`
9. Place it in the `private/` directory

### 3. Add Test Users (Optional but Recommended)

[](#3-add-test-users-optional-but-recommended)

To avoid verification warnings during development:

1. Go to **"APIs &amp; Services" &gt; "OAuth consent screen"**
2. Scroll to **"Test users"** section
3. Click **"+ ADD USERS"**
4. Add your Google email address
5. Save changes

### 4. First-Time Authentication

[](#4-first-time-authentication)

Run the translator command:

```
bin/console atico:demo:translator --sheet-name=common --book-name=frontend
```

The system will prompt you to authenticate:

1. **Copy the URL** displayed in the terminal
2. **Open it in your browser**
3. **Sign in** with your Google account
4. You may see a warning: *"Google hasn't verified this app"*
    - Click **"Advanced"** or **"Advanced settings"**
    - Click **"Go to Spreadsheet Translator (unsafe)"**
    - This is safe - it's your own application
5. **Accept the permissions** requested
6. Google will redirect to `localhost` and show a connection error - **this is expected**
7. **Look at the browser URL bar** - it contains the verification code: ```
    http://localhost/?code=4/0AeanS0Z...LONG_CODE...&scope=https://...

    ```
8. **Extract the verification code from the URL:**
    - The code is the value that comes **after** `code=` and **before** `&`
    - For example, if the URL is: ```
        http://localhost/?code=4/0AeanS0Zabcdefghijklmnopqrstuvwxyz1234567890&scope=https://...

        ```
    - The code to copy is: ```
        4/0AeanS0Zabcdefghijklmnopqrstuvwxyz1234567890

        ```
9. **Paste the code into the terminal** where it says "Enter verification code:"

The system will save your credentials in `private/token.json` and you won't need to authenticate again unless you delete this file.

### 5. Configuration

[](#5-configuration)

Edit `config/packages/atico_spreadsheet_translator.yaml` to configure your spreadsheets:

```
atico_spreadsheet_translator:
  frontend:
    provider:
      application_name: 'Your App Name'
      name: 'google_drive_auth'
      source_resource: 'YOUR_GOOGLE_SHEETS_URL'
      credentials_path: '%kernel.project_dir%/private/credentials.json'
      client_secret_path: '%kernel.project_dir%/private/token.json'
```

Replace `YOUR_GOOGLE_SHEETS_URL` with your Google Sheets URL.

**Note:** Make sure the Google account you authenticate with has access to the spreadsheet you want to translate.

Running the demo
----------------

[](#running-the-demo)

Execute the following command in your terminal:

```
bin/console atico:demo:translator --sheet-name=common --book-name=frontend
```

This command will generate translation files that will be stored in the `translations/` folder.

### Generated files structure:

[](#generated-files-structure)

```
translations/
│  demo_common.en_GB.php
│  demo_common.es_ES.php
│  demo_common.fr_FR.php

```

### Example output

[](#example-output)

`demo_common.en_GB.php` will contain:

```
