Skip to content

Linguify fails to find keys in headers after #outline() is called #25

@Tobionecenobi

Description

@Tobionecenobi

Overview

The linguify function appears to stop working correctly within header elements after the #outline() function has been executed, especially when a new database is loaded afterwards. Specifically, keys from a subsequent database loaded after #outline() are not found in headers, while they are found in regular text elements. Additionally, using linguify in headers immediately after #outline() but before loading a new database results in an "empty database" error.

Bug Reproduction Example

This example demonstrates the issue:

#import "@preview/linguify:0.4.2": *

// Initial database for cover page
#let database = toml("translationCover.toml")
#set-database(database)

// These keys are found in the initial database
= #linguify("cover_title")
= #linguify("subtitle")

// Generate the outline
#outline()

// Switch to the main translation database
#let database = toml("translation.toml")
#set-database(database)

// This key is NOT found in the header!
= #linguify("information_title")
// This key IS found in regular text
#linguify("text1")

Error Message

When running the above code, Typst panics with the following error:

Panicked with: "Could not find an entry for the key information_title in language en at the linguify database. Also, the fallback language en does not contain the key information_title."

Expected Behavior

I expect that after calling #outline() and setting a new database, linguify should be able to find and translate keys within header elements, just as it does in regular text elements.

Actual Behavior

As shown in the example, linguify fails to find the key "information_title" within the header after #outline() has been called and a new database has been loaded. However, it correctly finds the key "text1" in a regular text element using the same database.

Workaround

Removing the #outline() function resolves the primary issue of the key not being found in the subsequent database, as demonstrated by this working example:

#import "@preview/linguify:0.4.2": *

#let database = toml("translationCover.toml")
#set-database(database)

= #linguify("cover_title")
== #linguify("subtitle")

#let database = toml("translation.toml")
#set-database(database)

=============== #linguify("information_title")
#linguify("text1")

Additional Information

This bug seems to be specifically related to the interaction between linguify, header elements, and the #outline() function. The order of operations, particularly loading a new database after calling #outline(), appears to be the core of the problem.

Interestingly, the following code works as expected:

#import "@preview/linguify:0.4.2": *

#let database = toml("translationCover.toml")
#set-database(database)

#outline()

= #linguify("cover_title")
== #linguify("subtitle")

This indicates that linguify can successfully retrieve keys from the currently loaded database in headers even after #outline() has been called, as long as the database isn't changed afterwards.

However, this code does not work and throws an error:

#import "@preview/linguify:0.4.2": *

#let database = toml("translationCover.toml")
#set-database(database)

#outline()

= #linguify("cover_title")
== #linguify("subtitle")

Error Message:

Panicked with: "linguify database is empty."

This suggests that after #outline() is called, and before a new database is loaded, the linguify database might be in an unexpected state or potentially cleared, even if it was previously populated. This "empty database" error could be related to why subsequent databases are not correctly accessed within headers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions