I was solving the same problem and only solution I've found was to
parse `language.dat` file, see (some example is at the bottom of the
note that this method doesn't work universally, some formats exists
which doesn't use `language.dat` (csplain is the one I know about),
but if you want to support only LaTeX, this method should be fine.
also note that there is file `language.dat.lua`, which contains lua
table with language names and properties, but unfortunately, language
numbers aren't recorded here and language names are used as table
keys, so this table isn't useful for querying language numbers.
If someone knows about less hackish solution, I would be happy to use
> While we're at it, this code does the language identifier to number
> conversion in LaTeX and passes the result to Lua. Anybody know of a way
> to do the conversion in Lua? Given a Lua string, say, 'UKenglish', how
> do you get the corresponding language number that is referred to in,
> e.g., glyph nodes? A solution to that problem would save users of my
> code from having to specify language identifiers on the LaTeX side in
> addition to the Lua side.
> Looking at the Babel package, I infer that \l@<lang> is actually a
> \chardef definition (whatever that is ...). The LuaTeX manual contains
> in sec. 4.14.4 "Attribute, count, dimension, skip and token registers" a
> TeX's attributes (\attribute), counters (\count), dimensions
> (\dimen), skips (\skip) and token (\toks) registers can be
> accessed and written to using two times five virtual
> sub-tables of the tex table:
> tex.attribute tex.dimen tex.toks
> tex.count tex.skip
> It is possible to use the names of relevant \attributedef,
> \countdef, \dimendef, \skipdef, or \toksdef control sequences
> as indices to these tables:
> tex.count.scratchcounter = 0
> enormous = tex.dimen['maxdimen']
> In this case, LuaTeX looks up the value for you on the fly.
> You have to use a valid \countdef (or \attributedef, or
> \dimendef, or \skipdef, or \toksdef), anything else will
> generate an error (the intent is to eventually also allow
> <chardef tokens> and even macros that expand into a number).
> Does that mean I have to wait until LuaTeX provides access to \chardefs
> on the Lua side? Or is there any other way to get the language number
> in Lua?
> Best regards,
> Stephan Hennig