%D \module
%D   [      file=s-lan-06,
%D        version=2013.03.22,
%D          title=\CONTEXT\ Style File,
%D       subtitle=Language Environment 6,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\startluacode

languages.tracers = languages.tracers or { }

function languages.tracers.showfrequencies(language)
    local t = languages.frequencies.getdata(language or "en")
    context.starttabulate { "|lT|cw(2em)|r|" }
    context.NC()
    context.formatted.rlap("%s: %p",t.language,languages.frequencies.averagecharwidth(t.language))
    context.NC()
    context.NC()
    context.NR()
    context.HL()
    for k, v in table.sortedhash(t.frequencies) do
        context.NC()
        context("%U",k)
        context.NC()
        context("%c",k)
        context.NC()
        context("%0.3f",v)
        context.NC()
        context.NR()
    end
    context.stoptabulate()
end

\stopluacode

\unexpanded\def\ShowLanguageFrequencies#1%
  {\ctxlua{languages.tracers.showfrequencies("#1")}}

\continueifinputfile{s-lan-06.mkiv}

\starttext

    \hsize65\averagecharwidth \input ward \par

    \ShowLanguageFrequencies\currentmainlanguage

\stoptext
