Thomas Calvet
Contributed by Thomas Calvet in #36016

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:

Interface in English

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:

Interface translated into Spanish

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:

Original Symfony Demo page

And this is the same page with pseudolocalization enabled:

Symfony Demo page with pseudolocalization enabled
Published in #Living on the edge