Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to make wrapping in context optional #7

Closed
iilyak opened this issue Apr 16, 2024 · 4 comments
Closed

Add ability to make wrapping in context optional #7

iilyak opened this issue Apr 16, 2024 · 4 comments

Comments

@iilyak
Copy link

iilyak commented Apr 16, 2024

I am trying to use the linguify inside the calendar library I am working on. I would need to get string values for months and weekdays in different languages in typst code. Unfortunately it doesn't seem possible due to the fact that the linguify function creates context.

The simplest reproducer

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

#let database = toml("lang.toml")

#let localize(weekday) = {
  linguify(weekday, from: database, default: weekday)
}

#set text(lang: "en")
#assert.eq("sunday", localize("sunday"))

this code fails with

equality assertion failed: value "sunday" was not equal to "context()"
@jomaway
Copy link
Collaborator

jomaway commented Apr 16, 2024

Can you try to use _linguify() instead. Not sure if this function is exported though. Then you need to provide context around the function calling it.

@iilyak
Copy link
Author

iilyak commented Apr 16, 2024

The _linguify is private and not reachable.

@jomaway
Copy link
Collaborator

jomaway commented Apr 17, 2024

Ok I will fix this in the next version. But might take a while until I find some time.

@jomaway
Copy link
Collaborator

jomaway commented Apr 26, 2024

I published 0.4.1 if it is merged you can use

#context {
  lflib._linguify(...)
}

which returns an dictionary with { "ok": "result" } or { "error" : "error_message" }

you still need to provide context around the function call, because of checking for text.lang,
maybe i will refactor it in the future to have an context free version if all parameters are passed in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants