首页 > 解决方案 > Laravel 5.6 无法翻译内容

问题描述

我想在主文件以外的另一个文件中使用翻译(我有一些内容的文件,并且该文件由主文件扩展),但它不起作用。你知道有人为什么吗?theme_url('path') 也存在同样的问题。

在主文件中我有:

@php
    App::setLocale('en');
    Theme::Set('mobile');
@endphp
head...
<body>
    @yield('content')
</body>

并在扩展文件中:

@extends('main file')

@section('content')
    <img src="{{ theme_url('img/logo.png') }}">
    <span>{{ __('lang.title') }}</span>
@endsection

当我用@include 替换@yield('content') 时,一切都会正常工作(使用作者igaster 切换主题)

标签: phplaravelthemestranslate

解决方案


我认为问题在于

@extends('main file')

@section('content')
    <img src="{{ theme_url('img/logo.png') }}">
    <span>{{ __('lang.title') }}</span>
@endsection

此代码首先执行,然后放入主文件中,因此在此文件中语言环境不是“en”

试试这个

@extends('main file')

App::setLocale('en');
Theme::Set('mobile');

@section('content')
    <img src="{{ theme_url('img/logo.png') }}">
    <span>{{ __('lang.title') }}</span>
@endsection

推荐阅读