Humanizer French title case support

562 Views Asked by At

The built in .Net method TextInfo.ToTitleCase handles French sentences ok, but there are some samples which cause issues, see remarks (copied below):

Generally, title casing converts the first character of a word to uppercase and the rest of the characters to lowercase. However, this method does not currently provide proper casing to convert a word that is entirely uppercase, such as an acronym. The following table shows the way the method renders several strings.

Input Language Expected result Actual result
war and peace English War and Peace War And Peace
Per anhalter durch die Galaxis German Per Anhalter durch die Galaxis Per Anhalter Durch Die Galaxis
les naufragés d'ythaq French Les Naufragés d'Ythaq Les Naufragés D'ythaq

As illustrated above, the TextInfo.ToTitleCase method provides an arbitrary casing behavior which is not necessarily linguistically correct. A linguistically correct solution would require additional rules, and the current algorithm is somewhat simpler and faster. We reserve the right to make this API slower in the future.

The current implementation of the TextInfo.ToTitleCase method yields an output string that is the same length as the input string. However, this behavior is not guaranteed and could change in a future implementation.

Is there an option within the Humanizer library to Titleize with a given culture?

1

There are 1 best solutions below

0
On

It would feel like a good addition to the Humanizer library but currently it's not supported.

If I were to implement title casing for French, I'd look at the javascript titlecase-french library and rewrite it in C#, following the good set of rules it defines:

There are 5 main rules:

  • A title always starts with a word in uppercase
  • A specific list of words are in lowercase
  • After a quote ' words can be in lowercase or uppercase depending of the word before the quote
  • Acronyms are in uppercase
  • Special uppercase letters (with accent for example) are replaced with their simple version

The sample in TextInfo.ToTitleCase remarks (les naufragés d'ythaq) works as expected with titlecase-french:

console.log(require('titlecase-french').convert("les naufragés d'ythaq"));
// Les Naufragés d'Ythaq