Skip to content

Commit 1289103

Browse files
committed
Merge branch '5.4' into 6.2
* 5.4: [Translation] Add docs for pseudolocalization translator
2 parents c613d80 + 90f84ec commit 1289103

File tree

6 files changed

+134
-2
lines changed

6 files changed

+134
-2
lines changed
Loading
Loading
Loading
Loading

reference/configuration/framework.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. _framework-bundle-configuration:
1+
nsl.. _framework-bundle-configuration:
22

33
Framework Configuration Reference (FrameworkBundle)
44
===================================================
@@ -25,7 +25,7 @@ Configuration
2525
-------------
2626

2727
.. _configuration-framework-secret:
28-
28+
a
2929
secret
3030
~~~~~~
3131

translation.rst

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,136 @@ adapted to the format required by GitHub, but you can force that format too:
13121312
13131313
$ php vendor/bin/yaml-lint translations/
13141314
1315+
Pseudo-localization translator
1316+
------------------------------
1317+
1318+
.. versionadded:: 5.2
1319+
1320+
The pseudolocalization translator was introduced in Symfony 5.2.
1321+
1322+
.. note::
1323+
1324+
The pseudolocalization translator is meant to be used for development only.
1325+
1326+
The following image shows the main menu of the interface of a popular Internet
1327+
service:
1328+
1329+
.. image:: /_images/translation/pseudolocalization-interface-original.png
1330+
1331+
This other image shows the same menu when the user switches the language to
1332+
Spanish. Unexpectedly, some text is cut and other contents are so long that
1333+
they overflow and you can't see them:
1334+
1335+
.. image:: /_images/translation/pseudolocalization-interface-translated.png
1336+
1337+
These kind of errors are very common, because different languages can be longer
1338+
or shorter than the original application language. Another common issue is to
1339+
only check if the application works when using basic accented letters, instead
1340+
of checking for more complex characters such as the ones found in Polish,
1341+
Czech, etc.
1342+
1343+
These problems can be solved with `pseudolocalization`_, a software testing method
1344+
used for testing internationalization. In this method, instead of translating
1345+
the text of the software into a foreign language, the textual elements of an
1346+
application are replaced with an altered version of the original language.
1347+
1348+
For example, ``Account Settings`` is *translated* as ``[!!! Àççôûñţ
1349+
Šéţţîñĝš !!!]``. First, the original text is expanded in length with characters
1350+
like ``[!!! !!!]`` to test the application when using languages more verbose
1351+
than the original one. This solves the first problem.
1352+
1353+
In addition, the original characters are replaced by similar but accented
1354+
characters. This makes the text highly readable, while allowing to test the
1355+
application with all kinds of accented and special characters. This solves the
1356+
second problem.
1357+
1358+
Full support for pseudolocalization was added to help you debug
1359+
internationalization issues in your applications. You can enable and configure
1360+
it in the translator configuration:
1361+
1362+
.. configuration-block::
1363+
1364+
.. code-block:: yaml
1365+
1366+
# config/packages/translation.yaml
1367+
framework:
1368+
translator:
1369+
pseudo_localization:
1370+
# replace characters by their accented version
1371+
accents: true
1372+
# wrap strings with brackets
1373+
brackets: true
1374+
# controls how many extra characters are added to make text longer
1375+
expansion_factor: 1.4
1376+
# maintain the original HTML tags of the translated contents
1377+
parse_html: true
1378+
# also translate the contents of these HTML attributes
1379+
localizable_html_attributes: ['title']
1380+
1381+
.. code-block:: xml
1382+
1383+
<!-- config/packages/translation.xml -->
1384+
<?xml version="1.0" encoding="UTF-8" ?>
1385+
<container xmlns="http://symfony.com/schema/dic/services"
1386+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1387+
xmlns:framework="http://symfony.com/schema/dic/symfony"
1388+
xsi:schemaLocation="http://symfony.com/schema/dic/services
1389+
https://symfony.com/schema/dic/services/services-1.0.xsd
1390+
http://symfony.com/schema/dic/symfony
1391+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
1392+
1393+
<framework:config>
1394+
<framework:translator>
1395+
<!-- accents: replace characters by their accented version -->
1396+
<!-- brackets: wrap strings with brackets -->
1397+
<!-- expansion_factor: controls how many extra characters are added to make text longer -->
1398+
<!-- parse_html: maintain the original HTML tags of the translated contents -->
1399+
<framework:pseudo-localization
1400+
accents="true"
1401+
brackets="true"
1402+
expansion_factor="1.4"
1403+
parse_html="true"
1404+
>
1405+
<!-- also translate the contents of these HTML attributes -->
1406+
<framework:localizable-html-attribute>title</framework:localizable-html-attribute>
1407+
</framework:pseudo-localization>
1408+
</framework:translator>
1409+
</framework:config>
1410+
</container>
1411+
1412+
.. code-block:: php
1413+
1414+
// config/packages/translation.php
1415+
use Symfony\Config\FrameworkConfig;
1416+
1417+
return static function (FrameworkConfig $framework) {
1418+
// ...
1419+
$framework
1420+
->translator()
1421+
->pseudoLocalization()
1422+
// replace characters by their accented version
1423+
->accents(true)
1424+
// wrap strings with brackets
1425+
->brackets(true)
1426+
// controls how many extra characters are added to make text longer
1427+
->expansionFactor(1.4)
1428+
// maintain the original HTML tags of the translated contents
1429+
->parseHtml(true)
1430+
// also translate the contents of these HTML attributes
1431+
->localizableHtmlAttributes(['title'])
1432+
;
1433+
};
1434+
1435+
That's all. The application will now start displaying those strange, but
1436+
readable, contents to help you internationalize it. See for example the
1437+
difference in the `Symfony Demo`_ application. This is the original page:
1438+
1439+
.. image:: /_images/translation/pseudolocalization-symfony-demo-disabled.png
1440+
1441+
And this is the same page with pseudolocalization enabled:
1442+
1443+
.. image:: /_images/translation/pseudolocalization-symfony-demo-enabled.png
1444+
13151445
Summary
13161446
-------
13171447

@@ -1349,3 +1479,5 @@ Learn more
13491479
.. _`Machine object format`: https://www.gnu.org/software/gettext/manual/html_node/MO-Files.html
13501480
.. _`QT Translations TS XML`: https://doc.qt.io/qt-5/linguist-ts-file-format.html
13511481
.. _`GitHub Actions`: https://docs.github.com/en/free-pro-team@latest/actions
1482+
.. _`pseudolocalization`: https://en.wikipedia.org/wiki/Pseudolocalization
1483+
.. _`Symfony Demo`: https://github.com/symfony/demo

0 commit comments

Comments
 (0)