Skip to content

Translator contract is not respected by the blade complier #23162

@jeanmonod

Description

@jeanmonod
  • Laravel Version: v5.5.32
  • PHP Version: all

Description:

Here:

return "<?php echo app('translator')->getFromJson{$expression}; ?>";
The blade compiler is bypassing the translator interface. Ihmo it should call trans() instead of getFromJson

Steps To Reproduce:

Implement our own Translator service following the official interface:

use Illuminate\Contracts\Translation\Translator as TranslatorContract;
class Translator implements TranslatorContract
{
    public function trans($key, array $replace = [], $locale = null) { ... }
    public function transChoice($key, $number, array $replace = [], $locale = null) { ... }
    public function getLocale() { ... }
    public function setLocale($locale) { ... }
}

Start to use it and get the following error:

Call to undefined method MyProject\Libraries\Translation\Translator::getFromJson() (View: /vagrant/resources/views/components/my-block.blade.php)

Disclamer

I'm just starting to use Laravel, so I may be wrong. All my apologies if it's the case

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions