简体   繁体   English

多租户应用程序的不同翻译

[英]Different translations for multi-tenant applications

I'm developing a multi-tenant application where I'm using the same codebase for two different websites, each available in two languages.我正在开发一个多租户应用程序,其中我为两个不同的网站使用相同的代码库,每个网站都有两种语言。

  • Website A FR网站 A FR
  • Website A EN网站 A CN
  • Website B FR网站 B FR
  • Website B EN网站 B EN

Laravel allows you to store the localization translations in the resources/lang directory, under a different folder for each language (in this case one fr folder and one en folder). Laravel 允许您将本地化翻译存储在resources/lang目录中,在每种语言的不同文件夹下(在这种情况下,一个fr文件夹和一个en文件夹)。

This works well, but there are some strings that need to be translated differently depending on the current tenant.这很有效,但有一些字符串需要根据当前租户的不同进行不同的翻译。 On website A, the "Home" button link might be called "Home" and on website B it would be called "Go to Home".在网站 A 上,“主页”按钮链接可能被称为“主页”,而在网站 B 上,它可能被称为“转到主页”。

How can I specify different translations files for different tenants?如何为不同的租户指定不同的翻译文件?

I tried doing something like this :我尝试做这样的事情:

/ ressources
  / lang
    / fr
      / tenantA
        - messages.php
      / tenantB
        - messages.php
    /en
      /tenantA
        - messages.php
      /tenantB
         - messages.php

Then, I set the locale globally in a service provider :然后,我在服务提供者中全局设置语言环境:

App::setLocale('en');

I then try to load the proper translation from my view :然后我尝试从我的角度加载正确的翻译:

{{ __('tenantA.messages.home') }}

This does not work however, it only echo's out tenantA.messages.home (the literal string) instead of the translation that is contained in the messages.php file, under the home key.然而,这不起作用,它只回显了tenantA.messages.home (文字字符串)而不是包含在home键下的messages.php文件中的翻译。

How can I fix this?我怎样才能解决这个问题? Is there a better way to do this?有一个更好的方法吗?

It doesn't work with sub-directories using .它不工作的sub-directories使用. but it'll work with a / , so for example, you may try it the following way (tested on v-5.4 ):但它可以与/一起使用,因此例如,您可以按以下方式尝试(在v-5.4上测试):

{{ __('tenantA/messages.home') }}

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

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