[
https://issues.apache.org/jira/browse/FREEMARKER-97?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16494879#comment-16494879
]
Daniel Dekany commented on FREEMARKER-97:
-----------------------------------------
This is the same kind of problem than truncating long text, in that it's often
needed, but has no widely accepted algorithm. Even inside the same culture
there can be subtle variations. So, I think the way to go is adding
`?title_case` (and `?truncate`), but make the algorithm pluggable in the
configuration (on `Configurable` level, so that it can even vary per page).
Furthermore the algorithm depends on the current `locale`, which must be take
into account when designing this configuration API. So no wonder these "too
human" transformations were avoided so far, requiring users to come up with
their own functions.
Also, there need to be a default implementation. Hopefully it's possible to
chose a good enough default, which's better than the 95% of ad-hoc ones users
comes up with in the middle of some other work. But the sensible default is
locale specific. Especially in this case, as we need to recognize some English
words when the locale starts with `en`, which is quite weird (I mean,
hard-coded support for a specific language). It would be interesting to know
how they do this at some of the bigger nations at least, and what would be the
best default if we don't explicitly support the language. (Then there's the
slight problem that if we support, say, English, French and Spanish out of the
box, then why not language X... people can read things into that.) Or if what
exactly is the ideal rule for English, because the linked implementations
differ, and I'm not sure which is the best. Any help is appreciated. Especially
contributed code.
> Header capitalization using standard styles
> -------------------------------------------
>
> Key: FREEMARKER-97
> URL: https://issues.apache.org/jira/browse/FREEMARKER-97
> Project: Apache Freemarker
> Issue Type: Wish
> Components: engine
> Affects Versions: 2.3.28
> Reporter: T X
> Priority: Minor
>
> FreeMarker offers a couple of simple algorithms for changing the case of
> titles:
> *
> [https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_cap_firs|https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_cap_first]
> *
> [https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_capitalizet|https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_cap_first]
> Neither of these capitalize the text in ways that adhere to various standard
> styles:
> * [Chicago Manual of
> Style|https://en.wikipedia.org/wiki/The_Chicago_Manual_of_Style]
> * [Associated Press|https://en.wikipedia.org/wiki/AP_Stylebook]
> * [MLA Style Manual|https://en.wikipedia.org/wiki/MLA_Style_Manual]
> * [APA Style|https://en.wikipedia.org/wiki/APA_style]
> Consider the following texts:
> * On iPhone the Transcript Extends Outside of Screen Frame
> * PEAR And GNA Report Performance
> * BCMailPlusFTPClient Sends Document without Document ID
> * JWebUnit: Non-PEN Orders main.xhtml Meta Refresh Tag Issue
> These are correct as written and must not be adjusted by an algorithm that
> changes the text title. There are a couple of web sites that produce the
> expected titles (note that the second site capitalizes the word "without,"
> which implies the algorithm does not use Chicago conventions):
> * [https://titlecaseconverter.com/]
> * [http://individed.com/code/to-title-case/]
> There are a variety of implementations that perform such a feat:
> ||Language||Link||
> |JavaScript|[https://github.com/gouch/to-title-case/blob/master/to-title-case.js]|
> |Perl|[https://gist.github.com/gruber/9f9e8650d68b13ce4d78]|
> |PHP|[https://gist.github.com/HipsterJazzbo/2532c93a18db7451b0cec529c95b53c4]|
> These implementations do not require a whitelist. (So "iPhone" and
> "ClassName" will remain as given.) Apache Commons' {{WordUtils}} class does
> not implement Chicago Style, and I suspect it is also a fairly simple
> algorithm.
> Since {{?capitalize}} and {{?cap_first}} are taken, I propose {{?title_case}}
> with an optional parameter (default is Chicago):
> * chicago
> * ap
> * apa
> * mla
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)