https://kotlinlang.org logo
#kobweb
Title
# kobweb
v

Vojtěch Hořánek

03/24/2024, 12:17 AM
👋Hi! I'm trying to make my website locale-aware so I thought I would give moko-resources a try since I've used it on different KMM projects (no js tho). I've successfully got it to compile (with the use of an alpha version), but when moko tries to load the json localization file it generates, the call fails with a 404 error. I have a suspicion that kobweb does the routing here and it does not see those json files. The files should be included in the webpack. Anyway, I don't know how to check who's the culprit here, hence I'm asking for help here. Or if anyone can direct me into other ways of allowing localization in kobweb/Kotlin JS, I would appreciate it a lot 😄
K 1
👀 1
I've also tried using the new compose resources, but I found out that I had to have the string values in both
commonMain/composeResources/values/
and
resources/public/values/
. And the compose
stringResource
actually does not work because it cannot find the
LocalDensity
composition local (perhaps it's only for wasm compose then?).
d

David Herman

03/24/2024, 4:48 AM
Sadly I haven't had much time to look into how resources work in most Compose Multiplatform projects. See also: https://kotlinlang.slack.com/archives/C01F2HV7868/p1710644758035699?thread_ts=1710644758.035699
Normally if you have a file in Kobweb that needs to be available at runtime it needs to be put into the jsMain/resources/public/ folder for it to get served in the final site. I'm not sure how something like Moko works
s

S.

03/24/2024, 12:36 PM
an alternative that is proven to work is Libres
you can have a look here for a simple example https://github.com/TheDome0/kobweb_localisation
v

Vojtěch Hořánek

03/24/2024, 4:18 PM
Thanks both for the help! I think I'll try using libres and see if that works, as it seems to be the path of least resistance (and that's something I really need now 😅).
s

S.

03/24/2024, 4:20 PM
it should be fairly simple. let me know if you have any troubles.
❤️ 1
I haven't used moko (horrible compatibility) but it sounds like translations are being fetched dynamically. with libres it will be embedded into the js file itself
v

Vojtěch Hořánek

03/24/2024, 4:21 PM
Yep, that is exactly what is moko doing.
s

S.

03/24/2024, 4:21 PM
something to consider if you're using it for a very text heavy application like blogs
v

Vojtěch Hořánek

03/24/2024, 4:22 PM
Nono, I think embedding will work just fine for my usecase
s

S.

03/24/2024, 4:23 PM
good good. there are ways around it. in short: you export the website multiple times for each locale, that's what I'm doing for better seo
🤔 1
v

Vojtěch Hořánek

03/24/2024, 4:24 PM
I haven't used moko (horrible compatibility)
Could you elaborate on that? I haven't had that much of a problem with it when working on an Android/iOS only project
s

S.

03/24/2024, 4:27 PM
might be that I just hit an unfortunate time frame, but it was difficult to find a set of kobweb, compose and moko versions that works. I believe I also had to resort to alpha versions and downgrade some stuff
and going by gh issues this library seems to be outdated and not compatible quite often
v

Vojtěch Hořánek

03/24/2024, 4:33 PM
I see, for kobweb it does seem like the compatibility is quite bad.
Libres seems to work like a charm
s

S.

03/24/2024, 4:44 PM
good to hear. it also works with all the other compose targets so you can create a shared module and use the strings everywhere in your project
👍 1
d

David Herman

03/24/2024, 10:05 PM
Thanks for continuing this chat! I wish I had more knowledge / opinions about how to do localization with Kobweb. The recent resources change in Compose 1.6.0, which I haven't really had time to look into too deeply yet, confuses things more 🙂 In gamedev, there are lots of short strings, so it makes sense to create a base json (or other format) text file that contains a bunch of key/value text resources, and then create additional json files to add support for additional languages. (Maybe strings.json and strongs.de.json). You can host those files on your server (or an external asset server) and then pull those down (based on a language pulldown setting on the site). However, if you want to have a significantly different layout based on what language you are using (maybe extra paragraphs or different images, etc.), then yeah probably creating multiple copies of the site is a better way to go.
❤️ 1
2 Views