# getLocale

Learn how to provide the visitor's preferred locale.

An implementation must return the visitor's preferred locale, or `null` when none can be determined.

## Signature

This method has the following signature:

```php
public function getLocale(): ?string
```

This method returns the visitor's preferred locale, or `null` when none can be determined.

## Example

This example resolves the locale from the application's localization service:

```php
<?php
use Croct\Plug\LocaleResolver;

final class AppLocaleResolver implements LocaleResolver
{
    private Translator $translator;

    public function __construct(Translator $translator)
    {
        $this->translator = $translator;
    }

    public function getLocale(): ?string
    {
        return $this->translator->getLocale();
    }
}
```
