module documentation

Read and write TLK (Talk Table) files (for translation and base game string references).

All strings are transparently converted to and from the NWN encoding.

Class TlkEntry A single entry in a TLK file including the text, sound resref, and sound length. Only used when reading TLK files with sound data.
Function read Reads a TLK file fully into memory and returns a list of entries.
Function write Writes a Tlk object to a binary file.
def read(file: BinaryIO, include_sound_data=False, max_entries=524287) -> tuple[list, Language]: (source)

Reads a TLK file fully into memory and returns a list of entries.

Parameters
file:BinaryIOA binary file object containing the TLK file.
include_sound_dataIf True, entries are returned as TlkEntry objects. Otherwise, the resulting dict will contain only the text.
max_entriesThe maximum number of entries to read from the TLK file. This is a sanity check to avoid allocating excess memory when reading untrusted or corrupted data.
Returns
tuple[list, Language]
A tuple containing a list of entries and the language of the TLK file.
The list contains either strings or TlkEntry objects, depending on the value of include_sound_data.
Raises
ValueErrorIf the file does not contain valid TLK data.
def write(file: BinaryIO, entries: list, language: Language): (source)

Writes a Tlk object to a binary file.

Parameters
file:BinaryIOA binary file object to write the TLK data to.
entries:listA list containing the entries to write, in order. Entries can be either strings or TlkEntry objects.
language:LanguageThe language of the TLK file to write.
Raises
ValueErrorIf the TLK object contains invalid data.