UserFrosting 4.4 focuses on rewriting the Translator service and locale improvements.
The translator has been completely rewritten, focusing on optimization and better usability. All locales can now defines metadata and configuration options in a required locale.yaml
file. The current locale identifier (ie. en_US
or fr_FR
) can now be accessed from Twig template using the currentLocale
global variable.
A new Locale service is now available. It provides a list of available locales in diffeent form.
Finally, three new locale focused Bakery command are now available:
Services providers can now be defined in different files and semi-autoloaded for easier testing. See detailed document page for more info.
cli
service. Returns true if current app is a CLI envrionement, false otherwise.Interop\Container\ContainerInterface
has been replaced with Psr\Container\ContainerInterface
.\UserFrosting\I18n\MessageTranslator
is now \UserFrosting\I18n\Translator
.localePathBuilder
service has been removed. Tasks that used to be handled by this service are now handled by the locale
and translator
services.site.locales.available
config now accept (string) identifier => (bool) enabled
. Set identifier to false or null to remove it from the list.As of UserFrosting 4.4.0, support for PHP version 7.1 is officially deprecated as it has reached End Of Life. Support for PHP 7.1 will be removed in the next major version. PHP version 7.3 or higher is now recommended as official PHP 7.2 support will end in december 2020.
See the Changelog for the complete list of changes included in this release.
Upgrading UserFrosting to 4.4.x
is as simple as getting the new files and updating dependencies, migrations and assets! If you first installed UserFrosting using git, a simple git pull
or git pull upstream master
. Once you have the new files, simply use composer and Bakery to get up to date with everything else:
$ composer update
$ php bakery bake
Search for use Interop\Container\ContainerInterface;
and replace all instances with use Psr\Container\ContainerInterface;
.
container-interop/container-interop
in your sprinkle composer.json
to quickly reenable Interop
container interface. However, since container-interop/container-interop
is now deprecated, using Psr container is preferable.Previous version of Userfrostin allowed to define a "fallback" locale as the default one. For example:
'default' => 'en_US,fr_FR',
This meant the French language would be loaded first and if the requested key doesn't exist in French, it will try to use the English one instead.
Starting with 4.4.0, the fallback locale is now defined in the locale metadata. The default locale in your configuration file should be update to use a specific locale instead :
'default' => 'fr_FR',
The repository file 'locale://en_US,fr_FR/locale.yaml' could not be found.
The old configuration for available locale used to be an identifier => name
key/value pair :
'available' => [
'en_US' => 'English',
'zh_CN' => '中文',
'es_ES' => null', // Use null to disable locale
...
],
The new configuration are now an identifier => (bool) enabled
key/value pair :
'available' => [
'en_US' => true,
'zh_CN' => true,
'es_ES' => false, // False to disable locale
...
],
While both are compatible with eachother, it is now recommended all sprinkle be update to the new format. The locale name defined in the configuration will is not used anymore as it as been replaced by the locale config.
Custom locales (those not bundled by default with UserFrosting) needs to be updated with a new locale.yaml
file. See Custom locale for more information..
Search for UserFrosting\I18n\MessageTranslator
and replace all instances with UserFrosting\I18n\Translator
. The translate
method in Translator and MessageTranslator are compatible with each other.
If your sprinkle has PHPUnit tests, you may need to update them. The methods listed below now have a void
return type declaration:
PHPUnit\Framework\TestCase::setUp()
PHPUnit\Framework\TestCase::tearDown()
Your implementations of the methods listed above now must be declared void, too, otherwise you will get a compiler error.
public function setUp(): void
{
parent::setUp();
// Do stuff
// ...
}
public function tearDown(): void
{
parent::tearDown();
// Do stuff
// ...
}
See PHPUnit 8 Announcement page for more details.