Stream: ideas

Topic: Add effect for l10n to basic-cli/webserver


view this post on Zulip Luke Boswell (Nov 07 2024 at 00:53):

I was thinking of using https://crates.io/crates/sys-locale to add an effect to basic-cli and basic-webserver so that people could build apps (and/packages) in future that support different locales.

Something like this which returns IETF BCP 47 strings like en-AU or en-US etc...

Locale.get : Task Str [NotAvailable]

# or with purity-inference
Locale.get! {} => Result Str [NotAvailable]

view this post on Zulip Richard Feldman (Nov 07 2024 at 01:01):

can the locale change in the middle of a running program? :thinking:

view this post on Zulip Richard Feldman (Nov 07 2024 at 01:02):

I guess so

view this post on Zulip Richard Feldman (Nov 07 2024 at 01:02):

if so, that makes sense to me!

view this post on Zulip Luke Boswell (Nov 07 2024 at 01:02):

Richard Feldman said:

can the locale change in the middle of a running program? :thinking:

I'm not sure, I guess we could pass it into the app on init

view this post on Zulip Luke Boswell (Nov 07 2024 at 01:03):

For purity inference, there's always going to be at least an empty record passed in, why not have that contain useful information about the current environment

view this post on Zulip Luke Boswell (Nov 07 2024 at 01:03):

Like we could move the current OS/Arch in there too -- instead of that being a effect

view this post on Zulip Richard Feldman (Nov 07 2024 at 01:10):

I think if it can change in the middle of the program, we should go with the API above

view this post on Zulip Richard Feldman (Nov 07 2024 at 01:10):

if a program doesn't want to support that, they can always call this once during initialization and then store it

view this post on Zulip Richard Feldman (Nov 07 2024 at 01:10):

but having the option means you can potentially also support live-updating it if it does change in the middle of the program

view this post on Zulip Brendan Hansknecht (Nov 07 2024 at 01:28):

For webservers wouldn't locale depend on the request?

view this post on Zulip Luke Boswell (Nov 07 2024 at 01:29):

HTTP Accept-Language request header indicates the natural language and locale that the client prefers

view this post on Zulip Richard Feldman (Nov 07 2024 at 01:30):

oh cool, TIL!

view this post on Zulip Richard Feldman (Nov 07 2024 at 01:30):

I assumed that was just a server thing

view this post on Zulip Richard Feldman (Nov 07 2024 at 01:30):

then in that case yeah probably makes sense for basic-webserver to go off that

view this post on Zulip Luke Boswell (Nov 07 2024 at 01:30):

For basic-cli

https://github.com/roc-lang/basic-cli/pull/258

view this post on Zulip Luke Boswell (Nov 07 2024 at 01:33):

So it would live in Request then?

Request : {
    method : Method,
    headers : List Header,
    url : Str,
    mimeType : Str,
    body : List U8,
    timeout : TimeoutConfig,
    acceptedLocales: List Str,
}

view this post on Zulip Richard Feldman (Nov 07 2024 at 01:36):

I think you could parse it out of the headers

view this post on Zulip Richard Feldman (Nov 07 2024 at 01:36):

that feels like maybe it should be opt-in, since some webservers wouldn't bother to do anything with the locale info

view this post on Zulip Richard Feldman (Nov 07 2024 at 01:37):

e.g. Header.acceptedLocales which takes a List Header and returns all the accepted locales it finds in there

view this post on Zulip Luke Boswell (Nov 07 2024 at 01:37):

:man_facepalming:

view this post on Zulip Luke Boswell (Nov 07 2024 at 01:37):

Lol, it doesn't need to be an effect

view this post on Zulip Richard Feldman (Nov 07 2024 at 01:39):

yeah if it's not asking the OS, then it can be pure! :smiley:


Last updated: Jun 16 2026 at 16:19 UTC