INL / corpus-frontend

BlackLab Frontend, a feature-rich corpus search interface for BlackLab.
16 stars 7 forks source link

mixed text direction for multilingual corpus.. some documents rtl and others ltr #520

Open fadhleryani opened 1 month ago

fadhleryani commented 1 month ago

I understand you can switch the direction of the entire corpus interface in the corpusConfig setting in the ..format.blf file, but is it possible to customize things for this to work on the document level?

For reference, my corpus has multiple gloss features which exist for both the Arabic and English documents, and I've enabled multipleValues annotation, so the search returns the expected documents, but the direction is reversed for one of the languages which makes the interface unusable.

jan-niestadt commented 1 month ago

This is currently not yet possible, unfortunately.

If you want to take a stab at implementing this, here's a way to go about it:

If you have any more questions, don't hesitate to ask.

fadhleryani commented 1 month ago

Hi Jan thanks for your quick reply!

A main issue is actually with the "After Hit Hit Before Hit" order in the table. I'm imaginining I could rename the columns to "Context.. Hit ..Context" and have the text appear from the correct direction based on the metadata. Any pointers on how I might be able to do that?

jan-niestadt commented 1 month ago

Have a look at HitsTable.vue.

For the table headings, you can customize the text via custom locale files, see here. Create a file e.g. $corporaInterfaceDataDir/MyCorpus/static/locales/en-us.json containing:

{
  "results": {
    "table": {
      "before": "context",
      "after": "context"
    }
  }
}

For the direction the hit is displayed in, right now, the dir property is passed to the Hit component from HitsTable (line 90). You want to add a dir(h) method that determines the correct direction for the current hit based on h.doc.docInfo.textDirection (the metadata field to index with the doc).

Good luck and please submit a PR, we'd be happy to have a look and merge it if possible.

fadhleryani commented 1 month ago

I managed to create the method and pass the direction from metadata, but this only results in changing the placement of the dots '...'

What I would like is for the columns to be switched.

Also I noticed that regardless of whether or not I set textDirection: 'rtl' in the blf format file, the order of the HitContextComponent inside the HitRowDetails is always off for my rtl texts, and are fine for the ltr.

jan-niestadt commented 1 month ago

It's difficult for me to help without knowing your data, .blf.yaml and changes to corpus-frontend.

If you have your own clone of BlackLab on GitHub, you can easily create a (draft) pull request here with your changes so far, so I can have a look.

Please also upload a toy example data file, ideally 2 small docs, one rtl and one ltr, as well as your .blf.yaml file. Then I can index it and view it in your corpus-frontend version and have a better idea of what's happening.

KCMertens commented 1 month ago

Woops, that wasn't mean to close the issue! I did find and fix (quite a few! 😮) bugs relating to rtl rendering. Though I cannot read Arabic, so it is difficult to verify correctness. If you could take another look with the latest dev that would be great!