Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [0.5.0] - 2026-08-14
### Added
- `language` option on `ConfOptions` — sets the widget UI language through `conf()`, mirroring `theme`. Values: `null` (follows the browser, falling back to English), `en`, `cs`, `sk`. Unlike the `snippet()` parameter it can be changed at runtime; when both are given, the conf value wins

## [0.4.0] - 2026-08-07
### Added
- `entityResolve` callback option on `ConfOptions` — resolves business-entity detail for the message editor's chip hover-card
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,16 @@ See the full list of parameters in [`src/Options/ConfOptions.php`](src/Options/C
| `pageCSSPath` | `?string` | CSS file URL injected into the snippet iframe. |
| `notificationElementTargetElement` | `?string` | JS expression returning the target DOM element. |
| `notificationElementPosition` | `?int` | Icon position: 1=top-left, 2=top-right, 3=bottom-right, 4=bottom-left. |
| `language` | `?string` | UI language of the app. Values: `null` (follows the browser, falling back to English), `en`, `cs`, `sk`. |
| `theme` | `?string` | Light/dark mode for the app. Values: `null` (follows browser preference), `stromcom-light`, `stromcom-dark`. |
| `entityResolve` | `?string` | JS callback resolving business-entity detail (order, ticket…) for the message editor's chip hover-card. Receives `{type, id}`, returns (or resolves to) `{title, url?, fields: [{label, value}]}`. |

### UI language
Pass a language code to `snippet()` to force the widget UI language (`cs`, `en`, `sk`…). When omitted, the widget detects it from the browser, falling back to English.
Set the language on `ConfOptions`, the same way as the theme. When omitted, the widget detects it from the browser, falling back to English.
```php
echo $client->conf(new ConfOptions(language: 'cs'))->getHTML();
```
`snippet()` also takes a language code, which sets the initial value before `conf()` runs. Use it when the language is known at page render and you want the widget to boot into it without waiting for `conf()`; `ConfOptions::$language` wins whenever both are given.
```php
echo $client->snippet('cs')->getHTML();
```
Expand Down
11 changes: 11 additions & 0 deletions src/Options/ConfOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class ConfOptions extends SnippetOptions {
#[Docs('Callback invoked after the notification element is rendered', null, true, 'Function|null')]
private ?string $notificationElementAfterRender = null;

#[Docs('UI language of the app. Null follows the browser, falling back to English. Available: en, cs, sk', 'cs', true)]
private ?string $language = null;

#[Docs('Theme name applied to the host page via data-theme on <html>. Available: stromcom-default, stromcom-dark', 'stromcom-dark', true)]
private ?string $theme = null;

Expand All @@ -67,6 +70,9 @@ public function __construct(
?string $homeBeforeRender = null,
?string $theme = null,
?string $entityResolve = null,
// Appended last on purpose — inserting it next to $theme would shift the
// positional arguments of existing callers.
?string $language = null,
) {
$this->notificationRenderer = $notificationRenderer;
$this->onNotification = $onNotification;
Expand All @@ -80,6 +86,7 @@ public function __construct(
$this->notificationElementBeforeRender = $notificationElementBeforeRender;
$this->notificationElementAfterRender = $notificationElementAfterRender;
$this->homeBeforeRender = $homeBeforeRender;
$this->language = $language;
$this->theme = $theme;
$this->entityResolve = $entityResolve;
}
Expand Down Expand Up @@ -157,6 +164,10 @@ public function renderNotificationElementAfterRender(): ?JsValue {
return $this->wrapJsValue($this->notificationElementAfterRender);
}

public function getLanguage(): ?string {
return $this->language;
}

public function getTheme(): ?string {
return $this->theme;
}
Expand Down
2 changes: 2 additions & 0 deletions src/SnippetClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public function csp(): CspPolicy {
*
* @param string|null $language UI language (e.g. "cs", "en", "sk"). Null (default) lets the
* widget detect it from the browser, falling back to English.
* This is the initial value only — `ConfOptions::$language`
* overrides it and can be changed later at runtime.
*
* @throws SnippetGenerationException
*/
Expand Down
14 changes: 14 additions & 0 deletions tests/Options/ConfOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,20 @@ public function entity_resolve_null_renders_as_null(): void {
$this->assertNull($options->renderEntityResolve());
}

#[Test]
public function language_is_included_when_set(): void {
$options = new ConfOptions(language: 'cs');
$result = $options->getOptions();

$this->assertArrayHasKey('language', $result);
$this->assertSame('cs', $result['language']);
}

#[Test]
public function language_is_not_included_when_null(): void {
$this->assertArrayNotHasKey('language', (new ConfOptions())->getOptions());
}

#[Test]
public function get_options_with_docs_returns_all_property_schemas(): void {
$schema = ConfOptions::getOptionsWithDocs();
Expand Down
6 changes: 6 additions & 0 deletions tests/SnippetClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public function conf_output_contains_conf_call(): void {
$this->assertStringContainsString('stromCom.conf(', $code);
}

#[Test]
public function conf_output_contains_language(): void {
$code = $this->client->conf(new ConfOptions(language: 'cs'))->getCode();
$this->assertStringContainsString('"language": "cs"', $code);
}

#[Test]
public function conf_output_with_docs_contains_on_load(): void {
$code = $this->client->conf(new ConfOptions(), true)->getCode();
Expand Down