Sulu CMS-更改默认的网站提供商
我需要根据浏览器语言和IP地址打开网站的语言版本。 我正在尝试按照文档中建议的方式使用我的网站提供商。我将requestDefaultLocaleprovider.php复制到src文件夹,重命名并将其注册为Services.yaml的服务,然后将其ID插入sulu_website.yaml。 当我打开网站方法时,我的提供商中没有调用“ getDefaultLocale”,我无法打开所需的网站版本。我在做什么错?
services.yaml
app.locale.my_locale_provider:
class: App\Locale\MyLocaleProvider
arguments:
- '@Sulu\Component\Webspace\Analyzer\RequestAnalyzerInterface'
- '@Symfony\Component\HttpFoundation\RequestStack'
sulu_website.yaml
sulu_website:
twig:
attributes:
urls: false
path: false
default_locale:
provider_service_id: app.locale.my_locale_provider
mylocaleprovider.php
namespace App\Locale;
use Sulu\Bundle\WebsiteBundle\Locale\DefaultLocaleProviderInterface;
class MyLocaleProvider implements DefaultLocaleProviderInterface
{
public function __construct()
{
dump("from constructor") ;
}
public function getDefaultLocale()
{
dump("from getDefaultLocale") ;
return 'de';
}
}
我也尝试使用推荐的方法symfony(订阅onkernelrequest事件,并在$ request-setlocale()方法中设置我需要的语言
I need to open the language version of the site according to the browser language and IP address.
I'm trying to use my Locale Provider as suggested in the documentation.I copy the RequestDefaultLocaleProvider.php to src folder, rename and registered it as a service in services.yaml and insert his ID to sulu_website.yaml.
When I open the site method "getDefaultLocale" in my provider is not called and I can't open the desired version of the site. What am i doing wrong?
services.yaml
app.locale.my_locale_provider:
class: App\Locale\MyLocaleProvider
arguments:
- '@Sulu\Component\Webspace\Analyzer\RequestAnalyzerInterface'
- '@Symfony\Component\HttpFoundation\RequestStack'
sulu_website.yaml
sulu_website:
twig:
attributes:
urls: false
path: false
default_locale:
provider_service_id: app.locale.my_locale_provider
MyLocaleProvider.php
namespace App\Locale;
use Sulu\Bundle\WebsiteBundle\Locale\DefaultLocaleProviderInterface;
class MyLocaleProvider implements DefaultLocaleProviderInterface
{
public function __construct()
{
dump("from constructor") ;
}
public function getDefaultLocale()
{
dump("from getDefaultLocale") ;
return 'de';
}
}
I also tried to use the recommended approach Symfony (subscribe to the onKernelRequest event and set the language I need in $request->setLocale() method but this also did not work)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅当您在网络空间中使用以下URL架构时,仅考虑默认场所提供商:
因此,如果您有EG
sulu.rocks/en
和sulu.rocks/de
有人在调用sulu.rocks/
默认的环境提供商被调用并重定向,然后用户提供的语言。如果您要在Web空间的
rootlevel
上运行一个语言环境,则默认环境提供程序将不会被调用,因为它是AlreaThe default locale provider is only taken into account when you are using the following url schema in your webspace:
So if you have e.g.
sulu.rocks/en
andsulu.rocks/de
and somebody is callingsulu.rocks/
the default locale provider is called and redirect then the user provided language.If you are running a locale on the
rootLevel
of your webspace, the default locale provider will not be called as it is alrea解决了问题,我的错误是我期望在我的ISP中执行GetDefaultLocale()方法,但是释放了与Sulu.rocks/ {language}的重定向,并且在那里未执行GetDefaultLocale()。
The problem is solved, my mistake was that I expected the getDefaultLocale() method to be executed in my ISP, but a redirect to sulu.rocks/{language} was released and getDefaultLocale () was not executed there.