New in Symfony 5.2: Pseudo-localization translator
September 21, 2020 • Published by Javier Eguiluz
Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
Symfony 5.2 will be released in November 2020. This is the first article of the series that shows the most important new features introduced by this Symfony version.
The following image shows the main menu of the interface of a popular Internet service:
This other image shows the same menu when the user switches the language to Spanish. Unexpectedly, some text is cut and other contents are so long that they overflow and you can't see them:
These kind of errors are very common, because different languages can be longer or shorter than the original application language. Another common issue is to only check if the application works when using basic accented letters, instead of checking for more complex characters such as the ones found in Polish, Czech, etc.
These problems can be solved with pseudolocalization, a software testing method used for testing internationalization. In this method, instead of translating the text of the software into a foreign language, the textual elements of an application are replaced with an altered version of the original language.
For example, Account Settings
is translated as [!!! Àççôûñţ Šéţţîñĝš !!!]
.
First, the original text is expanded in length with characters like [!!! !!!]
to test the application when using languages more verbose than the original one.
This solves the first problem.
In addition, the original characters are replaced by similar but accented characters. This makes the text highly readable, while allowing to test the application with all kinds of accented and special characters. This solves the second problem.
In Symfony 5.2 we've added full support for pseudolocalization to help you debug internationalization issues in your applications. You can enable and configure it in the translator configuration:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# config/packages/translator.yaml
framework:
translator:
# ...
pseudo_localization:
# replace characters by their accented version
accents: true
# wrap strings with brackets
brackets: true
# controls how many extra characters are added to make text longer
expansion_factor: 1.4
# maintain the original HTML tags of the translated contents
parse_html: true
# also translate the contents of these HTML attributes
localizable_html_attributes: ['title']
That's all. The application will now start displaying those strange, but readable, contents to help you internationalize it. See for example the difference in the Symfony Demo application. This is the original page:
And this is the same page with pseudolocalization enabled:
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
Great work 🎉 :)
This is really wierd, but surprisingly reasonable solution.
Another idea for extending the words: Insert a thin nonbrekable space between characters. "I t w i l l l o o k l i k e t h i s."