- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我尝试扩展一个 Illuminate 类翻译器
我创建了一个类并扩展到翻译器然后我将这一行添加到我的 RepositoryServiceProvider
$this->app->bind(\Illuminate\Translation\Translator::class, \App\Repositories\Translation\TranslationTranslator::class);
但它不起作用
我做错了什么?
类如下
<?php
namespace App\Repositories\Translation;
use Countable;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Collection;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Support\NamespacedItemResolver;
use Symfony\Component\Translation\MessageSelector;
use Symfony\Component\Translation\TranslatorInterface;
class TranslationTranslator extends \Illuminate\Translation\Translator
{
/**
* Parse a key into namespace, group, and item.
*
* @param string $key
* @return array
*/
public function parseKey($key)
{
\Log::info('got in');
die;
$segments = parent::parseKey($key);
if (is_null($segments[0])) {
$segments[0] = @explode('.', $segments[2])[0];
}
if ($segments[1] == 'translatable') {
$segments[1] = @explode('.', $segments[2])[0] . '_' . @explode('.', $segments[2])[1];
}
return $segments;
}
}
更新
显然 Translator 类有一个构造函数
public function __construct(LoaderInterface $loader, $locale)
{
$this->loader = $loader;
$this->locale = $locale;
}
所以我的绑定(bind)必须通过接口(interface)..无法实例化
public function boot()
{
$app = $this->app;
$this->app->bind(\Illuminate\Translation\Translator::class, function() use ($app){
return $app->make(\App\Repositories\Translation\TranslationTranslator::class);
});
}
出现这个错误
Illuminate\Contracts\Container\BindingResolutionException with message 'Target [Illuminate\Translation\LoaderInterface] is not instantiable while building [App\Repositories\Translation\TranslationTranslator].'
最佳答案
您可以使用闭包来解析类
$this->app->bind(\Illuminate\Translation\Translator::class, function(){
return new \App\Repositories\Translation\TranslationTranslator;
});
其次翻译器在使用翻译器
别名时与laravel绑定(bind)。
您也可以覆盖它。
$this->app->bind('translator', function(){
return new \App\Repositories\Translation\TranslationTranslator;
})
关于php - Laravel 扩展供应商类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52312759/
Java 文档说 CompletableFuture:supplyAsync(Supplier supplier)在 ForkJoinPool#commonPool() 中运行任务而 Completa
我正在尝试设置 IVR,或者更具体地说是使用 Asterisk 的自动接线员。除了简单的自动菜单系统之外,我不想要任何花哨的东西,而不是调用分机(现在),如果按下 1,只需调用同一条电话线 (POTS
当我尝试从 Symfony2 项目根运行以下命令时 php bin/vendors install 我收到以下错误: Could not open input file: bin/vendors 我对
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 9 年前。 Improve
我正在开发一个涉及用户位置检测的 Android 应用程序。我想知道的是,这个 -> LocationManager.GPS_PROVIDER 是如何工作的? 它是使用手机中的 GPS 系统还是使用移
我不知道如何编写代码以在可能的情况下选择网络提供商,或者如果网络不可用则选择 GPS 提供商。我怎样才能改变代码来得到这个。这是我的第一个 Android 应用程序,我尝试这样做但没有成功。 pack
我不是 MySQL 专家,我必须为我的水平设计一个相当复杂的数据库。 我现在面临的问题在于同一个表(公司的宏观类别)中存在供应商-客户关系: 宏表 id name mega_i
我希望至少有人能在这里为我指明正确的方向。 我的业务需要开放式身份验证。 但是,不要使用其他服务,如facebook 或 google 等。 我们有一个成员(member)数据库 - 一个标准的 as
如果我需要一个变量的 ThreadLocal,是否还需要使用 Supplier(也是线程安全的)? 例如,Supplier 是否不需要在这里实现线程安全? private ThreadLocal> m
我在 brunch@1.7.6 没有编译 bower_component css 文件时遇到问题。类似于 Separating app and vendor css in Brunch .只有 css
我正在使用 select2在 angular 项目中(使用自耕农)。 Select2 css 位于以下目录中: bower_components/select2/select2.css bower_c
在我的 Rails 应用程序目录中,vendor/plugins 和 vendor/assets/stylesheets 存在(两者都是空的)。我想创建 javascripts 文件夹。我可以手动创建
我的代码 fragment 是: mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if
我继承了一个 Hadoop 安装,我很想知道以前的管理员是如何安装它的,它是从哪里来的。我是 Hadoop 的新手,但似乎以前的管理员简单地从源代码安装了 Apache Hadoop(而不是使用 Cl
我是 Ionic 2 的新手,正在尝试学习所有介绍如何添加提供程序的在线教程。 Ionic 似乎更改了生成的应用程序结构。有人可以给我一个例子,说明如何使用当前的 Ionic 2 应用程序结构执行此操
为什么供应商只支持无参数构造函数? 如果存在默认构造函数,我可以这样做: create(Foo::new) 但是如果唯一的构造函数需要一个字符串,我必须这样做: create(() -> new Fo
我已经通过 docker-compose 构建了一个容器,这里是 .yml: gateway: build: . image: sng container_name: sn
虽然不是直接的编程问题,但我想我可以在这里找到最佳答案。 为什么 USB-IF 监管供应商 ID 的使用并出售它们? 想要编写开源驱动程序的人或想要 2,000 美元会产生巨大影响的小公司会发生什
我正在使用 laravel-analytics ( https://github.com/spatie/laravel-analytics/ ) 并已在本地安装了所有内容,工作正常。 但是,每当我尝试
有没有一种方法/测试工作流程 - 如果我想从 gui 读取字符串内容并将其放入 ArrayList 中,然后将其写入 .xlsx 文件并使用该文件作为数据提供程序。如果是的话,我可以获得它的@test
我是一名优秀的程序员,十分优秀!