Quantcast
Channel: Symfony Blog
Viewing all articles
Browse latest Browse all 3057

New in Symfony 7.2: Translations Linter

$
0
0
Hugo Alliaume
Contributed by Hugo Alliaume in #57101

Linters are static code analysis tools used to flag errors like syntactic and stylistic issues. Symfony includes many linter commands to check YAML config files (lint:yaml), container services (lint:container), Twig templates (lint:twig) and even the syntax of XLIFF translation files (lint:xliff).

In Symfony 7.2 we're adding a new linter to check the content of translations. Unlike the lint:xliff command, this new lint:translations command checks all your translations, no matter which of the supported translation formats you use:

$ php bin/console lint:translations

# you can also lint only some of the supported locales
$ php bin/console lint:translations --locale=en --locale=tr

This command will be especially helpful when using the ICU MessageFormat syntax in your translations. This syntax is powerful but sometimes tricky, so it's common to miss closing braces (}), forget about the other key when using plurals, etc.

$ php bin/console lint:translations

  --------- -------------------------------- --------
   Locale    Domains                          Valid?
  --------- -------------------------------- --------
   ar        validators, security, messages   Yes
   bn        messages, validators             No
   de        validators, security, messages   Yes
   en        validators, security, messages   Yes
   es        validators, security, messages   Yes
   tr        validators, security, messages   Yes
  --------- -------------------------------- --------

  Errors for locale "bn" and domain "messages"
  --------------------------------------------
  Translation key "post.num_comments" is invalid:

  [ERROR] Invalid message format (error #65807): msgfmt_create: message formatter
          creation failed: U_DEFAULT_KEYWORD_MISSING

Sponsor the Symfony project.

Viewing all articles
Browse latest Browse all 3057

Trending Articles