Skip to content

Commit 86c724b

Browse files
authored
Merge pull request #1 from Scarbous/init
init
2 parents c624874 + c3b9a34 commit 86c724b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2229
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- develop
8+
pull_request:
9+
branches:
10+
- main
11+
- develop
12+
13+
jobs:
14+
test:
15+
name: "PHP ${{ matrix.env.php }} - Symfony ${{ matrix.env.symfony }}"
16+
runs-on: ubuntu-latest
17+
continue-on-error: ${{ matrix.env.experimental == true }}
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
env:
22+
- { php: 7.4, symfony: 5.4 }
23+
- { php: 8.0, symfony: 5.4 }
24+
- { php: 8.1, symfony: 5.4 }
25+
- { php: 8.2, symfony: 5.4 }
26+
- { php: 8.1, symfony: 6.4 }
27+
- { php: 8.2, symfony: 6.4 }
28+
- { php: 8.3, symfony: 6.4 }
29+
- { php: 8.4, symfony: 6.4, experimental: true }
30+
- { php: 8.2, symfony: 7.1, experimental: true }
31+
- { php: 8.3, symfony: 7.1, experimental: true }
32+
- { php: 8.4, symfony: 7.1, experimental: true }
33+
34+
steps:
35+
- uses: actions/checkout@v3
36+
37+
- name: Composer cache
38+
uses: actions/cache@v3
39+
with:
40+
path: "vendor"
41+
key: ${{ runner.os }}-${{ matrix.env.php }}-composer-${{ hashFiles('composer.json') }}
42+
43+
- name: Setup PHP
44+
uses: shivammathur/setup-php@v2
45+
with:
46+
php-version: ${{ matrix.env.php }}
47+
coverage: pcov
48+
49+
- name: Configure Symfony
50+
run: composer config extra.symfony.require "${{ matrix.env.symfony }}"
51+
52+
- name: Install composer
53+
run: composer update --no-progress --ansi --prefer-stable
54+
55+
- name: Validate composer.json and composer.lock
56+
run: composer validate --no-interaction --ansi
57+
58+
- name: PHPUnit tests
59+
env:
60+
XDEBUG_MODE: coverage
61+
run: vendor/bin/phpunit \
62+
--configuration phpunit.xml.dist \
63+
--coverage-php "coverage/test.${{ matrix.env.php }}.${{ matrix.env.symfony }}.cov"
64+
65+
- name: upload coverage file
66+
if: "${{github.event_name}} == 'pull_request'"
67+
uses: actions/upload-artifact@v3
68+
with:
69+
name: coverage
70+
path: "coverage/test.${{ matrix.env.php }}.${{ matrix.env.symfony }}.cov"
71+
72+
- name: upload composer.lock on fail
73+
if: ${{ failure() }}
74+
uses: actions/upload-artifact@v3
75+
with:
76+
name: "composer.php-${{ matrix.env.php }}.symfony-${{ matrix.env.symfony }}"
77+
path: |
78+
composer.json
79+
composer.lock
80+
81+
coverage_report:
82+
needs: test
83+
runs-on: ubuntu-latest
84+
if: "${{ github.event_name }} == 'pull_request'"
85+
steps:
86+
- uses: actions/checkout@v3
87+
88+
- uses: actions/download-artifact@v3
89+
with:
90+
name: coverage
91+
path: coverage
92+
93+
- name: Setup PHP
94+
uses: shivammathur/setup-php@v2
95+
with:
96+
php-version: 8.2
97+
coverage: pcov
98+
99+
- name: Install phpcov
100+
run: composer req --no-progress -n phpunit/phpcov
101+
102+
- name: 'merge coverage files'
103+
run: vendor/bin/phpcov merge --clover coverage/clover.xml ./coverage
104+
105+
- name: 'Generate code coverage summary report'
106+
uses: saschanowak/CloverCodeCoverageSummary@0.4.0
107+
with:
108+
filename: coverage/clover.xml
109+
110+
- name: 'Add code coverage summary as action run comment'
111+
run: |
112+
cat code-coverage-summary.md >> $GITHUB_STEP_SUMMARY
113+
cat code-coverage-details.md >> $GITHUB_STEP_SUMMARY
114+
115+
- name: 'Add code coverage summary as pr comment'
116+
uses: marocchino/sticky-pull-request-comment@v2
117+
with:
118+
recreate: true
119+
path: code-coverage-summary.md

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/composer.lock
2+
/vendor
3+
4+
/coverage
5+
/tests/App/var
6+
/tests/App/translations
7+
8+
/.phpunit.result.cache

