简体   繁体   English

在Laravel中覆盖包本地化

[英]Override package localization in Laravel

It should be "trivial", but after some chating on #laravel irc channel, I found it may be impossible for now. 它应该是“微不足道的”,但是在对#laravel irc频道进行一些讨论之后,我发现它现在可能是不可能的。 But I'll ask it here before doing it the ugly-go-horse way just to have the project done. 但是我会在这之前问这个丑陋的马,只是为了让项目完成。 If it's indeed impossible by current means, I'll fill a request on github (after handing over the project to my client). 如果通过当前方式确实不可能,我将在github上填写请求(在将项目交给我的客户之后)。

I'm using Zizaco\\Confide to handle authentication in my service. 我正在使用Zizaco\\Confide来处理我的服务中的身份验证。 It uses Laravel Lang everywhere to get strings in one of the 8 bundled languages of the package. 它使用Laravel Lang到处获取包的8种捆绑语言之一的字符串。 But I need to override some of those strings, and I don't want to modify the package files (which would defeat the whole purpose of Composer). 但我需要覆盖其中一些字符串,我不想修改包文件(这会破坏Composer的整个目的)。 How can I do this? 我怎样才能做到这一点?

For example, I needed to modify confide::confide.alerts.wrong_credentials for pt_BR language. 例如,我需要为pt_BR语言修改confide::confide.alerts.wrong_credentials What I tried so far: 到目前为止我尝试了什么:

  • /app/lang/pt_BR/confide.php file, with contents return array('alerts' => array('wrong_credentials' => '...')) . /app/lang/pt_BR/confide.php文件,内容return array('alerts' => array('wrong_credentials' => '...')) It works for Lang::get('confide.alerts.wrong_credentials') but not for the namespaced Lang::get('confide::confide.alerts.wrong_credentials') 它适用于Lang::get('confide.alerts.wrong_credentials')但不适用于命名空间Lang::get('confide::confide.alerts.wrong_credentials')
  • /app/lang/pt_BR/packages/zizaco/confide/confide.php with return array('alerts' => ......) /app/lang/pt_BR/packages/zizaco/confide/confide.php带有return array('alerts' => ......) /app/lang/pt_BR/packages/zizaco/confide/confide.php return array('alerts' => ......)
  • /app/lang/pt_BR/packages/zizaco/confide/confide/alerts.php with return array('wrong_credentials' => ...) /app/lang/pt_BR/packages/zizaco/confide/confide/alerts.php带有return array('wrong_credentials' => ...)
  • /app/lang/packages/zizaco/confide/pt_BR/confide.php with array('alerts' => array('wrong_credentials' => '...')) - /app/lang/packages/zizaco/confide/pt_BR/confide/alerts.php with return array('wrong_credentials' => ...) /app/lang/packages/zizaco/confide/pt_BR/confide.php with array('alerts' => array('wrong_credentials' => '...')) /app/lang/packages/zizaco/confide/pt_BR/confide.php array('alerts' => array('wrong_credentials' => '...')) - /app/lang/packages/zizaco/confide/pt_BR/confide/alerts.php带有return array('wrong_credentials' => ...) /app/lang/packages/zizaco/confide/pt_BR/confide/alerts.php return array('wrong_credentials' => ...)

Any clue on what am I missing? 关于我缺少什么的任何线索? Or does Laravel4 really lacks this feature? 或者Laravel4真的缺少这个功能吗?

Thanks in advance! 提前致谢!

actually it fixed in Laravel 4.1 core 实际上它固定在Laravel 4.1核心

you can now overwrite it by doing 你现在可以通过这样做来覆盖它

app/lang/packages/(locale)/confide/confide.php

check this 检查一下

laravel 4 language issue laravel 4语言问题

correct path for overriding package languages 覆盖包语言的正确路径

So, as for today, Laravel really does lack this feature. 所以,就目前而言,Laravel确实缺乏此功能。 I've asked for it creating a issue on github . 我已经要求它在github上创建一个问题

Meanwhile, this functionality could be achieved seamlessly using crynobone's Orchestra Platform 2 Translation Component, which can be found here 同时,可以使用crynobone的Orchestra Platform 2 Translation Component 无缝地实现此功能,该组件可在此处找到

All you need to do is require it in composer.json 所有你需要做的就是require它在composer.json

{
    "require": {
        "orchestra/translation": "2.0.*"
    }
}

and replace the original translation package ( 'Illuminate\\Translation\\TranslationServiceProvider' ) in /config/app.php 并替换/config/app.php的原始翻译包( 'Illuminate\\Translation\\TranslationServiceProvider'

'providers' => array(
    //'Illuminate\Translation\TranslationServiceProvider',
    // ...
    'Orchestra\Translation\TranslationServiceProvider',
),

That's it! 而已! Now, having app/lang/en/packages/confide/confide.php will do it! 现在,有了app/lang/en/packages/confide/confide.php就可以了! (please note that the path should be /packages/ packagename /, not /packages/vendor/packagename/ (请注意路径应该是/ packages / packagename /,而不是/ packages / vendor / packagename /

It really saved me from a big headache, hope others find this useful too. 它真的让我免于头痛,希望其他人也觉得这很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM