Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cached read on 304 response #4

Merged
merged 1 commit into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ PHRASE_DSN=phrase://PROJECT_ID:API_TOKEN@default?userAgent=myProject

- `PROJECT_ID`: can be retrieved in phrase from `project settings > API > Project ID`
- `API_TOKEN`: can be created in your [phrase profile settings](https://app.phrase.com/settings/oauth_access_tokens)
- `default`: enpoint, defaults to `api.phrase.com`
- `default`: endpoint, defaults to `api.phrase.com`
### dsn query parameters

- `userAgent`: please read [this](https://developers.phrase.com/api/#overview--identification-via-user-agent) for some examples.

## ❗ blocked key
to prevent your phrase interface to go all bonkers, add `*{{*}}*` as a blocked key to your project. basically ruling out a whole bunch of default symfony validator constraint messages.

at the moment this can't be done programmatically as phrase doesn't provide a way to query exisiting blocked keys and listing them has a limit of 100 blocked keys per response which will potentially endanger your rate limit for projects with large amounts of blocked keys.
## ❗ curly delimiters for placeholders
at the moment the phrase user interface to goes all bonkers when using curly brackets as delimiters for placeholders.
phrase is aware of this issue and is currently looking into that. until that's resolved, try and not be bothered by it.

## service phrase provider
in your `services.yaml` add the following to enable the phrase provider.
Expand All @@ -40,6 +39,7 @@ in your `services.yaml` add the following to enable the phrase provider.
$defaultLocale: '%kernel.default_locale%'
$loader: '@translation.loader.xliff'
$xliffFileDumper: '@translation.dumper.xliff'
$cache: '@cache.app'
```
and in your `translations.yaml` you can add:
```yaml
Expand All @@ -59,5 +59,14 @@ if you define a locale in your `translation.yaml` which is not configured in you
translations will be tagged in phrase with the symfony translation domain they belong to.
currently no feature to map domains to alternative tags is provided (helper to batch add tags to existing translations seems more sensible).

## phrase read event
after reading the catalogue from phrase, the resulting `TranslatorBag` is dispatched in a `PhraseReadEvent` prior to being returned from the provider's read method. this will enable you to perform post-processing on translation values and / or keys if needed.
## cache
the read responses from phrase are cached to speed up the read and delete method of this provider.
therefor the factory should be initialised with a PSR-6 compatible cache adapter.

## events
to enable you to perform post-processing on translation values and / or keys, two events are dispatched by this provider class.

### PhraseReadEvent
_after_ reading the catalogue from phrase, the resulting `TranslatorBag` is dispatched in a `PhraseReadEvent` prior to being returned from the read method.
### PhraseWriteEvent
_before_ writing the catalogue to phrase, the `TranslatorBag` is dispatched in a `PhraseWriteEvent`.
17 changes: 9 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,23 @@
"minimum-stability": "stable",
"require": {
"php": "~8.1.0 || ~8.2.0",
"psr/cache": "^3.0",
"psr/event-dispatcher": "^1.0",
"symfony/config": "^5.4.16|^6.0",
"symfony/event-dispatcher": "^6.2",
"symfony/http-client": "^5.4.16|^6.0",
"symfony/translation": "^5.4.16|^6.0",
"symfony/serializer": "^5.4.16|^6.0",
"symfony/event-dispatcher": "^5.4.16|^6.0",
"symfony/mime": "^5.4.16|^6.0",
"infection/infection": "^0.26.16"
"symfony/translation": "^5.4.16|^6.0"
}
,
"require-dev": {
"roave/security-advisories": "dev-latest",
"phpunit/phpunit": "^9.5.27",
"infection/infection": "^0.26.16",
"phpstan/phpstan": "^1.9.4",
"phpstan/phpstan-php-parser": "^1.1.0",
"phpstan/phpstan-deprecation-rules": "^1.1.1",
"phpstan/phpstan-phpunit": "^1.3.3"
"phpstan/phpstan-php-parser": "^1.1.0",
"phpstan/phpstan-phpunit": "^1.3.3",
"phpunit/phpunit": "^9.5.27",
"roave/security-advisories": "dev-latest"
},
"config": {
"sort-packages": true,
Expand Down
Loading