我有example.com网站,并希望对此进行解释。但我也希望默认语言是乌克兰语,因此url中没有语言环境参数。
url =>页面语言
example.com => ukrainian
example.com/ru => russian
example.com/en => english
example.com/add_new_post => ukrainian
example.com/ru/add_new_post => russian
example.com/en/add_new_post => english
example.com/ua
必须将您重定向到example.com/
或example.com
example.com/ua/add_new_post
必须将您重定向到example.com/add_new_post/
或example.com/add_new_post
我尝试像这样配置应用程序 app / config / services.yaml
parameters:
locale: ua
app_locales: '|ua|en|ru'
services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
bind:
$locales: '%app_locales%'
$defaultLocale: '%locale%'
app / config / packages / framework.yaml
framework:
secret: '%env(APP_SECRET)%'
default_locale: '%locale%'
app / config / packages / translation.yaml
framework:
default_locale: '%locale%'
translator:
default_path: '%kernel.project_dir%/translations'
fallbacks:
- en
app / config / routes / annotations.yaml
controllers:
resource: ../../src/Controller/
type: annotation
prefix: /{_locale}
requirements:
_locale: '%app_locales%'
defaults:
_locale: '%locale%'
kernel:
resource: ../../src/Kernel.php
type: annotation
但只能得到
example.com/ru
和example.com/en
,example.com/ru/add_new_post
和example.com/ru/add_new_post
的工作方式就像我想要的一样
example.com
和example.com/ua
在乌克兰语中是同一页面,
example.com/add_new_post
显示未找到路由错误,
example.com//add_new_post
使用乌克兰语。