c# - Humanizer 法语标题大小写支持

标签 c# cultureinfo humanizer

内置的 .Net 方法 TextInfo.ToTitleCase 可以很好地处理法语句子,但有些示例会导致问题,请参阅 remarks (复制如下):

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.

Humanizer 库中是否有一个选项可以用给定的文化标题化?

最佳答案

感觉像是对 Humanizer 的一个很好的补充库,但目前不支持。

如果我要为法语实现标题大小写,我会查看 javascript titlecase-french库并在 C# 中重写它,遵循 rules 的好集它定义:

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

TextInfo.ToTitleCase 注释 (les naufragés d'ythaq) 中的示例与 titlecase-french 一起正常工作:

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

关于c# - Humanizer 法语标题大小写支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28592944/

相关文章:

humanizer - 是否可以使用 Humanizer 将 TimeSpan 人性化为数年?

c# - 如何在 Silverlight 中设置默认打印机?

c# - 从 PDF 表单添加到 MSSQL

c# - 拆箱到更大的值类型

c# - 检测连接到局域网的主机

c# - 如何使用 TypeConverter 转换特定于文化的 double ?

c# - 在 WPF 应用程序中全局设置文化 (en-IN)

c# - CultureInfo 转换 (C#)

c# - DateTime 的人性化工具

c# - Humanizer 无法在 C# 中对意大利语单词进行单数化或复数化