DoDomuDojade Documentation

LanguageTranslator
in package
implements Translator

FinalYes

Table of Contents

Interfaces

Translator

Properties

$cache  : array<string|int, mixed>
$context  : LocaleContext
$defaultLocale  : string
$translationsPath  : string

Methods

__construct()  : mixed
translate()  : string
Translate a key with optional parameters
getNestedValue()  : string|null
Get nested array value using dot notation
loadMessages()  : array<string|int, mixed>
Load messages for a specific locale Caches result to avoid re-reading files

Properties

Methods

__construct()

public __construct(LocaleContext $context[, string $translationsPath = __DIR__ . '/../../../resources/lang/' ]) : mixed
Parameters
$context : LocaleContext
$translationsPath : string = __DIR__ . '/../../../resources/lang/'

translate()

Translate a key with optional parameters

public translate(string $key[, array<string|int, mixed> $params = [] ]) : string

Examples:

  • trans('auth.invalid_credentials')
  • trans('announcement.not_found')
  • trans('errors.database.connection', ['host' => 'localhost'])
Parameters
$key : string

Dot-notation key (e.g., 'auth.invalid_credentials')

$params : array<string|int, mixed> = []

Parameters to interpolate in the message

Return values
string

Translated message

getNestedValue()

Get nested array value using dot notation

private getNestedValue(array<string|int, mixed> $array, string $key) : string|null

Examples:

  • getNestedValue(['auth' => ['invalid' => 'msg']], 'auth.invalid') → 'msg'
  • getNestedValue(['auth' => [...]], 'auth.missing') → null
Parameters
$array : array<string|int, mixed>

Array to search

$key : string

Dot-notation key (e.g., 'auth.invalid_credentials')

Return values
string|null

loadMessages()

Load messages for a specific locale Caches result to avoid re-reading files

private loadMessages(string $locale) : array<string|int, mixed>
Parameters
$locale : string

Locale code (e.g., 'en', 'pl')

Return values
array<string|int, mixed>

Translation array


        
On this page

Search results