final class FluentTranslator implements Translator (View source)

Translator decorator that adds support for Fluent translations.

This class is adapted from the laravel-fluent package. This version of the class adds support for:

  • Loading namespaced translations from .ftl files, and allowing them to be overridden by the consumer.
  • Adding functions to FluentBundle instances.
  • Accept an array of keys and use the first one that exists.
  • Cache parsed Fluent bundles.

Methods

__construct(Translator $baseTranslator, Filesystem $files, string $path, string $locale, string $fallback, array $bundleOptions, string|null $cachePath = null, array $functions = [])

No description

bool
hasForLocale(string $key, string|null $locale = null)

No description

bool
has(string $key, string|null $locale = null, bool $fallback = true)

No description

string|array
get(string|array $key, array $replace = [], ?string $locale = null, bool $fallback = true)

No description

FluentBundle|false
loadPath(string $path, string $locale, string $group)

No description

void
flush()

No description

FluentBundle|false
loadNamespaced(string $locale, string $group, string $namespace)

No description

FluentBundle
loadNamespaceOverrides(FluentBundle $bundle, $locale, $group, $namespace)

No description

choice($key, $number, array $replace = [], $locale = null)

No description

void
addLines(array $lines, string $locale, string $namespace = '*')

No description

void
load(string $namespace, string $group, string $locale)

No description

void
addNamespace(string $namespace, string $hint)

No description

void
addJsonPath(string $path)

No description

array
parseKey(string $key)

No description

MessageSelector
getSelector()

No description

void
setSelector(MessageSelector $selector)

No description

Loader
getLoader()

No description

string
locale()

No description

string
getLocale()

No description

void
setLocale(string $locale)

No description

string
getFallback()

No description

void
setFallback(string $locale)

No description

Details

__construct(Translator $baseTranslator, Filesystem $files, string $path, string $locale, string $fallback, array $bundleOptions, string|null $cachePath = null, array $functions = [])

No description

Parameters

Translator $baseTranslator
Filesystem $files
string $path
string $locale
string $fallback
array $bundleOptions
string|null $cachePath
array $functions

bool hasForLocale(string $key, string|null $locale = null)

No description

Parameters

string $key
string|null $locale

Return Value

bool

bool has(string $key, string|null $locale = null, bool $fallback = true)

No description

Parameters

string $key
string|null $locale
bool $fallback

Return Value

bool

string|array get(string|array $key, array $replace = [], ?string $locale = null, bool $fallback = true)

No description

Parameters

string|array $key
array $replace
?string $locale
bool $fallback

Return Value

string|array

protected FluentBundle|false loadPath(string $path, string $locale, string $group)

No description

Parameters

string $path
string $locale
string $group

Return Value

FluentBundle|false

void flush()

No description

Return Value

void

protected FluentBundle|false loadNamespaced(string $locale, string $group, string $namespace)

No description

Parameters

string $locale
string $group
string $namespace

Return Value

FluentBundle|false

protected FluentBundle loadNamespaceOverrides(FluentBundle $bundle, $locale, $group, $namespace)

No description

Parameters

FluentBundle $bundle
$locale
$group
$namespace

Return Value

FluentBundle

choice($key, $number, array $replace = [], $locale = null)

No description

Parameters

$key
$number
array $replace
$locale

void addLines(array $lines, string $locale, string $namespace = '*')

No description

Parameters

array $lines
string $locale
string $namespace

Return Value

void

void load(string $namespace, string $group, string $locale)

No description

Parameters

string $namespace
string $group
string $locale

Return Value

void

void addNamespace(string $namespace, string $hint)

No description

Parameters

string $namespace
string $hint

Return Value

void

void addJsonPath(string $path)

No description

Parameters

string $path

Return Value

void

array parseKey(string $key)

No description

Parameters

string $key

Return Value

array

MessageSelector getSelector()

No description

Return Value

MessageSelector

void setSelector(MessageSelector $selector)

No description

Parameters

MessageSelector $selector

Return Value

void

Loader getLoader()

No description

Return Value

Loader

string locale()

No description

Return Value

string

string getLocale()

No description

Return Value

string

void setLocale(string $locale)

No description

Parameters

string $locale

Return Value

void

string getFallback()

No description

Return Value

string

void setFallback(string $locale)

No description

Parameters

string $locale

Return Value

void