dusanbre / laravel-tolgee
Help with Laravel integration of Tolgee service
Fund package maintenance!
Dusan Antonijevic
Requires
- php: ^8.2
- illuminate/contracts: ^10.0||^11.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
README
This package provides integration with Tolgee service with Laravel apps.
Installation
You can install the package via composer:
composer require dusanbre/laravel-tolgee
You can publish the config file with:
php artisan vendor:publish --tag="laravel-tolgee-config"
This is the contents of the published config file:
return [ /* * Specify the path to your language files * Default is 'lang' it can be set to 'resources/lang' */ 'lang_path' => env('TOLGEE_LANG_PATH', 'lang'), /* * Specify a language files subfolder, in order to filter specific language files.Please be aware that this applies to subfolders within your base local folders. * So if you have folder structure like `lang/en/messages/...`, you can set this env variable to `messages` and package will use only files from messages folder. */ 'lang_subfolder' => env('TOLGEE_LANG_SUBFOLDER'), /* * Host to you Tolgee service instance * Please note that if you are using Sail for local development, service need to be in the same docker network * and you will need to set host in the format of 'http://{docker_tolgee_service_name}:{docker_tolgee_service_port}' */ 'host' => env('TOLGEE_HOST', 'https://app.tolgee.io'), /** * Project ID of your Tolgee service. */ 'project_id' => env('TOLGEE_PROJECT_ID'), /** * Valid api key from Tolgee service for the given project. * Api key needs to have all permissions to manage project. */ 'api_key' => env('TOLGEE_API_KEY'), /** * Base locale of the project. * Please note that the locale you set here should match the base language in your project. */ 'locale' => env('TOLGEE_LOCALE', 'en'), /** * Override base locale translations files. */ 'override' => env('TOLGEE_OVERRIDE', false), /** * Accepted translation states. Check Tolgee documentation for available states. * Ex: REVIEWED,DISABLED,UNTRANSLATED,TRANSLATED */ 'accepted_states' => explode(",", env('TOLGEE_ACCEPTED_STATES', 'REVIEWED')), ];
Usage
Package provides several Artisan commands to work with you translations in Tolgee.
- Import keys from your local files into Tolgee service
php artisan tolgee:keys:sync --with-vendors
- Delete all keys from Tolgee service
php artisan tolgee:keys:flush
- Import translations from Tolgee service into your local files
php artisan tolgee:translations:sync
You will need to have Tolgee instance set up in your config file.
Configuration
If you want to use this locally in your project you can run it on the docker container:
- Add service in your docker-compose.yml
...
tolgee:
image: tolgee/tolgee
volumes:
- sail-tolgee:/data
- ./tolgee.config.yaml:/config.yaml
ports:
- '25432:25432'
- '9090:8080'
environment:
spring.config.additional-location: file:///config.yaml
networks:
- sail
...
volumes:
...
sail-tolgee:
driver: local
- Add config
tolgee.config.yaml
in root of you project
tolgee:
authentication:
enabled: true
initial-password: admin
initial-username: admin
jwt-secret: <jwt-secret> // Random string
machine-translation:
google:
api-key: <google-translations-api-key> // If you want to use google translation
smtp:
auth: false
from: Tolgee <no-reply@nibblo.com>
host: mailpit
password: 'password'
port: 1025
ssl-enabled: false
username: user@company.com
You can see more about configuration and setup on Tolgee docs
- Restart docker containers
- Publish laravel translation files
php artisan lang:publish
- Edit local translation files
- Use package commands to sync it with Tolgee
NOTE
You should be able to access Tolgee service on http://localhost:9090
When you setup is dockerized, you will need to set TOLGEE_HOST for docker internal network. In this case that would be
http://tolgee:8080
Limitations
All operations are constrained to one project.
This will be fixed/implemented in the future.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.