.gitpod.Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM gitpod/workspace-full:2022-05-08-14-31-53
2+
3+
RUN sudo update-alternatives --set php $(which php7.4)
4+
5+
RUN sudo install-packages php7.4-xdebug

.gitpod.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
image:
3+
file: .gitpod.Dockerfile
4+
5+
tasks:
6+
- name: translation-provider
7+
openMode: tab-before
8+
init: composer install --no-interaction --optimize-autoloader
9+
10+
- name: tolgee dev server
11+
openMode: split-right
12+
init: |
13+
docker run --restart always --name=tolgee \
14+
-d -v tolgee_data:/data/ \
15+
-v "$(pwd)/.gitpod/tolgee/importData/:/importData/" \
16+
-p 8085:8080 \
17+
--env-file ./.gitpod/tolgee/.env \
18+
tolgee/tolgee
19+
20+
command: |
21+
docker ps
22+
gp ports await 8085
23+
24+
# show tolgee logs
25+
docker logs -f tolgee
26+
27+
ports:
28+
- name: tolgee
29+
port: 8085
30+
onOpen: notify
31+
description: Tolgee Server
32+
33+
vscode:
34+
extensions:
35+
- bmewburn.vscode-intelephense-client
36+
- felixfbecker.php-debug

.gitpod/tolgee/.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
TOLGEE_IMPORT_BASE_LANGUAGE_TAG=en
3+
TOLGEE_IMPORT_CREATE_IMPLICIT_API_KEY=true
4+
TOLGEE_IMPORT_DIR=/importData

.gitpod/tolgee/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM tolgee/tolgee
2+
3+
ENV HEALTHCHECK_PORT=8080
4+
5+
HEALTHCHECK --interval=10s --timeout=3s --retries=20 \
6+
CMD [[ "$(wget -q -O - http://127.0.0.1:$HEALTHCHECK_PORT/actuator/health)" == *"UP"* ]] || exit 1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"wellcome": "Willkommen"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"wellcome": "Wellcome"
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"success": "erfolgreich",
3+
"error": "fehler"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"success": "success",
3+
"error": "error"
4+
}

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,18 @@ where:
2626
You get the project ID from the project URL.
2727

