未加星标

New in Symfony 4.2: Translation related improvements

字体大小 | |
[开发(php) 所属分类 开发(php) | 发布者 店小二05 | 时间 2018 | 作者 红领巾 ] 0人收藏点击收藏
Fallback for internationalized routes

Contributed by

Thomas Calvet in #27957 .

In complex internationalized apps it's common to define different contents for each regional locale (e.g. en_GB for British English and en_US for American English). However, routes (or at least some of them) could be the same for all regions, so it's cumbersome to define duplicated routes:

use Symfony\Component\Routing\Annotation\Route; /** * @Route({ "en_GB": "/about-us", "en_US": "/about-us" }, name="about") */ public function about() { // ... }

In Symfony 4.2 you can define internationalized routes without the region part and Symfony will match them ignoring the region part of the locale:

/** * @Route({ "en": "/about-us" }, name="about") */ public function about() { // ... }

In this example, both en_GB and en_US will match the en route.

ICU parent locales as fallback locales

Contributed by

Chris Wilkinson in #28070 .

Currently, when some content is not found for some locale (e.g. es_AR for Argentinian Spanish) Symfony uses the region-less locale ( es in this case) as the fallback locale.

However, the ICU project defines "parent locales" for some languages (English, French, Spanish, Portuguese, etc.) In Symfony 4.2 we now use those parents as the first fallback locale. The previous example will now work as follows:

es_AR es_419 es

Identity translator as fallback

Contributed by

Yonel Ceruto in #28523 .

When using certain features of Symfony Forms in an application that hasn't installed the Translation component you may find errors like "The helper "translator" is not defined" .

In Symfony 4.2 we've added an "identity translator" helper which acts as fallback when the Translation component is not installed. This identity translator doesn't actually translate anything and it just returns the given content.

Update XLF translations by default
New in Symfony 4.2: Translation related improvements

Contributed by

Alexis Boyer in #27935 .

XLIFF is officially recommended by Symfony as the format to use for your translations. That's why in Symfony 4.2 the translation:update command has changed the default value of its output-format option from yml to xlf .

It's a minor change, but it will save you from typing --output-format=xlf when running this command.

Lint multiple XLIFF dirs or files

Contributed by

Yonel Ceruto in #28522 .

The lint:xliff command has also improved in Symfony 4.2 to support linting multiple directories and files at once.

Moreover, the command is now much faster to execute because the validation is done using local XSD files. This will solve the timeout problems you may have found in the past.

$ ./bin/console lint:xliff translations/messages.en.xlf translations/messages.es.xlf $ ./bin/console lint:xliff translations/ legacy_translations/ data/translations/messages.en.xlf

本文开发(php)相关术语:php代码审计工具 php开发工程师 移动开发者大会 移动互联网开发 web开发工程师 软件开发流程 软件开发工程师

分页:12
转载请注明
本文标题:New in Symfony 4.2: Translation related improvements
本站链接:https://www.codesec.net/view/611835.html


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 开发(php) | 评论(0) | 阅读(12)