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
Installs: 12
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:project
pkg:composer/atico/translator-symfony-demo-google-auth-to-php
Requires
- php: >=8.4
- samuelvi/spreadsheet-translator-core: ^8.4
- samuelvi/spreadsheet-translator-exporter-php: ^8.0
- samuelvi/spreadsheet-translator-provider-googledriveauth: ^8.0
- samuelvi/spreadsheet-translator-reader-xlsx: ^8.1
- samuelvi/spreadsheet-translator-symfony-bundle: ^8.0
- symfony/console: ^7.0
- symfony/dotenv: ^7.0
- symfony/filesystem: ^7.0
- symfony/finder: ^7.0
- symfony/framework-bundle: ^7.0
- symfony/http-foundation: ^7.0
- symfony/http-kernel: ^7.0
- symfony/monolog-bundle: ^3.10
- symfony/routing: ^7.0
- symfony/runtime: ^7.0
- symfony/security-bundle: ^7.0
- symfony/translation: ^7.0
- symfony/yaml: ^7.0
Requires (Dev)
- phpunit/phpunit: ^11.0
- rector/jack: ^0.2.9
- rector/rector: ^2.1
- symfony/phpunit-bridge: ^7.0
This package is auto-updated.
Last update: 2025-11-10 19:50:05 UTC
README
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
- PHP >= 8.4
- Symfony ^7.0
- Composer
Installation
composer create-project atico/translator-symfony-demo-google-auth-to-php
This will install the demo application on your computer.
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
- Go to Google Cloud Console
- Create a new project or select an existing one
- Navigate to "APIs & Services" > "Library"
- Search and enable "Google Sheets API"
- Search and enable "Google Drive API"
2. Create OAuth 2.0 Credentials
- Go to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "OAuth client ID"
- If prompted, configure the OAuth consent screen:
- Add your email and application name
- User Type: External (or Internal if using Google Workspace)
- Select application type: "Desktop application"
- Give it a name (e.g., "Spreadsheet Translator")
- Click "Create"
- Download the JSON file
- Rename it to
credentials.json - Place it in the
private/directory
3. Add Test Users (Optional but Recommended)
To avoid verification warnings during development:
- Go to "APIs & Services" > "OAuth consent screen"
- Scroll to "Test users" section
- Click "+ ADD USERS"
- Add your Google email address
- Save changes
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:
- Copy the URL displayed in the terminal
- Open it in your browser
- Sign in with your Google account
- 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
- Accept the permissions requested
- Google will redirect to
localhostand show a connection error - this is expected - Look at the browser URL bar - it contains the verification code:
http://localhost/?code=4/0AeanS0Z...LONG_CODE...&scope=https://... - 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
- The code is the value that comes after
- 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
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
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:
translations/
│ demo_common.en_GB.php
│ demo_common.es_ES.php
│ demo_common.fr_FR.php
Example output
demo_common.en_GB.php will contain:
<?php return [ 'homepage' => [ 'title' => 'Secured Spreadsheet translator', 'subtitle' => 'Translator of web pages from secured spreadsheet', ], ];
Dependencies
This project uses the Spreadsheet Translator library ecosystem. Check composer.json for the complete list of dependencies.
Main components:
- spreadsheet-translator-core: Core functionality
- spreadsheet-translator-symfony-bundle: Symfony integration
- spreadsheet-translator-provider-googledriveauth: Google Drive authentication
- spreadsheet-translator-reader-xlsx: Excel file reader
- spreadsheet-translator-exporter-php: PHP format exporter
Testing
The project includes comprehensive unit tests using PHPUnit 11:
# Run all tests bin/phpunit # or make test # Run tests with coverage report (generates coverage/index.html) bin/phpunit --coverage-html coverage # or make test-coverage # Run specific test file bin/phpunit tests/Command/TranslatorCommandTest.php
Test Structure
tests/Command/TranslatorCommandTest.php- Unit tests for the translator commandtests/KernelTest.php- Integration tests for the Symfony kerneltests/bootstrap.php- PHPUnit bootstrap filephpunit.xml.dist- PHPUnit configuration
Code Quality
The project uses Rector for automated code refactoring and modernization to PHP 8.4 and Symfony 7:
# Apply Rector changes bin/rector process # or make rector # Preview Rector changes without applying them bin/rector process --dry-run # or make rector-dry
Development
Makefile Commands
The project includes a comprehensive Makefile for convenient development. Run make help to see all available commands:
Local Development (without Docker):
# Install dependencies make install # Run tests make test # Run tests with coverage report make test-coverage # Run Rector to modernize code make rector # Preview Rector changes without applying them make rector-dry # Run all code quality checks make lint # Run the translator command make translate # Clear Symfony cache make cache-clear
Docker Development:
# Show all available commands make help # Start the application make up # Run tests inside Docker make docker-test # Run the translator command inside Docker make docker-translate # Run Rector inside Docker make docker-rector # Access the container shell make shell # Stop the application make down
Related Projects
Symfony Bundle:
Symfony Demos:
- Symfony Demo - Local File to PHP - Takes a local file and creates translation files per locale in PHP format
- Symfony Demo - Google to YML - Takes a non secured Google Drive spreadsheet and creates translation files per locale in YML format
- Symfony Demo - OneDrive to XLIFF - Takes a Microsoft OneDrive spreadsheet and creates translation files per locale in XLIFF format
Contributing
We welcome contributions to this project, including pull requests and issues (and discussions on existing issues).
If you'd like to contribute code but aren't sure what, the issues list is a good place to start. If you're a first-time code contributor, you may find Github's guide to forking projects helpful.
All contributors (whether contributing code, involved in issue discussions, or involved in any other way) must abide by our code of conduct.
License
Spreadsheet Translator Symfony Bundle is licensed under the MIT License. See the LICENSE file for full details.