| 1 |
# Lua-UCA hacking |
| 2 |
|
| 3 |
You need the full installation from |
| 4 |
[Github](https://github.com/michal-h21/lua-uca) in order to do stuff described |
| 5 |
in this section. Package distributed on CTAN doesn't contain all necessary |
| 6 |
files. |
| 7 |
|
| 8 |
## Install |
| 9 |
|
| 10 |
The package needs to download Unicode collation data and convert it to a Lua |
| 11 |
table. It depends on `wget` and `unzip` utilities. All files can be downloaded |
| 12 |
using Make: |
| 13 |
|
| 14 |
make |
| 15 |
|
| 16 |
To install the package in the local TEXMF tree, run: |
| 17 |
|
| 18 |
make install |
| 19 |
|
| 20 |
## New language support |
| 21 |
|
| 22 |
To add a new language, add new function to `src/lua-uca/lua-uca-languages.lua` |
| 23 |
file. The function name should be short language code. Example function for |
| 24 |
the Russian language: |
| 25 |
|
| 26 |
languages.ru = function(collator_obj) |
| 27 |
collator_obj:reorder{ "cyrillic" } |
| 28 |
return collator_obj |
| 29 |
end |
| 30 |
|
| 31 |
The language function takes the Collator object as a parameter. Methods showed |
| 32 |
in the *Change sorting rules* section can be used with this object. |
| 33 |
|
| 34 |
The `data/common/collation/` directory in the source repository contains files from the `CLDR` project. |
| 35 |
They contain rules for many languages. The files needs to be normalized to the |
| 36 |
[NFC form](https://en.wikipedia.org/wiki/Unicode_equivalence), for example using: |
| 37 |
|
| 38 |
cat cs.xml | uconv -x any-nfc -o cs.xml |
| 39 |
|
| 40 |
The `uconv` utility is a part of the [ICU Project](http://userguide.icu-project.org/). |
| 41 |
|
| 42 |
Sorting rules for a language are placed in the `<collation>` element. Multiple |
| 43 |
`<collation>` elements may be present in the XML file. It is usually best to chose the one with attribute |
| 44 |
`type="standard"`. |
| 45 |
|
| 46 |
The following example contains code from `da.xml`: |
| 47 |
|
| 48 |
|
| 49 |
[caseFirst upper] |
| 50 |
&D<<đ<<<Đ<<ð<<<Ð |
| 51 |
&th<<<þ |
| 52 |
&TH<<<Þ |
| 53 |
&Y<<ü<<<Ü<<ű<<<Ű |
| 54 |
&[before 1]ǀ<æ<<<Æ<<ä<<<Ä<ø<<<Ø<<ö<<<Ö<<ő<<<Ő<å<<<Å<<<aa<<<Aa<<<AA |
| 55 |
&oe<<œ<<<Œ |
| 56 |
|
| 57 |
This is translated to Lua code in `lua-uca-languages.lua` in the following way: |
| 58 |
|
| 59 |
|
| 60 |
languages.da = function(collator_obj) |
| 61 |
-- helper function for more readable tailoring definition |
| 62 |
local tailoring = function(s) collator_obj:tailor_string(s) end |
| 63 |
collator_obj:uppercase_first() |
| 64 |
tailoring("&D<<đ<<<Đ<<ð<<<Ð") |
| 65 |
tailoring("&th<<<þ") |
| 66 |
tailoring("&TH<<<Þ") |
| 67 |
tailoring("&Y<<ü<<<Ü<<ű<<<Ű") |
| 68 |
tailoring("&ǀ<æ<<<Æ<<ä<<<Ä<ø<<<Ø<<ö<<<Ö<<ő<<<Ő<å<<<Å<<<aa<<<Aa<<<AA") |
| 69 |
tailoring("&oe<<œ<<<Œ") |
| 70 |
return collator_obj |
| 71 |
end |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
Pull requests with new language support are highly appreciated. |
| 77 |
|
| 78 |
## Support files in the source distribution |
| 79 |
|
| 80 |
The `xindex` directory contains some examples for configuration of `Xindex`, Lua based indexing system. |
| 81 |
Run `make xindex` command to compile them. |
| 82 |
|
| 83 |
`Xindex` has built-in support for Lua-UCA since version `0.23`, it can be requested using the `-u` option. |
| 84 |
|
| 85 |
The `tools/indexing-sample.lua` file provides a simple indexing processor, independent of any other tool. |
| 86 |
|
| 87 |
## Testing |
| 88 |
|
| 89 |
You can run unit tests using the following command: |
| 90 |
|
| 91 |
make test |
| 92 |
|
| 93 |
Testing requires [Busted](https://olivinelabs.com/busted/) testing framework installed on your system. |
| 94 |
Tests are placed in the `spec` directory and they provide more examples of the package usage. |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|