Thai word-breaking doesn't work in snaps using common Gnome snaps (e.g. Firefox)

It seems like snaps which depends on Gnome common snaps (e.g. gnome-42-2204) cannot find libthai’s dictionary, which is required for Thai word-breaking to works. This affects applications from snapped gedit to Firefox [1].

Steps to reproduce:

  1. Install gedit snap from the store, and then open it.
  2. Copy and paste the following text into gedit window [2]:
ตัดฉันทีตัดฉันทีตัดฉันทีตัดฉันทีตัดฉันทีตัดฉันทีตัดฉันที
word break word break word break word break

Resize the window down to force word break. Both lines should be broken into multiple lines. However, only the second line is broken; the first one isn’t. (If the second line also isn’t broken, check your gedit preference.)

If, however, I launch gedit with:

LIBTHAI_DICTDIR=/snap/gedit/current/gnome-platform/usr/share/libthai/ /snap/bin/gedit

then the word breaking works as expected. A similar problem and a similar fix also applies to Firefox as well.

Using snap run --strace='--trace=%file' shows that it’s trying to look for a dictionary at /usr/share/libthai (i.e. host’s copy), which I understands is blocked by AppArmor for a reason (I can’t find the denial in the journal log though).

A workaround would be for every snap to put:

export LIBTHAI_DICTDIR=${SNAP}/gnome-platform/usr/share/libthai/

in snap’s launcher script. However, IMO applications shouldn’t be expected to set this environment variable. There should be a way for the gnome common snaps to provide this environment variable for all snaps that use these common snaps. I’m not sure how this would be possible though, so I start this thread to discuss possibilities to make this works for all snaps.

As a side note, Chromium seems to be an odd-one-out It also uses common snap (gnome-3-38-2004, the same one as Firefox actually), but Thai word breaking works there. I’ve grep’ed the snap and it doesn’t seem to set LIBTHAI_DICTDIR anyhow. strace even shows that it can’t open the dictionary either, so I’m not sure how it works there. Their word breaker don’t use libthai?

[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1796939 (also reported by me)
[2] For reference, “ตัด”, “ฉัน”, and “ที”, are 3 distinct words in Thai.

3 Likes

Firefox on Flatpak works, so this issue must be specific to Snap.

As you mentioned LIBTHAI_DICTDIR=${SNAP}/gnome-platform/usr/share/libthai/, I guess inserting it after line 23 in snapcraft.yaml will solve this issue.

Chromium is different since it breaks lines using libicu, so it doesn’t require libthai’s dictionary.

well, if it is a general issue with all snaps using the gnome platform snap, this variable should better be exported from the desktop-launch script so all apps benefit from it, not only firefox …

awesome find BTW :slight_smile:

@kenvandine can we add the above ?

Thank you. Although I have no idea what the desktop-launch script is, it sounds appropriate.

it is shipped by the gnome-platform snap and sets up the environment for all snap applications that utilize gnome-platform …

2 Likes

Right, that’s the place. Thank you. Also, since KDE frameworks also contain libthai, I think it makes sense to add this variable there too. Qt probably doesn’t use actually libthai (for licensing, I assume), but applications might link to libthai in the framework and use that.

I mean, I wonder why it takes 6 months since Ubuntu 22.04 release before any Thai user notice that word-breaking is broken in Firefox…

According to polls in the Thai Open Source Community on Facebook a few hours, Ubuntu and Firefox are surprisingly popular. So it is very strange.

image

@ogra @kenvandine Any progress?

@ogra @kenvandine Any progress on this? Or any repo/hint on where I can add it myself?