dusanbre/laravel-tolgee

Help with Laravel integration of Tolgee service

1.0.3 2024-09-30 11:26 UTC

This package is auto-updated.

Last update: 2024-10-30 11:40:12 UTC


README

Latest Version on Packagist Total Downloads

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'),

    /*
     * 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'),
];

Usage

Package provides several Artisan commands to work with you translations in Tolgee.

  1. Import keys from your local files into Tolgee service
php artisan tolgee:keys:sync --with-vendors
  1. Delete all keys from Tolgee service
php artisan tolgee:keys:flush
  1. 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:

  1. 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
  1. 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

  1. Restart docker containers
  2. Publish laravel translation files php artisan lang:publish
  3. Edit local translation files
  4. 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

You are need to use English as base language.
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.