Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Fajar's avatar
Level 2

installation fresh laravel

hey guys I did a new installation for the laravel project with version 5.7.

composer create-project --prefer-dist laravel/laravel newprojek "5.7.*"

after I finished configuring I tried to access the project and get a message like this

Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN)
Declaration of Symfony\Component\Translation\TranslatorInterface::setLocale($locale) must be compatible with Symfony\Contracts\Translation\LocaleAwareInterface::setLocale(string $locale)

this is my first time getting this error message thanks

0 likes
13 replies
Fajar's avatar
Level 2

@crnkovic I have tried first I delete this section

 public function setLocale(string $locale);

to 

 public function setLocale();

and i get error again i try to delete

public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null);

to

public function trans();

not fix for me is there something wrong with my stage?

Fajar's avatar
Fajar
OP
Best Answer
Level 2

thx all i fix this with

check composer.json on Symfony/translation-contracts/

and i change

"require": {
        "php": "^7.2.9"
    },

to

"require": {
        "php": "^7.1.3"
    },

and i add

"symfony/translation-contracts": "^1.1.6"

to composer.json

and i run command composer update refresh projek and done

5 likes
Fajar's avatar
Level 2

@shaikh709

really, if it really works for you, I'm happy to be able to help you :)

hadifox's avatar

where do you add this :

"symfony/translation-contracts": "^1.1.6"

==

{ "name": "symfony/translation-contracts", "type": "library", "description": "Generic abstractions related to translation", "keywords": ["abstractions", "contracts", "decoupling", "interfaces", "interoperability", "standards"], "homepage": "https://symfony.com", "license": "MIT", "authors": [ { "name": "Nicolas Grekas", "email": "[email protected]" }, { "name": "Symfony Community", "homepage": "https://symfony.com/contributors" } ], "require": { "php": "^7.2.5" }, "suggest": { "symfony/translation-implementation": "" }, "autoload": { "psr-4": { "Symfony\Contracts\Translation\": "" } }, "minimum-stability": "dev", "extra": { "branch-alias": { "dev-master": "2.0-dev" } } }

==

Fajar's avatar
Level 2

@hadifox i add in.

for example my project is blog

and i add 
"symfony/translation-contracts": "^1.1.6"
in 
blog
    -composer.json

here

"license": "MIT",
    "require": {
        "php": "^7.1.3",
        "fideloper/proxy": "^4.0",
        "laracasts/flash": "^3.0",
        "laravel/framework": "5.7.*",
        "laravel/tinker": "^1.0",
        "symfony/translation-contracts": "^1.1.6"
    },

full composer.json

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.1.3",
        "fideloper/proxy": "^4.0",
        "laracasts/flash": "^3.0",
        "laravel/framework": "5.7.*",
        "laravel/tinker": "^1.0",
        "symfony/translation-contracts": "^1.1.6"
    },
    "require-dev": {
        "beyondcode/laravel-dump-server": "^1.0",
        "filp/whoops": "^2.0",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^2.0",
        "phpunit/phpunit": "^7.0"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}

thx

Fajar's avatar
Level 2

@hadifox

go to youre project

for example project name WebApp

find folder vendor/symfony/translation-contracts/composer.json

and find line "symfony/translation-contracts":  change to "symfony/translation-contracts": "^1.1.6"

and now go to TranslatorInterface.php 
change to 
public function trans($id, array $parameters = [], $domain = null, $locale = null);

and go to  TranslatorTrait.php
change to
public function setLocale($locale);

and run composer update

thx

kosar's avatar

@fajar i did the same but "composer update" didn't work for me ... so I ran "composer update --ignore-platform-reqs" and it was okay...tnx

Please or to participate in this conversation.