std::format
and other formatting functions have an overload that allows specifying a locale to format the arguments. For instance, to
use a .
or a ,
for floating point values, or to spell the months in dates. However, just passing the right locale is not
enough. You have to mark each argument that is subject to internationalization by specifying the L
flag in the format specification.
This rule raises an issue when a locale is passed to a formatting function, but localization is not enabled for any argument.
Noncompliant code example
std::locale fr{“fr_FR”}; // locale names are platform dependant
std::cout << std::format(fr, "{}", 1.2); // Noncompliant, will display 1.2
std::cout << std::format(fr, "{:%A}", chrono::system_clock::now()); // Noncompliant, will display weekday in English
Compliant solution
std::cout << std::format(fr, "{:L}", 1.2); // Compliant, will display 1,2
std::cout << std::format(fr, "{:L%A}", chrono::system_clock::now()); // Compliant, will display weekday in French