2828
[Generate an API key on Tolge](https://app.tolgee.io/account/apiKeys)
29+
30+
DevSetup
31+
-----------
32+
33+
If you want to develop this package, you can use [gitpod.io](https://gitpod.io/) to start a development environment with all dependencies installed.
34+
35+
It also starts a local Tolgee server with a test project.
36+
http://localhost:8085
37+
38+
You can use the following commands to pull and push translations from/to Tolgee server.
39+
40+
```bash
41+
tests/console translation:pull
42+
tests/console translation:push
43+
```

composer.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "scarbous/tolgee-translation-provider",
3+
"description": "Symfony Tolgee Translation Provider Bridge",
4+
"type": "symfony-bridge",
5+
"keywords": [
6+
"tolgee",
7+
"translation",
8+
"provider"
9+
],
10+
"authors": [
11+
{
12+
"name": "Sascha Heilmeier"
13+
}
14+
],
15+
"license": "MIT",
16+
"autoload": {
17+
"psr-4": {
18+
"Scarbous\\TolgeeTranslationProvider\\": "src/"
19+
}
20+
},
21+
"autoload-dev": {
22+
"psr-4": {
23+
"Scarbous\\TolgeeTranslationProvider\\Test\\": "tests/"
24+
}
25+
},
26+
"require": {
27+
"php": "^7.2 || ^8.0 || ^8.1 || ^8.2",
28+
"symfony/config": "^5.4 || ^6.4",
29+
"symfony/http-client": "^5.4 || ^6.4",
30+
"symfony/intl": "^5.4 || ^6.4",
31+
"symfony/mime": "^5.4 || ^6.4",
32+
"symfony/polyfill-intl-icu": "^1.28"
33+
},
34+
"require-dev": {
35+
"symfony/translation": "^5.4 || ^6.4",
36+
"symfony/phpunit-bridge": "*",
37+
"symfony/framework-bundle": "^5.4 || ^6.4",
38+
"symfony/console": "^5.4 || ^6.4",
39+
"phpunit/phpunit": "^9.6",
40+
"mockery/mockery": "^1.6"
41+
},
42+
"scripts": {
43+
"test": "phpunit",
44+
"test-coverage": "XDEBUG_MODE=coverage phpunit --coverage-html=coverage"
45+
}
46+
}

phpunit.xml.dist

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/9.3/phpunit.xsd"
5+
backupGlobals="false"
6+
colors="true"
7+
bootstrap="tests/bootstrap.php"
8+
failOnRisky="true"
9+
failOnWarning="true"
10+
>
11+
<php>
12+
<ini name="error_reporting" value="-1" />
13+
<server name="APP_ENV" value="test" force="true" />
14+
<server name="KERNEL_CLASS" value="Scarbous\TolgeeTranslationProvider\Test\App\TestKernel" />
15+
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled" />
16+
<env name="TOLGEE_DSN" value="tolgee://1:test-admim-imported-project-implicit@tolgee.local/"/>
17+
</php>
18+
19+
<testsuites>
20+
<testsuite name="unit">
21+
<directory>tests/Unit</directory>
22+
</testsuite>
23+
24+
<testsuite name="functional">
25+
<directory>tests/Functional</directory>
26+
</testsuite>
27+
28+
<testsuite name="Symfony Lokalise Translation Provider Bridge Test Suite">
29+
<directory>tests/Symfony</directory>
30+
</testsuite>
31+
</testsuites>
32+
33+
<coverage>
34+
<include>
35+
<directory suffix=".php">src/</directory>
36+
</include>
37+
<exclude>
38+
<directory>tests</directory>
39+
<directory>vendor</directory>
40+
</exclude>
41+
</coverage>
42+
</phpunit>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Scarbous\TolgeeTranslationProvider\DependencyInjection;
4+
5+
use Symfony\Component\Config\FileLocator;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
use Symfony\Component\DependencyInjection\Extension\Extension;
8+
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
9+
10+
/**
11+
* @codeCoverageIgnore
12+
*/
13+
class TolgeeTranslationProviderExtension extends Extension
14+
{
15+
public function load(array $configs, ContainerBuilder $container)
16+
{
17+
$loader = new PhpFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
18+
$loader->load('translation_providers.php');
19+
}
20+
}

src/Exception/TolgeeException.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Scarbous\TolgeeTranslationProvider\Exception;
6+
7+
use Symfony\Contracts\HttpClient\ResponseInterface;
8+
9+
class TolgeeException extends \Exception
10+
{
11+
private ?ResponseInterface $response;
12+
13+
public function __construct(
14+
string $message,
15+
int $code = 0,
16+
?ResponseInterface $response = null,
17+
\Throwable $previous = null
18+
) {
19+
$this->response = $response;
20+
parent::__construct($message, $code, $previous);
21+
}
22+
23+
public function getResponse(): ?ResponseInterface
24+
{
25+
return $this->response;
26+
}
27+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Scarbous\TolgeeTranslationProvider\TolgeeProviderFactory;
15+
16+
// @codeCoverageIgnoreStart
17+
return static function (ContainerConfigurator $container) {
18+
$container->services()
19+
->set('translation.provider_factory.tolgee', TolgeeProviderFactory::class)
20+
->autowire(true)
21+
->args([
22+
service('http_client'),
23+
service('logger'),
24+
param('kernel.default_locale'),
25+
service('translation.loader.json')
26+
])
27+
->tag('translation.provider_factory');
28+
};
29+
// @codeCoverageIgnoreEnd

0 commit comments

Comments
 (0)