-
-
Notifications
You must be signed in to change notification settings - Fork 99
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
Review the fluent (i18n) implementation #1477
Comments
Yes, aware of scope leakage here. Right now it's basically required to reset the local before using any strings. This probably needs to be moved to a per-language instantiation and all calls to strings should use the instance connected to the language setting. This is closely related to #1367. |
Sure. Still true. The Lua implementation of Project Fluent was my own from the start. It tries to present the upstream ProjectFluent paradigm in a Lua idiomatic way. The major variable scope leakage I know about has been addressed, but there may be more issues of course. Since I started with a Lua implementation things have gotten even crazier as I'm now the upstream maintainer for the Rust implementation (used in Firefox and many many other places). I've also contributed to the upcoming Message Format 2 spec. Localization is a bugbear.
No, it's enforced on the Fluent "bundle". Any direct access the user tries to make on the Fluent global would be affected by this, but no SILE functions should be. In the future when we get a settings stack that separates language settings per typesetter we should initialize a bundle for each typesetter. Given that this is set every time the SILE function runs it will always
The Fluent bundle is state-full. The SILE function we're in here is also state-full, but with a different scope. Hence we're resetting the Fluent state to the SILE state every time this function is called. We're creating a wrapper here: we're wrapping an API that doesn't fit very naturally with SILE in some functions that do fit fairly nicely inside SILE.
This has been done. Did I miss something?
Again who cares, we're resetting the bundle state every time we call it to match whatever the current SILE state is.
Yes, the language loader stuff stinks a bit right now. It isn't just Fluent though, the whole thing as a mess and I can't get around to fixing it until 15 is out the door.
Sure, but if there is any way to make it both idiomatic Lua and follow he upstream Project Fluent model well I'd love to hear about it. The fluent-lua repo would be a better place for any issues with how that API works though.
We're providing state-less functions that wrap an inherently state-full API. The global state is in the API we're using (and the model it is meant to implement) not our own.
hello = Hello { $name }!
foo = bar
.attr = baz The somewhat Penlight object model usage that looks like this: print(bundle:format("foo"))
print(bundle:format("foo.attr"))
print(bundle:format("hello", { name = "World" })) ...could also be used as more generally Lua idioms that look like this: print(bundle["foo"])
print(bundle.foo.attr)
print(bundle.hello({ name = "World" })) Since lots of things in SILE are modeled around Penlight the first set of usages probably makes a lot more sense here, but for folks in many other Lua scopes with different models the later approach may be preferred. Hence fluent-lua provides both. |
If there is anything actionable for the SILE wrapper functions I'm quite happy to review them, but the last couple times I've read this issue I didn't come up with any. Please do re-open if I'm missing something. |
Further the issues I encountered in #1474...
The Fluent implementation is real weird...
It has potential side-effects...
nil
is there was no localization found. Boom?SILE.fluent:set_locale()
thing really annoys me. It means the Fluent thing is state-full. It ought to be state-less, andSILE.fluent:get_message(key, locale)
should be the way to go, IMHO.Let's checks every other call at
SILE.fluent:set_locale()
\font
: likewise, the font change might be transient (if we had content, i.e. we are in a temporary settings push/pop state): the previous local ought to be restored... Or this thing be state-less, again...\ftl
...SILE.languageSupport.languages.loadLanguage()
but this have some smell...The Fluent library implementation is even weirder... It uses Penlight classes, which are already broken to some extent (Er... Do I have to quote the package owner here?), but that could be okay... Er, wait, all the
metatable
access are weird, and this is typically why one would want to use an OOP framework: to avoid those... Even after trying to fix (1) and (2) above, I couldn't make sense of the results seen on the SILE manual with Localization for as many languages as possible #1474...I would suggest:
get_message
) rather than use some "global"._patch_init
andself:catch
things all have heavy code smell (IMHO) and are hardly understandable, therefore maintainable... for something, after all, which in the end resolves to some (key, value) patterns...The text was updated successfully, but these errors were encountered: